From 1f0852885672ff70f17a92b7195706bf1779101d Mon Sep 17 00:00:00 2001 From: sago35 Date: Thu, 18 Jul 2024 22:23:38 +0900 Subject: [PATCH] Add device.GetKeyboardCount() (#43) --- keyboard.go | 4 ++++ via.go | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/keyboard.go b/keyboard.go index 024d4ab..93c85b2 100644 --- a/keyboard.go +++ b/keyboard.go @@ -134,6 +134,10 @@ func (d *Device) Init() error { return nil } +func (d *Device) GetKeyboardCount() int { + return len(d.kb) +} + func (d *Device) GetMaxKeyCount() int { cnt := 0 for _, k := range d.kb { diff --git a/via.go b/via.go index 08c2214..85ffbdc 100644 --- a/via.go +++ b/via.go @@ -144,8 +144,8 @@ func rxHandler2(b []byte) bool { for i := 0; i < int(sz/2); i++ { //fmt.Printf(" %02X %02X\n", b[4+i+1], b[4+i+0]) tmp := i + int(offset)/2 - layer := tmp / (cnt * len(device.kb)) - tmp = tmp % (cnt * len(device.kb)) + layer := tmp / (cnt * device.GetKeyboardCount()) + tmp = tmp % (cnt * device.GetKeyboardCount()) kbd := tmp / cnt idx := tmp % cnt //layer := 0 @@ -265,7 +265,7 @@ func rxHandler2(b []byte) bool { func Save() error { layers := 6 - keyboards := len(device.kb) + keyboards := device.GetKeyboardCount() cnt := device.GetMaxKeyCount() wbuf := make([]byte, 4+layers*keyboards*cnt*2+len(device.Macros))