refactor lighthardware struct
- add led struct for individual colour LEDs
This commit is contained in:
parent
32d03ddd05
commit
856a6e2d88
84
main.go
84
main.go
@ -11,32 +11,32 @@ type pwm interface {
|
||||
Channel(machine.Pin) (uint8, error)
|
||||
}
|
||||
|
||||
type led struct {
|
||||
pin machine.Pin
|
||||
pwm pwm
|
||||
channel uint8
|
||||
}
|
||||
|
||||
type lighthardware struct {
|
||||
rPin machine.Pin
|
||||
gPin machine.Pin
|
||||
bPin machine.Pin
|
||||
rPwm pwm
|
||||
gPwm pwm
|
||||
bPwm pwm
|
||||
rCh uint8
|
||||
gCh uint8
|
||||
bCh uint8
|
||||
red led
|
||||
green led
|
||||
blue led
|
||||
}
|
||||
|
||||
func (lhw *lighthardware) InitPWM() error {
|
||||
var err error
|
||||
|
||||
lhw.rCh, err = lhw.rPwm.Channel(lhw.rPin)
|
||||
lhw.red.channel, err = lhw.red.pwm.Channel(lhw.red.pin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lhw.gCh, err = lhw.gPwm.Channel(lhw.gPin)
|
||||
lhw.green.channel, err = lhw.green.pwm.Channel(lhw.green.pin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
lhw.bCh, err = lhw.bPwm.Channel(lhw.bPin)
|
||||
lhw.blue.channel, err = lhw.blue.pwm.Channel(lhw.blue.pin)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -120,12 +120,18 @@ func main() {
|
||||
})
|
||||
|
||||
insideLight := lighthardware{
|
||||
rPin: machine.GP11,
|
||||
gPin: machine.GP13,
|
||||
bPin: machine.GP12,
|
||||
rPwm: pwm5,
|
||||
gPwm: pwm6,
|
||||
bPwm: pwm6,
|
||||
red: led{
|
||||
pin: machine.GP11,
|
||||
pwm: pwm5,
|
||||
},
|
||||
green: led{
|
||||
pin: machine.GP13,
|
||||
pwm: pwm6,
|
||||
},
|
||||
blue: led{
|
||||
pin: machine.GP12,
|
||||
pwm: pwm6,
|
||||
},
|
||||
}
|
||||
err := insideLight.InitPWM()
|
||||
|
||||
@ -133,12 +139,18 @@ func main() {
|
||||
errs <- err
|
||||
} else {
|
||||
insideLight2 := lighthardware{
|
||||
rPin: machine.GP8,
|
||||
gPin: machine.GP10,
|
||||
bPin: machine.GP9,
|
||||
rPwm: pwm4,
|
||||
gPwm: pwm5,
|
||||
bPwm: pwm4,
|
||||
red: led{
|
||||
pin: machine.GP8,
|
||||
pwm: pwm4,
|
||||
},
|
||||
green: led{
|
||||
pin: machine.GP10,
|
||||
pwm: pwm5,
|
||||
},
|
||||
blue: led{
|
||||
pin: machine.GP9,
|
||||
pwm: pwm4,
|
||||
},
|
||||
}
|
||||
err = insideLight2.InitPWM()
|
||||
|
||||
@ -146,12 +158,18 @@ func main() {
|
||||
errs <- err
|
||||
} else {
|
||||
outsideLight := lighthardware{
|
||||
rPin: machine.GP5,
|
||||
gPin: machine.GP7,
|
||||
bPin: machine.GP6,
|
||||
rPwm: pwm2,
|
||||
gPwm: pwm3,
|
||||
bPwm: pwm3,
|
||||
red: led{
|
||||
pin: machine.GP5,
|
||||
pwm: pwm2,
|
||||
},
|
||||
green: led{
|
||||
pin: machine.GP7,
|
||||
pwm: pwm3,
|
||||
},
|
||||
blue: led{
|
||||
pin: machine.GP6,
|
||||
pwm: pwm3,
|
||||
},
|
||||
}
|
||||
err = outsideLight.InitPWM()
|
||||
|
||||
@ -258,7 +276,7 @@ func normal(lights lightSet, inBrightChange <-chan uint32, outBrightChange <-cha
|
||||
}
|
||||
|
||||
func setNormal(light *lighthardware, brightness uint32) {
|
||||
ledset(light.rPwm, light.rCh, brightness)
|
||||
ledset(light.gPwm, light.gCh, brightness)
|
||||
ledset(light.bPwm, light.bCh, brightness)
|
||||
ledset(light.red.pwm, light.red.channel, brightness)
|
||||
ledset(light.green.pwm, light.green.channel, brightness)
|
||||
ledset(light.blue.pwm, light.blue.channel, brightness)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user