1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00

69 lines
1.1 KiB
Go
Raw Normal View History

2014-04-27 19:34:16 -07:00
package gpio
import (
"github.com/hybridgroup/gobot"
)
type LedDriver struct {
gobot.Driver
Adaptor PwmDigitalWriter
High bool
}
2014-05-22 21:29:37 -07:00
func NewLedDriver(a PwmDigitalWriter, name string, pin string) *LedDriver {
2014-04-27 19:34:16 -07:00
return &LedDriver{
Driver: gobot.Driver{
2014-04-30 08:10:44 -07:00
Name: name,
Pin: pin,
2014-04-27 19:34:16 -07:00
Commands: []string{
"ToggleC",
"OnC",
"OffC",
"BrightnessC",
},
},
High: false,
2014-04-30 08:10:44 -07:00
Adaptor: a,
2014-04-27 19:34:16 -07:00
}
}
func (l *LedDriver) Start() bool { return true }
func (l *LedDriver) Halt() bool { return true }
func (l *LedDriver) Init() bool { return true }
func (l *LedDriver) IsOn() bool {
return l.High
}
func (l *LedDriver) IsOff() bool {
return !l.IsOn()
}
func (l *LedDriver) On() bool {
l.changeState(1)
l.High = true
return true
}
func (l *LedDriver) Off() bool {
l.changeState(0)
l.High = false
return true
}
func (l *LedDriver) Toggle() {
if l.IsOn() {
l.Off()
} else {
l.On()
}
}
func (l *LedDriver) Brightness(level byte) {
l.Adaptor.PwmWrite(l.Pin, level)
}
func (l *LedDriver) changeState(level byte) {
l.Adaptor.DigitalWrite(l.Pin, level)
}