Skip to content

Commit

Permalink
Fixing bug where color was turning off lights before fade.
Browse files Browse the repository at this point in the history
Setting up build cache locally to speed up builds. Note in README.
  • Loading branch information
Andrew Suderman committed Jan 19, 2020
1 parent 503673f commit 1061b1b
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
init-decrypted
coverage.txt
*-report.out
.tmp
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@ VERSION=dev
HYPRIOT_IMAGE="https://github.com/hypriot/image-builder-rpi/releases/download/v1.12.0/hypriotos-rpi-v1.12.0.img.zip"
PKG_PATH=/go/src/github.com/sudermanjr/led-controller
LDFLAGS=\"-X main.version=$(VERSION) -X main.commit=$(COMMIT) -s -w\"
DOCKER_GOCACHE=/root/.cache/go-build
LOCAL_TMP=$(PWD)/.tmp


all: lint test create-builder build
build: create-builder build-arm
build-arm:
docker run --rm -ti -v ${GOPATH}:/go -w $(PKG_PATH) rpi-ws281x-go-builder /usr/bin/qemu-arm-static /bin/sh -c "$(GOCMD) build -ldflags $(LDFLAGS) -o $(PKG_PATH)/$(BINARY_NAME) -v"
docker run --rm -ti -v ${GOPATH}:/go -v $(LOCAL_TMP):$(DOCKER_GOCACHE) -w $(PKG_PATH) rpi-ws281x-go-builder /usr/bin/qemu-arm-static /bin/sh -c "$(GOCMD) build -ldflags $(LDFLAGS) -o $(PKG_PATH)/$(BINARY_NAME) -v"
file led-controller
create-builder:
docker build --tag rpi-ws281x-go-builder .
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ This is cross-compiled for the Raspberry Pi using the instructions in the rpi-ws

The build commands are in the [Makefile](Makefile). You can `make build` to build the Docker container and then use that to build the binary for the Pi. At the end it will show the output of `file led-controller` to verify the type of the binary.

The build will also create a local `.tmp` directory for storing build cache so that subsequent builds are much much faster.

Another word of caution: This container build will utilized your local GOPATH so that it doesn't have to download every package every time.

## References
Expand Down
7 changes: 3 additions & 4 deletions control.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ var onCmd = &cobra.Command{
klog.Fatal(err)
}
defer led.ws.Fini()

_ = led.fade(colors[colorName], onBrightness)
led.color = colors[colorName]
_ = led.fade(led.color, onBrightness)
},
}

Expand All @@ -40,7 +40,6 @@ var offCmd = &cobra.Command{
klog.Fatal(err)
}
defer led.ws.Fini()

_ = led.fade(off, minBrightness)
_ = led.fade(led.color, minBrightness)
},
}
6 changes: 3 additions & 3 deletions homekit.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ func startHomekit() {
ac.Lightbulb.On.OnValueRemoteUpdate(func(on bool) {
if on {
klog.Infof("Switch is on")
err = led.fade(colors["white"], maxBrightness)
err = led.fade(led.color, maxBrightness)
if err != nil {
klog.Error(err)
}
} else {
klog.Infof("Switch is off")
err = led.fade(off, minBrightness)
err = led.fade(led.color, minBrightness)
if err != nil {
klog.Error(err)
}
Expand All @@ -80,7 +80,7 @@ func startHomekit() {

hc.OnTermination(func() {
klog.Info("terminated. turning off lights")
err = led.fade(off, minBrightness)
err = led.fade(led.color, minBrightness)
if err != nil {
klog.Error(err)
}
Expand Down
2 changes: 1 addition & 1 deletion neopixel.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newLEDArray() (*LEDArray, error) {
}
// Start off
led.brightness = minBrightness
led.color = off
led.color = colors["white"]
return led, nil
}

Expand Down

0 comments on commit 1061b1b

Please sign in to comment.