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.
devices/firmata/pin_state.go

32 lines
513 B
Go

package firmata
import (
"fmt"
"periph.io/x/conn/v3/pin"
)
type PinStateResponse struct {
Pin uint8
Mode pin.Func
State int
}
func ParsePinStateResponse(data []byte) PinStateResponse {
var response = PinStateResponse{
Pin: data[0],
Mode: pinModeToFuncMap[data[1]],
State: 0,
}
for i, b := range data[2:] {
response.State |= int(b << (i * 7))
}
return response
}
func (p PinStateResponse) String() string {
return fmt.Sprintf("pin(%d) mode(%s) state(%d)", p.Pin, p.Mode, p.State)
}