Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvements #26

Merged
merged 10 commits into from
Jan 16, 2024
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
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.19
require (
github.com/bgould/tinygo-rotary-encoder v0.0.0-20231106003644-94bb14d88946
github.com/itchio/lzma v0.0.0-20190703113020-d3e24e3e3d49
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b
tinygo.org/x/drivers v0.25.0
tinygo.org/x/tinydraw v0.3.0
tinygo.org/x/tinyfont v0.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
github.com/bgould/http v0.0.0-20190627042742-d268792bdee7/go.mod h1:BTqvVegvwifopl4KTEDth6Zezs9eR+lCWhvGKvkxJHE=
github.com/bgould/tinygo-rotary-encoder v0.0.0-20221224155058-c26fcc9a3d20 h1:V+y/i2c6xdvTB/gmiYdlj1/lc9XVEPDysxe6+7U5Yt4=
github.com/bgould/tinygo-rotary-encoder v0.0.0-20221224155058-c26fcc9a3d20/go.mod h1:vozFQeh667GysGEvJ6GKutjAOilleV5usLdxYan+XYM=
github.com/bgould/tinygo-rotary-encoder v0.0.0-20231106003644-94bb14d88946 h1:WpPlCYe9fY1nvOxoaIql88KewO1pMMv+/mdcC8zpnsI=
github.com/bgould/tinygo-rotary-encoder v0.0.0-20231106003644-94bb14d88946/go.mod h1:vozFQeh667GysGEvJ6GKutjAOilleV5usLdxYan+XYM=
github.com/eclipse/paho.mqtt.golang v1.2.0/go.mod h1:H9keYFcgq3Qr5OUJm/JZI/i6U7joQ8SYLhZwfeOo6Ts=
Expand All @@ -16,6 +14,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/sago35/go-bdf v0.0.0-20200313142241-6c17821c91c4/go.mod h1:rOebXGuMLsXhZAC6mF/TjxONsm45498ZyzVhel++6KM=
github.com/valyala/fastjson v1.6.3/go.mod h1:CLCAqky6SMuOcxStkYQvblddUtoRxhYMGLrsQns1aXY=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b h1:kLiC65FbiHWFAOu+lxwNPujcsl8VYyTYYEZnsOO1WK4=
golang.org/x/exp v0.0.0-20231226003508-02704c960a9b/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
16 changes: 6 additions & 10 deletions kbduplexmatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func (d *DuplexMatrixKeyboard) SetCallback(fn Callback) {
d.callback = fn
}

func (d *DuplexMatrixKeyboard) Callback(layer, index int, state State) {
if d.callback != nil {
d.callback(layer, index, state)
}
}

func (d *DuplexMatrixKeyboard) Get() []State {
for c := range d.Col {
d.Col[c].Configure(machine.PinConfig{Mode: machine.PinOutput})
Expand All @@ -81,19 +87,15 @@ func (d *DuplexMatrixKeyboard) Get() []State {
case NoneToPress:
if current {
d.State[idx] = Press
d.callback(0, idx, Press)
} else {
d.State[idx] = PressToRelease
d.callback(0, idx, Press)
d.callback(0, idx, PressToRelease)
}
case Press:
if current {
d.cycleCounter[idx] = 0
} else {
if d.cycleCounter[idx] >= duplexMatrixCyclesToPreventChattering {
d.State[idx] = PressToRelease
d.callback(0, idx, PressToRelease)
d.cycleCounter[idx] = 0
} else {
d.cycleCounter[idx]++
Expand All @@ -102,7 +104,6 @@ func (d *DuplexMatrixKeyboard) Get() []State {
case PressToRelease:
if current {
d.State[idx] = NoneToPress
d.callback(0, idx, Press)
} else {
d.State[idx] = None
}
Expand Down Expand Up @@ -133,19 +134,15 @@ func (d *DuplexMatrixKeyboard) Get() []State {
case NoneToPress:
if current {
d.State[idx] = Press
d.callback(0, idx, Press)
} else {
d.State[idx] = PressToRelease
d.callback(0, idx, Press)
d.callback(0, idx, PressToRelease)
}
case Press:
if current {
d.cycleCounter[idx] = 0
} else {
if d.cycleCounter[idx] >= duplexMatrixCyclesToPreventChattering {
d.State[idx] = PressToRelease
d.callback(0, idx, PressToRelease)
d.cycleCounter[idx] = 0
} else {
d.cycleCounter[idx]++
Expand All @@ -154,7 +151,6 @@ func (d *DuplexMatrixKeyboard) Get() []State {
case PressToRelease:
if current {
d.State[idx] = NoneToPress
d.callback(0, idx, Press)
} else {
d.State[idx] = None
}
Expand Down
11 changes: 6 additions & 5 deletions kbgpio.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func (d *GpioKeyboard) SetCallback(fn Callback) {
d.callback = fn
}

func (d *GpioKeyboard) Callback(layer, index int, state State) {
if d.callback != nil {
d.callback(layer, index, state)
}
}

func (d *GpioKeyboard) Get() []State {
for c := range d.Col {
current := d.Col[c].Get()
Expand All @@ -80,19 +86,15 @@ func (d *GpioKeyboard) Get() []State {
case NoneToPress:
if current {
d.State[c] = Press
d.callback(0, c, Press)
} else {
d.State[c] = PressToRelease
d.callback(0, c, Press)
d.callback(0, c, PressToRelease)
}
case Press:
if current {
d.cycleCounter[c] = 0
} else {
if d.cycleCounter[c] >= gpioCyclesToPreventChattering {
d.State[c] = PressToRelease
d.callback(0, c, PressToRelease)
d.cycleCounter[c] = 0
} else {
d.cycleCounter[c]++
Expand All @@ -101,7 +103,6 @@ func (d *GpioKeyboard) Get() []State {
case PressToRelease:
if current {
d.State[c] = NoneToPress
d.callback(0, c, Press)
} else {
d.State[c] = None
}
Expand Down
11 changes: 6 additions & 5 deletions kbmatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func (d *MatrixKeyboard) SetCallback(fn Callback) {
d.callback = fn
}

func (d *MatrixKeyboard) Callback(layer, index int, state State) {
if d.callback != nil {
d.callback(layer, index, state)
}
}

func (d *MatrixKeyboard) Get() []State {
for c := range d.Col {
for r := range d.Row {
Expand Down Expand Up @@ -95,19 +101,15 @@ func (d *MatrixKeyboard) Get() []State {
case NoneToPress:
if current {
d.State[idx] = Press
d.callback(0, idx, Press)
} else {
d.State[idx] = PressToRelease
d.callback(0, idx, Press)
d.callback(0, idx, PressToRelease)
}
case Press:
if current {
d.cycleCounter[idx] = 0
} else {
if d.cycleCounter[idx] >= matrixCyclesToPreventChattering {
d.State[idx] = PressToRelease
d.callback(0, idx, PressToRelease)
d.cycleCounter[idx] = 0
} else {
d.cycleCounter[idx]++
Expand All @@ -116,7 +118,6 @@ func (d *MatrixKeyboard) Get() []State {
case PressToRelease:
if current {
d.State[idx] = NoneToPress
d.callback(0, idx, Press)
} else {
d.State[idx] = None
}
Expand Down
11 changes: 6 additions & 5 deletions kbrotary.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func (d *RotaryKeyboard) SetCallback(fn Callback) {
d.callback = fn
}

func (d *RotaryKeyboard) Callback(layer, index int, state State) {
if d.callback != nil {
d.callback(layer, index, state)
}
}

func (d *RotaryKeyboard) Get() []State {
rot := []bool{false, false}
if newValue := d.enc.Value(); newValue != d.oldValue {
Expand All @@ -70,22 +76,17 @@ func (d *RotaryKeyboard) Get() []State {
case NoneToPress:
if current {
d.State[c] = Press
d.callback(0, c, Press)
} else {
d.State[c] = PressToRelease
d.callback(0, c, Press)
d.callback(0, c, PressToRelease)
}
case Press:
if current {
} else {
d.State[c] = PressToRelease
d.callback(0, c, PressToRelease)
}
case PressToRelease:
if current {
d.State[c] = NoneToPress
d.callback(0, c, Press)
} else {
d.State[c] = None
}
Expand Down
11 changes: 6 additions & 5 deletions kbshifter.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ func (d *ShifterKeyboard) SetCallback(fn Callback) {
d.callback = fn
}

func (d *ShifterKeyboard) Callback(layer, index int, state State) {
if d.callback != nil {
d.callback(layer, index, state)
}
}

func (d *ShifterKeyboard) Get() []State {
d.Shifter.Read8Input()

Expand All @@ -68,22 +74,17 @@ func (d *ShifterKeyboard) Get() []State {
case NoneToPress:
if current {
d.State[c] = Press
d.callback(0, c, Press)
} else {
d.State[c] = PressToRelease
d.callback(0, c, Press)
d.callback(0, c, PressToRelease)
}
case Press:
if current {
} else {
d.State[c] = PressToRelease
d.callback(0, c, PressToRelease)
}
case PressToRelease:
if current {
d.State[c] = NoneToPress
d.callback(0, c, Press)
} else {
d.State[c] = None
}
Expand Down
11 changes: 6 additions & 5 deletions kbsquaredmatrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ func (d *SquaredMatrixKeyboard) SetCallback(fn Callback) {
d.callback = fn
}

func (d *SquaredMatrixKeyboard) Callback(layer, index int, state State) {
if d.callback != nil {
d.callback(layer, index, state)
}
}

func (d *SquaredMatrixKeyboard) Get() []State {
c := int(0)
cols := []int{}
Expand Down Expand Up @@ -85,19 +91,15 @@ func (d *SquaredMatrixKeyboard) Get() []State {
case NoneToPress:
if current {
d.State[idx] = Press
d.callback(0, idx, Press)
} else {
d.State[idx] = PressToRelease
d.callback(0, idx, Press)
d.callback(0, idx, PressToRelease)
}
case Press:
if current {
d.cycleCounter[idx] = 0
} else {
if d.cycleCounter[idx] >= squaredMatrixCyclesToPreventChattering {
d.State[idx] = PressToRelease
d.callback(0, idx, PressToRelease)
d.cycleCounter[idx] = 0
} else {
d.cycleCounter[idx]++
Expand All @@ -106,7 +108,6 @@ func (d *SquaredMatrixKeyboard) Get() []State {
case PressToRelease:
if current {
d.State[idx] = NoneToPress
d.callback(0, idx, Press)
} else {
d.State[idx] = None
}
Expand Down
10 changes: 6 additions & 4 deletions kbuart.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ func (d *UartKeyboard) SetCallback(fn Callback) {
d.callback = fn
}

func (d *UartKeyboard) Callback(layer, index int, state State) {
if d.callback != nil {
d.callback(layer, index, state)
}
}

func (d *UartKeyboard) Get() []State {
uart := d.uart

Expand Down Expand Up @@ -78,26 +84,22 @@ func (d *UartKeyboard) Get() []State {
case None:
if current {
d.State[index] = NoneToPress
d.callback(0, index, Press)
} else {
}
case NoneToPress:
if current {
d.State[index] = Press
} else {
d.State[index] = PressToRelease
d.callback(0, index, PressToRelease)
}
case Press:
if current {
} else {
d.State[index] = PressToRelease
d.callback(0, index, PressToRelease)
}
case PressToRelease:
if current {
d.State[index] = NoneToPress
d.callback(0, index, Press)
} else {
d.State[index] = None
}
Expand Down
Loading