forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
digispark_adaptor.go
69 lines (59 loc) · 1.64 KB
/
digispark_adaptor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package digispark
import (
"github.com/edmontongo/gobot"
"strconv"
)
type DigisparkAdaptor struct {
gobot.Adaptor
littleWire *LittleWire
servo bool
pwm bool
connect func(*DigisparkAdaptor)
}
func NewDigisparkAdaptor(name string) *DigisparkAdaptor {
return &DigisparkAdaptor{
Adaptor: *gobot.NewAdaptor(
name,
"DigisparkAdaptor",
),
connect: func(d *DigisparkAdaptor) {
d.littleWire = LittleWireConnect()
},
}
}
func (d *DigisparkAdaptor) Connect() bool {
d.connect(d)
d.SetConnected(true)
return true
}
func (d *DigisparkAdaptor) Reconnect() bool {
return d.Connect()
}
func (d *DigisparkAdaptor) Finalize() bool { return true }
func (d *DigisparkAdaptor) Disconnect() bool { return true }
func (d *DigisparkAdaptor) DigitalWrite(pin string, level byte) {
p, _ := strconv.Atoi(pin)
d.littleWire.PinMode(uint8(p), 0)
d.littleWire.DigitalWrite(uint8(p), level)
}
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
}
d.littleWire.PwmUpdateCompare(value, value)
}
func (d *DigisparkAdaptor) AnalogRead(string) int { return -1 }
func (d *DigisparkAdaptor) InitServo() {}
func (d *DigisparkAdaptor) ServoWrite(pin string, angle uint8) {
if d.servo == false {
d.littleWire.ServoInit()
d.servo = true
}
d.littleWire.ServoUpdateLocation(angle, angle)
}
func (d *DigisparkAdaptor) I2cStart(byte) {}
func (d *DigisparkAdaptor) I2cRead(uint16) []uint16 { return make([]uint16, 0) }
func (d *DigisparkAdaptor) I2cWrite([]uint16) {}