2 Commits

Author SHA1 Message Date
Joel Wetzell 21beb6316e remove panics 2026-05-14 14:53:15 -05:00
jwetzell 4ec174462b fix readme 2024-12-26 17:41:32 -06:00
2 changed files with 8 additions and 15 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
# free-d-js
# free-d-go
Collection of free-d things written in Go
- [free-d encoding/decoding library](./pkg/free-d/)
- [free-d encoding/decoding library](./free_d.go)
+6 -13
View File
@@ -1,7 +1,6 @@
package freeD
import (
"bytes"
"encoding/binary"
"errors"
"math"
@@ -100,23 +99,17 @@ func checksum(bytes []byte) uint8 {
func rotationToFreeDUnits(rotation float32) []byte {
units := int32(rotation * 32768 * 256)
var buf bytes.Buffer
err := binary.Write(&buf, binary.BigEndian, units)
if err != nil {
panic(err)
}
return buf.Bytes()[0:3]
buf := make([]byte, 4)
binary.BigEndian.PutUint32(buf, uint32(units))
return buf[0:3]
}
func positionToFreeDUnits(position float32) []byte {
units := int32(position * 64 * 256)
var buf bytes.Buffer
err := binary.Write(&buf, binary.BigEndian, units)
if err != nil {
panic(err)
}
return buf.Bytes()[0:3]
buf := make([]byte, 4)
binary.BigEndian.PutUint32(buf, uint32(units))
return buf[0:3]
}
func freeDUnitsToRotation(upper uint8, middle uint8, lower uint8) float32 {