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 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 package freeD
import ( import (
"bytes"
"encoding/binary" "encoding/binary"
"errors" "errors"
"math" "math"
@@ -100,23 +99,17 @@ func checksum(bytes []byte) uint8 {
func rotationToFreeDUnits(rotation float32) []byte { func rotationToFreeDUnits(rotation float32) []byte {
units := int32(rotation * 32768 * 256) units := int32(rotation * 32768 * 256)
var buf bytes.Buffer buf := make([]byte, 4)
err := binary.Write(&buf, binary.BigEndian, units) binary.BigEndian.PutUint32(buf, uint32(units))
if err != nil { return buf[0:3]
panic(err)
}
return buf.Bytes()[0:3]
} }
func positionToFreeDUnits(position float32) []byte { func positionToFreeDUnits(position float32) []byte {
units := int32(position * 64 * 256) units := int32(position * 64 * 256)
var buf bytes.Buffer buf := make([]byte, 4)
err := binary.Write(&buf, binary.BigEndian, units) binary.BigEndian.PutUint32(buf, uint32(units))
if err != nil { return buf[0:3]
panic(err)
}
return buf.Bytes()[0:3]
} }
func freeDUnitsToRotation(upper uint8, middle uint8, lower uint8) float32 { func freeDUnitsToRotation(upper uint8, middle uint8, lower uint8) float32 {