diff --git a/go.mod b/go.mod index 90400e2..36ad461 100644 --- a/go.mod +++ b/go.mod @@ -3,10 +3,9 @@ module github.com/sago35/tinygo-keyboard 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/drivers v0.27.0 tinygo.org/x/tinydraw v0.3.0 tinygo.org/x/tinyfont v0.3.0 ) diff --git a/go.sum b/go.sum index 19d5721..dace614 100644 --- a/go.sum +++ b/go.sum @@ -1,22 +1,17 @@ github.com/bgould/http v0.0.0-20190627042742-d268792bdee7/go.mod h1:BTqvVegvwifopl4KTEDth6Zezs9eR+lCWhvGKvkxJHE= -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= github.com/frankban/quicktest v1.10.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s= github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= -github.com/hajimehoshi/go-jisx0208 v1.0.0/go.mod h1:yYxEStHL7lt9uL+AbdWgW9gBumwieDoZCiB1f/0X0as= github.com/itchio/lzma v0.0.0-20190703113020-d3e24e3e3d49 h1:+YrBMf3rkLjkT10zIHyVE4S7ma4hqvfjl6XgnzZwS6o= github.com/itchio/lzma v0.0.0-20190703113020-d3e24e3e3d49/go.mod h1:avNrevQMli1pYPsz1+HIHMvx95pk6O+6otbWqCZPeZI= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= 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= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -28,8 +23,8 @@ tinygo.org/x/drivers v0.14.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2 tinygo.org/x/drivers v0.15.1/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI= tinygo.org/x/drivers v0.16.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI= tinygo.org/x/drivers v0.19.0/go.mod h1:uJD/l1qWzxzLx+vcxaW0eY464N5RAgFi1zTVzASFdqI= -tinygo.org/x/drivers v0.25.0 h1:MFnec5lY8Sxk1bIfqQWsflIbxcpAFbohWhg/qZ7psdM= -tinygo.org/x/drivers v0.25.0/go.mod h1:v+mXaA4cgpz/YZJ3ZPm/86bYQJAXTaYtMkHlVwbodbw= +tinygo.org/x/drivers v0.27.0 h1:TEGk1lQvEhXxfvpEhUu+pwmCnhtldPI+hpHlO9VYixI= +tinygo.org/x/drivers v0.27.0/go.mod h1:q/mU8G/wz821p8xXqbkBACOlmZFDHXd//DnYnCW+dDQ= tinygo.org/x/tinydraw v0.3.0 h1:OjsdMcES5+7IIs/4diFpq/pWFsa0VKtbi1mURuj2q64= tinygo.org/x/tinydraw v0.3.0/go.mod h1:Yz0vLSP2rHsIKpLYkEmLnE+2zyhhITu2LxiVtLRiW6I= tinygo.org/x/tinyfont v0.2.1/go.mod h1:eLqnYSrFRjt5STxWaMeOWJTzrKhXqpWw7nU3bPfKOAM= diff --git a/kbrotary.go b/kbrotary.go index 38151d5..1a1c91f 100644 --- a/kbrotary.go +++ b/kbrotary.go @@ -1,11 +1,11 @@ -//go:build tinygo +//go:build tinygo && (rp2040 || stm32 || k210 || esp32c3 || nrf || (avr && (atmega328p || atmega328pb))) package keyboard import ( "machine" - rotary_encoder "github.com/bgould/tinygo-rotary-encoder" + "tinygo.org/x/drivers/encoders" ) type RotaryKeyboard struct { @@ -13,15 +13,17 @@ type RotaryKeyboard struct { Keys [][]Keycode callback Callback - enc *rotary_encoder.Device + enc *encoders.QuadratureDevice oldValue int } func (d *Device) AddRotaryKeyboard(rotA, rotB machine.Pin, keys [][]Keycode) *RotaryKeyboard { state := make([]State, 2) - enc := rotary_encoder.New(rotA, rotB) - enc.Configure() + enc := encoders.NewQuadratureViaInterrupt(rotA, rotB) + enc.Configure(encoders.QuadratureConfig{ + Precision: 4, + }) keydef := make([][]Keycode, LayerCount) for l := 0; l < len(keydef); l++ { @@ -57,7 +59,7 @@ func (d *RotaryKeyboard) Callback(layer, index int, state State) { func (d *RotaryKeyboard) Get() []State { rot := []bool{false, false} - if newValue := d.enc.Value(); newValue != d.oldValue { + if newValue := d.enc.Position(); newValue != d.oldValue { if newValue < d.oldValue { rot[0] = true } else {