forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
606 additions
and
598 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package gpio | ||
|
||
import ( | ||
"github.com/hybridgroup/gobot" | ||
) | ||
|
||
type AnalogSensorDriver struct { | ||
gobot.Driver | ||
Adaptor AnalogReader | ||
} | ||
|
||
func NewAnalogSensor(a AnalogReader) *AnalogSensorDriver { | ||
return &AnalogSensorDriver{ | ||
Driver: gobot.Driver{ | ||
Commands: []string{ | ||
"ReadC", | ||
}, | ||
}, | ||
Adaptor: a, | ||
} | ||
} | ||
|
||
func (a *AnalogSensorDriver) Start() bool { return true } | ||
func (a *AnalogSensorDriver) Init() bool { return true } | ||
func (a *AnalogSensorDriver) Halt() bool { return true } | ||
|
||
func (a *AnalogSensorDriver) Read() int { | ||
return a.Adaptor.AnalogRead(a.Pin) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package gpio | ||
|
||
import ( | ||
"github.com/hybridgroup/gobot" | ||
) | ||
|
||
type ButtonDriver struct { | ||
gobot.Driver | ||
Adaptor DigitalReader | ||
Active bool | ||
} | ||
|
||
func NewButtonDriver(a DigitalReader) *ButtonDriver { | ||
return &ButtonDriver{ | ||
Driver: gobot.Driver{ | ||
Events: map[string]chan interface{}{ | ||
"push": make(chan interface{}), | ||
"release": make(chan interface{}), | ||
}, | ||
}, | ||
Active: false, | ||
Adaptor: a, | ||
} | ||
} | ||
|
||
func (b *ButtonDriver) Start() bool { | ||
state := 0 | ||
go func() { | ||
for { | ||
new_value := b.readState() | ||
if new_value != state && new_value != -1 { | ||
state = new_value | ||
b.update(new_value) | ||
} | ||
} | ||
}() | ||
return true | ||
} | ||
func (b *ButtonDriver) Halt() bool { return true } | ||
func (b *ButtonDriver) Init() bool { return true } | ||
|
||
func (b *ButtonDriver) readState() int { | ||
return b.Adaptor.DigitalRead(b.Pin) | ||
} | ||
|
||
func (b *ButtonDriver) update(new_val int) { | ||
if new_val == 1 { | ||
b.Active = true | ||
gobot.Publish(b.Events["push"], new_val) | ||
} else { | ||
b.Active = false | ||
gobot.Publish(b.Events["release"], new_val) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
package gobotGPIO | ||
package gpio | ||
|
||
import "strconv" | ||
|
||
// Led | ||
func (l *Led) ToggleC(params map[string]interface{}) { | ||
func (l *LedDriver) ToggleC(params map[string]interface{}) { | ||
l.Toggle() | ||
} | ||
func (l *Led) OnC(params map[string]interface{}) { | ||
func (l *LedDriver) OnC(params map[string]interface{}) { | ||
l.On() | ||
} | ||
func (l *Led) OffC(params map[string]interface{}) { | ||
func (l *LedDriver) OffC(params map[string]interface{}) { | ||
l.Off() | ||
} | ||
func (l *Led) BrightnessC(params map[string]interface{}) { | ||
func (l *LedDriver) BrightnessC(params map[string]interface{}) { | ||
level := byte(params["level"].(float64)) | ||
l.Brightness(level) | ||
} | ||
|
||
// Servo | ||
func (l *Servo) MoveC(params map[string]interface{}) { | ||
func (l *ServoDriver) MoveC(params map[string]interface{}) { | ||
angle := byte(params["angle"].(float64)) | ||
l.Move(angle) | ||
} | ||
func (l *Servo) MinC(params map[string]interface{}) { | ||
func (l *ServoDriver) MinC(params map[string]interface{}) { | ||
l.Min() | ||
} | ||
func (l *Servo) CenterC(params map[string]interface{}) { | ||
func (l *ServoDriver) CenterC(params map[string]interface{}) { | ||
l.Center() | ||
} | ||
func (l *Servo) MaxC(params map[string]interface{}) { | ||
func (l *ServoDriver) MaxC(params map[string]interface{}) { | ||
l.Max() | ||
} | ||
|
||
// Direct Pin | ||
func (d *DirectPin) DigitalReadC(params map[string]interface{}) int { | ||
func (d *DirectPinDriver) DigitalReadC(params map[string]interface{}) int { | ||
return d.DigitalRead() | ||
} | ||
func (d *DirectPin) DigitalWriteC(params map[string]interface{}) { | ||
func (d *DirectPinDriver) DigitalWriteC(params map[string]interface{}) { | ||
level, _ := strconv.Atoi(params["level"].(string)) | ||
d.DigitalWrite(byte(level)) | ||
} | ||
func (d *DirectPin) AnalogReadC(params map[string]interface{}) int { | ||
func (d *DirectPinDriver) AnalogReadC(params map[string]interface{}) int { | ||
return d.AnalogRead() | ||
} | ||
func (d *DirectPin) AnalogWriteC(params map[string]interface{}) { | ||
func (d *DirectPinDriver) AnalogWriteC(params map[string]interface{}) { | ||
level, _ := strconv.Atoi(params["level"].(string)) | ||
d.AnalogWrite(byte(level)) | ||
} | ||
func (d *DirectPin) PwmWriteC(params map[string]interface{}) { | ||
func (d *DirectPinDriver) PwmWriteC(params map[string]interface{}) { | ||
level, _ := strconv.Atoi(params["level"].(string)) | ||
d.PwmWrite(byte(level)) | ||
} | ||
func (d *DirectPin) ServoWriteC(params map[string]interface{}) { | ||
func (d *DirectPinDriver) ServoWriteC(params map[string]interface{}) { | ||
level, _ := strconv.Atoi(params["level"].(string)) | ||
d.ServoWrite(byte(level)) | ||
} | ||
|
||
// Analog Sensor | ||
func (d *AnalogSensor) ReadC(params map[string]interface{}) int { | ||
func (d *AnalogSensorDriver) ReadC(params map[string]interface{}) int { | ||
return d.Read() | ||
} |
Oops, something went wrong.