2014-04-28 19:23:15 +08:00
|
|
|
package digispark
|
2014-04-26 18:11:51 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/hybridgroup/gobot"
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DigisparkAdaptor struct {
|
|
|
|
gobot.Adaptor
|
2014-04-28 19:23:15 +08:00
|
|
|
littleWire *LittleWire
|
2014-04-26 18:11:51 +08:00
|
|
|
servo bool
|
|
|
|
pwm bool
|
2014-04-28 19:23:15 +08:00
|
|
|
connect func(*DigisparkAdaptor)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-05-23 11:13:38 +08:00
|
|
|
func NewDigisparkAdaptor(name string) *DigisparkAdaptor {
|
2014-04-28 19:23:15 +08:00
|
|
|
return &DigisparkAdaptor{
|
2014-07-08 07:44:21 +08:00
|
|
|
Adaptor: *gobot.NewAdaptor(
|
|
|
|
name,
|
|
|
|
"DigisparkAdaptor",
|
|
|
|
),
|
2014-04-28 19:23:15 +08:00
|
|
|
connect: func(d *DigisparkAdaptor) {
|
|
|
|
d.littleWire = LittleWireConnect()
|
|
|
|
},
|
|
|
|
}
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) Connect() bool {
|
|
|
|
d.connect(d)
|
2014-07-08 07:44:21 +08:00
|
|
|
d.SetConnected(true)
|
2014-04-26 18:11:51 +08:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) Reconnect() bool {
|
|
|
|
return d.Connect()
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) Finalize() bool { return true }
|
|
|
|
func (d *DigisparkAdaptor) Disconnect() bool { return true }
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) DigitalWrite(pin string, level byte) {
|
2014-04-26 18:11:51 +08:00
|
|
|
p, _ := strconv.Atoi(pin)
|
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
d.littleWire.PinMode(uint8(p), 0)
|
|
|
|
d.littleWire.DigitalWrite(uint8(p), level)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) DigitalRead(pin string, level byte) {}
|
|
|
|
func (d *DigisparkAdaptor) PwmWrite(pin string, value byte) {
|
|
|
|
if d.pwm == false {
|
|
|
|
d.littleWire.PwmInit()
|
|
|
|
d.littleWire.PwmUpdatePrescaler(1)
|
|
|
|
d.pwm = true
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
2014-04-28 19:23:15 +08:00
|
|
|
d.littleWire.PwmUpdateCompare(value, value)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) AnalogRead(string) int { return -1 }
|
2014-04-26 18:11:51 +08:00
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) InitServo() {}
|
|
|
|
func (d *DigisparkAdaptor) ServoWrite(pin string, angle uint8) {
|
|
|
|
if d.servo == false {
|
|
|
|
d.littleWire.ServoInit()
|
|
|
|
d.servo = true
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
2014-04-28 19:23:15 +08:00
|
|
|
d.littleWire.ServoUpdateLocation(angle, angle)
|
2014-04-26 18:11:51 +08:00
|
|
|
}
|
|
|
|
|
2014-04-28 19:23:15 +08:00
|
|
|
func (d *DigisparkAdaptor) I2cStart(byte) {}
|
|
|
|
func (d *DigisparkAdaptor) I2cRead(uint16) []uint16 { return make([]uint16, 0) }
|
|
|
|
func (d *DigisparkAdaptor) I2cWrite([]uint16) {}
|