1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-05-01 13:48:57 +08:00
hybridgroup.gobot/platforms/i2c/hmc6352_driver.go

37 lines
699 B
Go
Raw Normal View History

2014-04-27 18:54:41 -07:00
package i2c
import (
"github.com/hybridgroup/gobot"
)
type HMC6352Driver struct {
gobot.Driver
Adaptor I2cInterface
Heading uint16
}
2014-05-22 21:33:05 -07:00
func NewHMC6352Driver(a I2cInterface, name string) *HMC6352Driver {
2014-04-27 18:54:41 -07:00
return &HMC6352Driver{
2014-05-22 21:33:05 -07:00
Driver: gobot.Driver{
Name: name,
},
2014-04-27 18:54:41 -07:00
Adaptor: a,
}
}
func (h *HMC6352Driver) Start() bool {
h.Adaptor.I2cStart(0x21)
h.Adaptor.I2cWrite([]byte("A"))
2014-04-27 18:54:41 -07:00
gobot.Every(h.Interval, func() {
h.Adaptor.I2cWrite([]byte("A"))
2014-04-27 18:54:41 -07:00
ret := h.Adaptor.I2cRead(2)
if len(ret) == 2 {
h.Heading = (uint16(ret[1]) + uint16(ret[0])*256) / 10
2014-04-27 18:54:41 -07:00
}
})
return true
}
2014-06-10 15:16:11 -07:00
func (h *HMC6352Driver) Init() bool { return true }
func (h *HMC6352Driver) Halt() bool { return true }