Skip to content

Commit

Permalink
Merge pull request #64 from Kaiede/vNext
Browse files Browse the repository at this point in the history
Prep 1.0 for Release
  • Loading branch information
Kaiede authored Aug 14, 2019
2 parents 2f401bb + 996bc21 commit 5d89f10
Show file tree
Hide file tree
Showing 50 changed files with 2,566 additions and 1,740 deletions.
24 changes: 12 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ env: # important!

matrix:
include:
- name: "Linux Swift 3.1.1"
- name: "Linux Swift 4.1.3"
os: linux
dist: trusty
env: SWIFT_VERSION=3.1.1
env: SWIFT_VERSION=4.1.3
install:
- mkdir swift
- curl https://swift.org/builds/swift-${SWIFT_VERSION}-release/ubuntu1404/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu14.04.tar.gz -s | tar -xz -C swift
- export PATH="$(pwd)/swift/swift-${SWIFT_VERSION}-RELEASE-ubuntu14.04/usr/bin:$PATH"

- name: "Linux Swift 4.1.3"
- name: "Linux Swift 4.2.3"
os: linux
dist: trusty
env: SWIFT_VERSION=4.1.3
env: SWIFT_VERSION=4.2.3
install:
- mkdir swift
- curl https://swift.org/builds/swift-${SWIFT_VERSION}-release/ubuntu1404/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu14.04.tar.gz -s | tar -xz -C swift
- export PATH="$(pwd)/swift/swift-${SWIFT_VERSION}-RELEASE-ubuntu14.04/usr/bin:$PATH"

- name: "Linux Swift 4.2"
- name: "Linux Swift 5.0.2"
os: linux
dist: trusty
env: SWIFT_VERSION=4.2
env: SWIFT_VERSION=5.0.2
install:
- mkdir swift
- curl https://swift.org/builds/swift-${SWIFT_VERSION}-release/ubuntu1404/swift-${SWIFT_VERSION}-RELEASE/swift-${SWIFT_VERSION}-RELEASE-ubuntu14.04.tar.gz -s | tar -xz -C swift
- export PATH="$(pwd)/swift/swift-${SWIFT_VERSION}-RELEASE-ubuntu14.04/usr/bin:$PATH"

- name: "Mac Xcode 9"
- name: "Mac Xcode 9 (Swift 4.1)"
os: osx
osx_image: xcode9.4

- name: "Mac Xcode 10"
- name: "Mac Xcode 10 (Swift 4.2)"
os: osx
osx_image: xcode10

allow_failures:
- os: linux
env: SWIFT_VERSION=4.2
- name: "Mac Xcode 10.2 (Swift 5)"
os: osx
osx_image: xcode10.2

script:
- swift package reset
Expand Down
23 changes: 23 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "swift",
"args": [
"test"
],
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"reveal": "always",
"clear": true
}
}
]
}
125 changes: 59 additions & 66 deletions Docs/Configuration.md
Original file line number Diff line number Diff line change
@@ -1,89 +1,90 @@
# Configuring the Light Schedule

