From 91b4bd81e7732bcaea66a203da69f0a164396199 Mon Sep 17 00:00:00 2001 From: baldeau Date: Mon, 18 Nov 2024 23:59:40 +0100 Subject: [PATCH] clean --- xiao_controller_code/Makefile | 7 ++- xiao_controller_code/main.go | 38 ++++-------- xiao_controller_code/test.go | 106 ---------------------------------- 3 files changed, 17 insertions(+), 134 deletions(-) delete mode 100644 xiao_controller_code/test.go diff --git a/xiao_controller_code/Makefile b/xiao_controller_code/Makefile index 36f7072..3dc4f9b 100644 --- a/xiao_controller_code/Makefile +++ b/xiao_controller_code/Makefile @@ -4,7 +4,10 @@ prepare: ./flashing_time.py flash: - tinygo flash -target=xiao-ble + tinygo flash -target=xiao-ble -size=short production: - tinygo flash -target=xiao-ble -serial=none -size=short -opt=z -gc=leaking -scheduler=tasks \ No newline at end of file + tinygo flash -target=xiao-ble -serial=none -size=short + +testing: + tinygo flash -target=xiao-ble -serial=none -size=short -opt=2 -gc=leaking -scheduler=tasks \ No newline at end of file diff --git a/xiao_controller_code/main.go b/xiao_controller_code/main.go index 9699832..0ebae45 100644 --- a/xiao_controller_code/main.go +++ b/xiao_controller_code/main.go @@ -2,6 +2,7 @@ package main import ( "encoding/binary" + "fmt" "machine" "time" @@ -134,6 +135,7 @@ func main() { arrAcc := valuesToByteArray(x, y, z, int8(2)) currentTimeStamp = currentTimeStamp.Add(time.Now().Sub(lastTimeStamp)) + fmt.Println("TIME: ", time.Now().Sub(lastTimeStamp)) arrTime := timeStampToByteArray(currentTimeStamp.UnixMilli(), int8(3)) senseCharacteristic.Write(arrRot) @@ -149,35 +151,19 @@ func main() { } func valuesToByteArray(x int32, y int32, z int32, p int8) []byte { - arr := make([]byte, 13) - arr[0] = byte(x) - arr[1] = byte(x >> 8) - arr[2] = byte(x >> 16) - arr[3] = byte(x >> 24) - arr[4] = byte(y) - arr[5] = byte(y >> 8) - arr[6] = byte(y >> 16) - arr[7] = byte(y >> 24) - arr[8] = byte(z) - arr[9] = byte(z >> 8) - arr[10] = byte(z >> 16) - arr[11] = byte(z >> 24) - arr[12] = byte(p) - return arr + byteSlice := make([]byte, 13) + binary.LittleEndian.PutUint32(byteSlice, uint32(x)) + binary.LittleEndian.PutUint32(byteSlice[4:], uint32(y)) + binary.LittleEndian.PutUint32(byteSlice[8:], uint32(z)) + byteSlice[12] = byte(p) + return byteSlice } func timeStampToByteArray(value int64, p int8) []byte { - arr := make([]byte, 9) - arr[0] = byte(value) - arr[1] = byte(value >> 8) - arr[2] = byte(value >> 16) - arr[3] = byte(value >> 24) - arr[4] = byte(value >> 32) - arr[5] = byte(value >> 40) - arr[6] = byte(value >> 48) - arr[7] = byte(value >> 56) - arr[8] = byte(p) - return arr + byteSlice := make([]byte, 9) + binary.LittleEndian.PutUint64(byteSlice, uint64(value)) + byteSlice[8] = byte(p) + return byteSlice } func must(action string, err error) { diff --git a/xiao_controller_code/test.go b/xiao_controller_code/test.go deleted file mode 100644 index b644d76..0000000 --- a/xiao_controller_code/test.go +++ /dev/null @@ -1,106 +0,0 @@ -package main - -// import ( -// "encoding/binary" -// "fmt" -// "unsafe" -// ) - -// func main() { -// const x int32 = 2017403647 -// const y int32 = 1010101010 -// const z int32 = 2020202020 - -// // bytearr := valuesToByteArrayTest(x, y, z, 1) -// // fmt.Println("TEST: ", bytearr) - -// // slice := binary.LittleEndian.Uint32(bytearr[0:4]) -// // fmt.Println("SLICE:", slice) - -// // slice2 := binary.LittleEndian.Uint32(bytearr[4:8]) -// // fmt.Println("SLICE2:", slice2) - -// bs := make([]byte, 4) -// binary.LittleEndian.PutUint32(bs, uint32(y)) -// fmt.Println(bs) - -// // buf := make([]byte, 4) -// // arr[0] = byte(x >> 8) - -// // buf[0], buf[1], buf[2] = uint8(7676767>>16), uint8(id>>8), uint8(id) - -// bytearr := valuesToByteArray3(x, y, z, 1) -// fmt.Println("TEST: ", bytearr) - -// slice := binary.LittleEndian.Uint32(bytearr[0:4]) -// fmt.Println("SLICE:", slice) - -// slice2 := binary.LittleEndian.Uint32(bytearr[4:8]) -// fmt.Println("SLICE2:", slice2) - -// } - -// func valuesToByteArrayOld(x int32, y int32, z int32, p int8) []byte { -// arr := make([]byte, 13) -// for i := 0; i < 12; i++ { -// var test unsafe.Pointer -// var test2 unsafe.Pointer -// var test3 unsafe.Pointer -// if i < 4 { -// test = unsafe.Pointer(&x) -// } else if i < 8 { -// test2 = unsafe.Pointer(&y) -// } else if i < 12 { -// test3 = unsafe.Pointer(&z) -// } -// byt := *(*uint8)(unsafe.Pointer(uintptr(test) + uintptr(i))) -// arr[i] = byt -// } -// arr[12] = byte(p) -// return arr -// } - -// func valuesToByteArray1(x int32, y int32, z int32, p int8) []byte { -// arr := make([]byte, 13) -// arr[0] = byte(x) -// arr[1] = byte(x >> 8) -// arr[2] = byte(x >> 16) -// arr[3] = byte(x >> 24) -// arr[4] = byte(y) -// arr[5] = byte(y >> 8) -// arr[6] = byte(y >> 16) -// arr[7] = byte(y >> 24) -// arr[8] = byte(z) -// arr[9] = byte(z >> 8) -// arr[10] = byte(z >> 16) -// arr[11] = byte(z >> 24) -// arr[12] = byte(p) -// return arr -// } - -// func valuesToByteArray2(x int32, y int32, z int32, p int8) []byte { -// buf := make([]byte, 13) -// binary.LittleEndian.PutUint32(buf[0:], uint32(x)) -// binary.LittleEndian.PutUint32(buf[4:], uint32(y)) -// binary.LittleEndian.PutUint32(buf[8:], uint32(z)) -// buf[12] = byte(p) -// return buf -// } - -// func valuesToByteArray3(x int32, y int32, z int32, p int8) []byte { -// arr := make([]byte, 13) -// for i := 0; i < 12; i++ { -// var test unsafe.Pointer -// if i < 4 { -// test = unsafe.Pointer(&x) -// } else if i < 8 { -// test = unsafe.Pointer(&y) -// } else if i < 12 { -// test = unsafe.Pointer(&z) -// } -// byt := *(*uint8)(unsafe.Pointer(uintptr(test) + uintptr(i))) -// arr[i] = byt -// } -// arr[12] = byte(p) -// return arr -// }