mirror of
https://github.com/jwetzell/free-d-go.git
synced 2026-09-07 06:48:59 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 21beb6316e | |||
| 4ec174462b |
@@ -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)
|
||||||
@@ -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 {
|
||||||
|
|||||||
Reference in New Issue
Block a user