There are example configuration files in the [examples](https://github.com/Kaiede/RPiLight/examples) folder. These files are JSON-formatted. Let's go ahead and break down a specific example:
There are example configuration files in the [examples](https://github.com/Kaiede/RPiLight/examples) folder. These files are JSON-formatted, and are split into two components: The hardware configuration, and the schedule.

## Hardware Configuration

Let's look at an example that uses a PWM HAT (config-example-pca9685.json):

```
{
"user": "pi",
"hardware" : {
"board": "pizero",
"pwmMode": "pca9685",
"freq": 960,
"channels": 8,
"gamma": 1.8
},
"lunarCycle": {
"start": "21:00:00",
"end": "07:00:00",
},
"PWM00": {
"minIntensity": 0.0025
"schedule": [
{ "time": "08:00:00", "brightness": 0.0 },
{ "time": "08:30:00", "brightness": 0.25 },
{ "time": "12:00:00", "brightness": 0.25 },
{ "time": "14:00:00", "brightness": 0.50 },
{ "time": "18:00:00", "brightness": 0.50 },
{ "time": "20:00:00", "brightness": 0.10 },
{ "time": "22:30:00", "brightness": 0.10 },
{ "time": "23:00:00", "brightness": 0.0 }
]
}
<etc>
"board": "raspberryPi",
"controllers": [
{
"type": "hardware",
"frequency": 960,
"gamma": 2.2,
"channels": {
"primary": 0,
"secondary": 1
}
}
]
}
```

### Username
* `user` can be any valid user on the OS. `pi` is recommended.

```
"user": "pi",
```
This is the account to run the service as. This should **not** be `root`, as that has too many permissions. Instead, the service starts as root, and then switches to this user once it has mapped in any hardware it needs extra permissions for, such as the PWM hardware.

* `user` can be any valid user on the OS. `pi` is recommended.
* `board` can currently only be `raspberryPi`.

This is the account to run the service as. This should **not** be `root`, as that has too many permissions. Instead, the service starts as root, and then switches to this user once it has access to the hardware.
* `gamma` can be between `1.0` and `3.0`. Default is `1.8`

This controls how brightness is converted into light intensity. The human eye is closer to a gamma of around `2.5`, and most displays use a gamma of `2.2`. If using a gamma of `1.0`, then `brightness` and `intensity` are the same thing.

### Hardware
### Controllers

This is an array of hardware you want to control. It's possible to have multiple controllers handling many channels of lighting.

```
"hardware" : {
"board": "pizero",
"pwmMode": "pca9685",
"freq": 960,
"channels": 8,
"gamma": 1.8
{
"type": "raspberryPwm",
"frequency": 960,
"address": 0x61,
"channels": {
"primary": 0,
"secondary": 1
}
}
```

* `board` can be `pi1`, `pi2`, `pi3`, `pizero` or `desktop`
* `type` can be `raspberryPwm`, `pca9685`, `mcp4725` or `simulated`

This is optional. RPiLight will attempt to detect which Raspberry Pi board you are using for you. Only set this if you are having problems. `desktop` is used for testing.
`raspberryPwm` uses the two PWM channels included with the Raspberry Pi. `pca9685` uses the PCA9685 I2C PWM chip, available from Adafruit as the PCA9685 PWM/Servo Bonnet or Hat. `mcp4725` is meant for use with 0-10V boards that use the MCP4725 I2C DAC. `simulated` is used for testing.

* `pwmMode` can be `hardware`, `pca9685` or `simulated`
> The MCP4725 support is currently experimental. Use at your own risk.
`hardware` uses the two PWM channels included with the Raspberry Pi. `pca9685` uses the PCA9685 I2C PWM chip, available from Adafruit as the PCA9685 PWM/Servo Bonnet or Hat. `simulated` is used for testing.

* `freq` must be between `480` and `1500` (Hz). If `pwmMode = hardware` the max is `16000` (16 kHz). Default is `480`
* `frequency` must be between `480` and `1500` (Hz). If `pwmMode = hardware` the max is `16000` (16 kHz). Default is `480`

This is the frequency of PWM to use. Lower values produce more flicker, but not all light drivers can take higher values. Before picking a value, check to see what your LED drivers support. This setting should not be used with `simulated`, as it has no meaning.

> ex. Meanwell LDD drivers can only go so high (1 KHz), and so RPiLight should not use a value over `960` when driving Meanwell LDDs.
* `channels` can be `1` to `16`. If `pwmMode = hardware`, it can only be `1` to `2`.
* `address` is used by the `pca9685` and `mcp4725` types that use I2C, if using multiple boards, or non-default I2C addresses.

This tells RPiLight how many channels to actually control. This should match how many LED channels you have wired up.
This doesn't normally need to be put into the configuration file. But it allows someone to use a non-default I2C address for these chips

* `gamma` can be between `1.0` and `3.0`. Default is `1.8`
* `channels` is a dictionary of names being mapped to channels for the controller.

This controls how brightness is converted into light intensity. The human eye is closer to a gamma of around `2.5`, and most displays use a gamma of `2.2`. If using a gamma of `1.0`, then `brightness` and `intensity` are the same thing.
This is where you map numbered channels to a more friendly name you can reference in your schedule. This friendly name is also what will be used in any sort of logging or remote control, to make it easier to identify.

Valid indexes are:
* `raspberryPwm`: 0 or 1
* `pca9685`: 0-15
* `mcp4725`: 0
* `simulated`: 0 and up.

## Schedule

The schedule.json file contains the schedule for the lighting. It doesn't contain any information related to the hardware, so it can be configured separately from the underlying hardware configuration, making it easier to share settings.

### Channel Configuration

```
"PWM00": {
"primary": {
"minIntensity": 0.0025
"schedule": [
{ "time": "08:00:00", "brightness": 0.0 },
Expand All @@ -98,23 +99,15 @@ This controls how brightness is converted into light intensity. The human eye is
}
```

Each channel has its settings and schedule bound to it. The channel token is used to name the settings/schedule assoicated with it, and depends on what hardware you are using.

Example Channel Tokens:
```
PWM00 to PWM15 : Adafruit PCA9685 Channels 0-15
PWM0-IO18 : Raspberry Pi PWM channel 0, on GPIO18
PWM1-IO19 : Raspberry Pi PWM channel 1, on GPIO19
SIM00 to SIM15 : Simulated Channels 0-15
```
Each channel has its settings and schedule bound to it. The channel name is used to name the settings/schedule assoicated with it, and depends on what you named your channels in the config.json file earlier.

`minIntensity` is used to adjust the cut-off of the light, and is optional. The default is `0.0`. This will treat the channel as off at any intensity level or lower. In this example it will turn of at `0.25%` intensity. Twinstar E lights start shutting off some LEDs but not others at around `0.2%` intensity, so this example provides a generally nicer transition for the lights when turning off or on.

The `schedule` array is where the work really happens. It is an array of events used to control the lights. In this example, the lights will be off at 8:00 am. Starting at 8:00 am, it will ramp up the lights until they are at 25% at 8:30 am. Then they will remain at 25% until 12:00 pm. Increase again to 50% brightness (28.7% intensity) by 2:00 pm until 6:00 pm. Then it shifts to 10% brightness by 8:00pm where it stays before ramping back to off between 10:30 pm and 11:00 pm.

* `time` is a 24-hour time.

This time is in the local timezone set on the Raspberry Pi.
This time is in the local timezone set on the Raspberry Pi.

> ex. 8:15 pm would be 20:15:00.
Expand Down Expand Up @@ -146,9 +139,9 @@ The feature doesn't currently take moonrise or moonset into account.
The `--preview` option was meant to test hardware configurations with simple ramps:
```
cd /opt/rpilight
RPiLight --preview <config.json>
RPiLight --preview
```

This file is expected to be in the `./config/` directory, and by default it will look for `./config/config.json`. For now, it is required to be root to copy the file to the service's config directory: `sudo cp <myfile> /opt/rpilight/config/config.json`.
This file is expected to be in the `./config/` directory, and by default it will look for `./config/config.json` for the hardware configuration, and `./config/schedule.json` for the schedule. For now, it is required to be root to copy either file to the service's config directory: `sudo cp <myfile> /opt/rpilight/config/config.json`.

You should first make sure the service is stopped before running previews to avoid getting weird results. See "Starting the Daemon" below.
You should first make sure the service is stopped before running previews to avoid getting weird results.
72 changes: 37 additions & 35 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,44 +1,46 @@
// swift-tools-version:3.1
// swift-tools-version:4.0
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription

//
// Backport of Package(url:from:)
//
extension Package.Dependency {
public class func Package(url: String, from versionString: String) -> Package.Dependency {
guard let version = Version(versionString) else { fatalError() }
let nextMajor = Version(version.major + 1, 0, 0)
return Package(url: url, versions: version..<nextMajor)
}
}

//
// Package
//
let package = Package(
name: "RPiLight",
targets: [
Target(
name: "RPiLight",
dependencies: ["Core"]
),
Target(
name: "Core",
dependencies: ["PWM", "Logging"]
),
Target(
name: "PWM",
dependencies: ["Logging"]
),
Target(name: "Logging")
products: [
// Products define the executables and libraries produced by a package, and make them visible to other packages.
.executable(
name: "RPiLight",
targets: ["RPiLight"]),
],
dependencies: [
.Package(url: "https://github.com/Kaiede/Ephemeris.git", from: "1.0.0"),
.Package(url: "https://github.com/kareman/Moderator.git", from: "0.5.0"),
.Package(url: "https://github.com/Kaiede/PCA9685.git", from: "2.0.0"),
.Package(url: "https://github.com/Kaiede/SingleBoard.git", from: "0.2.0"),
.Package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", from: "17.0.2")
// Dependencies declare other packages that this package depends on.
.package(url: "https://github.com/Kaiede/Ephemeris.git", from: "1.0.2"),
.package(url: "https://github.com/Kaiede/Moderator.git", .branch("swift5compat")), // Need merging
.package(url: "https://github.com/Kaiede/PCA9685.git", from: "3.0.0"),
.package(url: "https://github.com/Kaiede/MCP4725.git", from: "0.1.0"),
.package(url: "https://github.com/Kaiede/SingleBoard.git", from: "1.0.0")
],
swiftLanguageVersions: [3, 4]
targets: [
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
// Targets can depend on other targets in this package, and on products in packages which this package depends on.
.target(
name: "RPiLight",
dependencies: ["Service", "Moderator"]),
.target(
name: "Service",
dependencies: ["LED", "Logging", "Ephemeris"]),
.target(
name: "LED",
dependencies: ["Logging", "MCP4725", "PCA9685", "SingleBoard"]),
.target(name: "Logging"),

// Test Targets
.testTarget(
name: "ServiceTests",
dependencies: ["Service"]
),
.testTarget(
name: "LEDTests",
dependencies: ["LED"]
)
]
)
42 changes: 0 additions & 42 deletions [email protected]

This file was deleted.

Loading

0 comments on commit 5d89f10

Please sign in to comment.