From fc3669937463b329a815f148106241883020388e Mon Sep 17 00:00:00 2001 From: Dimitri Sokolyuk Date: Thu, 29 Dec 2016 21:08:59 +0100 Subject: Lights --- protocol.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'protocol.go') diff --git a/protocol.go b/protocol.go index 273967f..5c39db4 100644 --- a/protocol.go +++ b/protocol.go @@ -1,6 +1,9 @@ package anki -import "encoding/binary" +import ( + "bytes" + "encoding/binary" +) // VehicleMsgMaxSize = 20 // VehicleMsgPayloadMaxSize = 18 @@ -67,6 +70,15 @@ func SplitMsg(b []byte) (id ID, payload []byte) { return ID(b[1]), b[2:] } +func Encode(v interface{}) []byte { + buf := new(bytes.Buffer) + binary.Write(buf, binary.LittleEndian, v) + b := buf.Bytes()[:] + z := make([]byte, len(b)) + copy(z, b) // FIXME workaround "cgo argument has Go pointer to Go pointer" + return z +} + type VehicleMsgVersionResponse struct { Size uint8 MsgID ID @@ -304,7 +316,7 @@ func (v *VehicleLightConfig) Set(channel, effect uint8, start, end uint8, cycles if cpm > VehicleMaxLightTime { cpm = VehicleMaxLightTime } - v.Cycles = uint8(cpm / 6) + v.Cycles = uint8(cpm / 6) // BUG integer division } type VehicleMsgLightsPattern struct { -- cgit v1.2.3