Permalink
Browse files

Added some state to keep duplicate button presses from firing while a…

… job is running and removed go blocks to simplify that state.
  • Loading branch information...
1 parent cfc5ecf commit ca4a7ba44a45fa14a1992229a94098d16e20b047 @mikeflynn committed Nov 1, 2015
Showing with 34 additions and 36 deletions.
  1. +26 −34 main.go
  2. +8 −2 sniffer.go
View
@@ -95,40 +95,34 @@ func ToggleWorkshopConfig(config map[string]interface{}) {
if inConfig == false {
// Turn the front lights off and the back lights down to half brightness.
if strings.Contains(v.Name, "Workshop Front") {
- go func(idx string) {
- for i := 0; i < 3; i++ {
- err := HueSetLight(idx, HueLightState{On: config["front_on"].(bool), Bri: config["front_bri"].(int)})
- if err != nil {
- log.Printf("HUE ERROR: %v", err.Error())
- } else {
- break
- }
+ for i := 0; i < 3; i++ {
+ err := HueSetLight(k, HueLightState{On: config["front_on"].(bool), Bri: config["front_bri"].(int)})
+ if err != nil {
+ log.Printf("HUE ERROR: %v", err.Error())
+ } else {
+ break
}
- }(k)
+ }
} else if strings.Contains(v.Name, "Workshop Back") {
- go func(idx string) {
- for i := 0; i < 3; i++ {
- err := HueSetLight(idx, HueLightState{On: config["back_on"].(bool), Bri: config["back_bri"].(int)})
- if err != nil {
- log.Printf("HUE ERROR: %v", err.Error())
- } else {
- break
- }
- }
- }(k)
- }
- } else {
- // Turn the lights back on with regular brightness.
- go func(idx string) {
for i := 0; i < 3; i++ {
- err := HueSetLight(idx, HueLightState{On: true, Bri: 200})
+ err := HueSetLight(k, HueLightState{On: config["back_on"].(bool), Bri: config["back_bri"].(int)})
if err != nil {
log.Printf("HUE ERROR: %v", err.Error())
} else {
break
}
}
- }(k)
+ }
+ } else {
+ // Turn the lights back on with regular brightness.
+ for i := 0; i < 3; i++ {
+ err := HueSetLight(k, HueLightState{On: true, Bri: 200})
+ if err != nil {
+ log.Printf("HUE ERROR: %v", err.Error())
+ } else {
+ break
+ }
+ }
}
}
}
@@ -155,16 +149,14 @@ func ToggleWorkshopLights() {
for k, v := range lights {
if strings.Contains(v.Name, "Workshop") {
- go func(idx string) {
- for i := 0; i < 3; i++ {
- err := HueSetLight(idx, HueLightState{On: toggle, Bri: 200})
- if err != nil {
- log.Printf("HUE ERROR: %v", err.Error())
- } else {
- break
- }
+ for i := 0; i < 3; i++ {
+ err := HueSetLight(k, HueLightState{On: toggle, Bri: 200})
+ if err != nil {
+ log.Printf("HUE ERROR: %v", err.Error())
+ } else {
+ break
}
- }(k)
+ }
}
}
}
View
@@ -14,6 +14,7 @@ import (
//type fn func(string)
var DashMacs = map[string]func(){}
+var State = map[string]bool{}
func SnifferStart() {
// Get a list of all interfaces.
@@ -104,8 +105,13 @@ func readARP(handle *pcap.Handle, iface *net.Interface, stop chan struct{}) {
for mac, fn := range DashMacs {
if net.HardwareAddr(arp.SourceHwAddress).String() == mac {
- log.Printf("Click sniffed for %v", mac)
- fn()
+
+ if !State[mac] {
+ log.Printf("Click sniffed for %v", mac)
+ State[mac] = true
+ fn()
+ State[mac] = false
+ }
found = true
}

0 comments on commit ca4a7ba

Please sign in to comment.