diff options
| author | Sam Anthony <sam@samanthony.xyz> | 2025-11-07 19:10:23 -0500 |
|---|---|---|
| committer | Sam Anthony <sam@samanthony.xyz> | 2025-11-07 19:10:23 -0500 |
| commit | c43588e172917783843133eb0061bf0d118ae5d5 (patch) | |
| tree | c748fecb1b530422c57dae449064cd8a5beb6c6a /sw/cal/table.go | |
| parent | 688972df9daa1f80d24feff5c056ab3a66c4eee9 (diff) | |
| download | can-gauge-interface-c43588e172917783843133eb0061bf0d118ae5d5.zip | |
cal: transmit table to CAN bus
Diffstat (limited to 'sw/cal/table.go')
| -rw-r--r-- | sw/cal/table.go | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sw/cal/table.go b/sw/cal/table.go new file mode 100644 index 0000000..20d21d0 --- /dev/null +++ b/sw/cal/table.go @@ -0,0 +1,28 @@ +package main + +import ( + "fmt" + "slices" +) + +const tabRows = 32 + +type Table struct { + keys []int32 + vals []uint16 +} + +func (t *Table) Insert(key int32, val uint16) error { + if len(t.keys) >= tabRows { + return fmt.Errorf("too many rows") + } + + i, ok := slices.BinarySearch(t.keys, key) + if ok { + return ErrDupKey{key} + } + t.keys = slices.Insert(t.keys, i, key) + t.vals = slices.Insert(t.vals, i, val) + + return nil +} |