Makey button now uses Interval to manage polling

This commit is contained in:
Adrian Zankich 2014-06-06 14:44:51 -07:00
parent 57bb8bbce6
commit a7d648eee8
2 changed files with 9 additions and 9 deletions

0
examples/firmata_makey_button.go Normal file → Executable file
View File

18
platforms/gpio/makey_button_driver.go Normal file → Executable file
View File

@ -11,9 +11,11 @@ type MakeyButtonDriver struct {
data []int
}
func NewMakeyButton(a DigitalReader) *MakeyButtonDriver {
func NewMakeyButtonDriver(a DigitalReader, name string, pin string) *MakeyButtonDriver {
return &MakeyButtonDriver{
Driver: gobot.Driver{
Name: name,
Pin: pin,
Events: map[string]chan interface{}{
"push": make(chan interface{}),
"release": make(chan interface{}),
@ -26,15 +28,13 @@ func NewMakeyButton(a DigitalReader) *MakeyButtonDriver {
func (m *MakeyButtonDriver) Start() bool {
state := 0
go func() {
for {
new_value := m.readState()
if new_value != state && new_value != -1 {
state = new_value
m.update(new_value)
}
gobot.Every(m.Interval, func() {
new_value := m.readState()
if new_value != state && new_value != -1 {
state = new_value
m.update(new_value)
}
}()
})
return true
}
func (m *MakeyButtonDriver) Halt() bool { return true }