Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# Added by goreleaser init:
dist/

# Build artifacts
bin/

# Claude Code artifacts
.claude/
14 changes: 7 additions & 7 deletions cmd/gotoMemory.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"tinygo.org/x/bluetooth"
)

var memory_num int
var memoryNum int
var j *jiecang.Jiecang

var gotoMemoryCmd = &cobra.Command{
Expand All @@ -26,9 +26,9 @@ var gotoMemoryCmd = &cobra.Command{
PreRun: func(cmd *cobra.Command, args []string) {
var err error
// Validate that argument is an integer between 1 and 3
memory_num, err = strconv.Atoi(args[0])
if err != nil || memory_num < 1 || memory_num > 3 {
fmt.Fprintf(os.Stderr, "Memory number is not within boundaries (1-3): %d\n", memory_num)
memoryNum, err = strconv.Atoi(args[0])
if err != nil || memoryNum < 1 || memoryNum > 3 {
fmt.Fprintf(os.Stderr, "Memory number is not within boundaries (1-3): %d\n", memoryNum)
os.Exit(1)
}

Expand All @@ -55,7 +55,7 @@ var gotoMemoryCmd = &cobra.Command{
defer cancel()

var err error
switch memory_num {
switch memoryNum {
case 1:
err = j.GoToMemory1(opCtx)
case 2:
Expand All @@ -64,11 +64,11 @@ var gotoMemoryCmd = &cobra.Command{
err = j.GoToMemory3(opCtx)
default:
// We should never reach this state as we validate this argument with PreRun hook.
fmt.Fprintf(os.Stderr, "Memory %d is not within boundaries (1-3)\n", memory_num)
fmt.Fprintf(os.Stderr, "Memory %d is not within boundaries (1-3)\n", memoryNum)
os.Exit(1)
}
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to go to memory %d: %v\n", memory_num, err)
fmt.Fprintf(os.Stderr, "Failed to go to memory %d: %v\n", memoryNum, err)
os.Exit(1)
}
},
Expand Down
4 changes: 2 additions & 2 deletions cmd/listDevices.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ func onScan(adapter *bluetooth.Adapter, device bluetooth.ScanResult) {

//Print results
fmt.Printf("%-20s %-20s %-10s\n", "ADDRESS", "NAME", "RSSI")
for device_address, device := range results {
fmt.Printf("%-20s %-20s %-10d\n", device_address, device.LocalName(), device.RSSI)
for deviceAddr, device := range results {
fmt.Printf("%-20s %-20s %-10d\n", deviceAddr, device.LocalName(), device.RSSI)
}
} else {
mu.Lock()
Expand Down
16 changes: 8 additions & 8 deletions pkg/jiecang/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ func isValidData(buf []byte) bool {
}

// Calculate checksum and verify if its correct
data_type := int(buf[2])
data_len := int(buf[3])
dataType := int(buf[2])
dataLen := int(buf[3])
// Length of the data should not exceed the length of the payload.
// Last two bytes should always be the checksum and EoM (Ox7e)
if data_len+3 >= len(buf)-2 {
if dataLen+3 >= len(buf)-2 {
return false
}
received_checksum := int(buf[len(buf)-2])
receivedChecksum := int(buf[len(buf)-2])

calc_checksum := data_type + data_len
for i := 0; i < data_len; i++ {
calc_checksum += int(buf[4+i])
calcChecksum := dataType + dataLen
for i := 0; i < dataLen; i++ {
calcChecksum += int(buf[4+i])
}
return (calc_checksum % 256) == received_checksum
return (calcChecksum % 256) == receivedChecksum
}
4 changes: 2 additions & 2 deletions pkg/jiecang/jiecang.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ func (j *Jiecang) characteristicReceiver(buf []byte) {
j.mu.Unlock()
case 0x25, 0x26, 0x27, 0x28: // Data contains height for each memory preset (1-4). Memory 4 is currently 0
memory := int(msg[i][2] % 0x24)
memory_name := fmt.Sprintf("memory%d", memory)
memoryName := fmt.Sprintf("memory%d", memory)
j.mu.Lock()
j.presets[memory_name] = readMemoryPreset(msg[i])
j.presets[memoryName] = readMemoryPreset(msg[i])
j.mu.Unlock()
case 0x0e: // Data contains units setting
fmt.Printf("Unit settings: %x\n", msg[i][3])
Expand Down
Loading