You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
781 B
Go
44 lines
781 B
Go
package I2C
|
|
|
|
import (
|
|
"fmt"
|
|
_ "sync"
|
|
)
|
|
|
|
type I2CDevice struct {
|
|
*I2CBus // embeds bus
|
|
bool // stores whether dev is currently connected
|
|
int // addr
|
|
}
|
|
|
|
func (d I2CDevice) String() string {
|
|
t := map[int]string{97:"DO Sensor",99:"pH Sensor",102:"Temperature Sensor"}
|
|
return t[d.int]
|
|
}
|
|
|
|
func NewDevice(addr int,bus *I2CBus) *I2CDevice {
|
|
d := &I2CDevice{}
|
|
d.I2CBus = bus
|
|
d.int = addr
|
|
return d
|
|
}
|
|
|
|
func (d *I2CDevice) GetAddr() int {
|
|
return d.int
|
|
}
|
|
|
|
func (d *I2CDevice) GetStatus() string {
|
|
// TODO
|
|
s := d.I2CBus.GetStatus(d.int)
|
|
if s {
|
|
return "ACTIVE"
|
|
} else {
|
|
return "KILLED"
|
|
}
|
|
}
|
|
|
|
func (d *I2CDevice) GetType() string {
|
|
// TODO
|
|
return fmt.Sprint(d)
|
|
}
|