1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-29 13:49:14 +08:00
hybridgroup.gobot/platforms/i2c/hmc6352_driver.go

35 lines
685 B
Go
Raw Normal View History

2014-04-27 18:54:41 -07:00
package i2c
import (
"github.com/hybridgroup/gobot"
2014-05-03 03:37:02 -07:00
"time"
2014-04-27 18:54:41 -07:00
)
type HMC6352Driver struct {
gobot.Driver
Adaptor I2cInterface
Heading uint16
}
func NewHMC6352Driver(a I2cInterface) *HMC6352Driver {
return &HMC6352Driver{
Adaptor: a,
}
}
func (h *HMC6352Driver) Start() bool {
h.Adaptor.I2cStart(0x21)
h.Adaptor.I2cWrite([]uint16{uint16([]byte("A")[0])})
2014-05-03 03:37:02 -07:00
gobot.Every(1*time.Second, func() {
2014-04-27 18:54:41 -07:00
h.Adaptor.I2cWrite([]uint16{uint16([]byte("A")[0])})
ret := h.Adaptor.I2cRead(2)
if len(ret) == 2 {
h.Heading = (ret[1] + ret[0]*256) / 10
}
})
return true
}
func (self *HMC6352Driver) Init() bool { return true }
func (self *HMC6352Driver) Halt() bool { return true }