mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-07-27 11:08:41 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 592f66e1ca | |||
| 71c77d4b53 | |||
| 1f54c7dd23 | |||
| d0163c67f5 |
@@ -15,8 +15,8 @@ var (
|
||||
|
||||
func main() {
|
||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
button.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||||
key = makeybutton.NewButton(button)
|
||||
key.Configure()
|
||||
|
||||
for {
|
||||
switch key.Get() {
|
||||
@@ -25,6 +25,6 @@ func main() {
|
||||
case makeybutton.Released:
|
||||
led.Low()
|
||||
}
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ func Setup() (*rtl8720dn.RTL8720DN, error) {
|
||||
rtl := rtl8720dn.New(uart)
|
||||
rtl.Debug(debug)
|
||||
|
||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||
_, err := rtl.Rpc_tcpip_adapter_init_with_timeout(10 * time.Second)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ require (
|
||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||
github.com/frankban/quicktest v1.10.2
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
||||
tinygo.org/x/tinyfont v0.2.1
|
||||
tinygo.org/x/tinyfont v0.3.0
|
||||
tinygo.org/x/tinyfs v0.2.0
|
||||
tinygo.org/x/tinyterm v0.1.0
|
||||
)
|
||||
|
||||
@@ -5,12 +5,15 @@ github.com/frankban/quicktest v1.10.2 h1:19ARM85nVi4xH7xPXuc5eM/udya5ieh7b/Sv+d8
|
||||
github.com/frankban/quicktest v1.10.2/go.mod h1:K+q6oSqb0W0Ininfk863uOk1lMy69l/P6txr3mVT54s=
|
||||
github.com/google/go-cmp v0.5.2 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||
github.com/hajimehoshi/go-jisx0208 v1.0.0/go.mod h1:yYxEStHL7lt9uL+AbdWgW9gBumwieDoZCiB1f/0X0as=
|
||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||
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 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
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/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM=
|
||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
||||
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=
|
||||
@@ -25,8 +28,9 @@ 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/tinyfont v0.2.1 h1:FAaemBzw8wsfhAtG6fWW+QjyWw/K8YqEeiWo4N1pv4o=
|
||||
tinygo.org/x/tinyfont v0.2.1/go.mod h1:eLqnYSrFRjt5STxWaMeOWJTzrKhXqpWw7nU3bPfKOAM=
|
||||
tinygo.org/x/tinyfont v0.3.0 h1:HIRLQoI3oc+2CMhPcfv+Ig88EcTImE/5npjqOnMD4lM=
|
||||
tinygo.org/x/tinyfont v0.3.0/go.mod h1:+TV5q0KpwSGRWnN+ITijsIhrWYJkoUCp9MYELjKpAXk=
|
||||
tinygo.org/x/tinyfs v0.1.0/go.mod h1:ysc8Y92iHfhTXeyEM9+c7zviUQ4fN9UCFgSOFfMWv20=
|
||||
tinygo.org/x/tinyfs v0.2.0 h1:M0lwZC/dEGFt16XYN5GTQsif/qCkAN2qUVNxELVD1xg=
|
||||
tinygo.org/x/tinyfs v0.2.0/go.mod h1:6ZHYdvB3sFYeMB3ypmXZCNEnFwceKc61ADYTYHpep1E=
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package makeybutton
|
||||
|
||||
const bufferSize = 10
|
||||
const bufferSize = 6
|
||||
|
||||
// Buffer is a buffer to keep track of the most recent readings for a button.
|
||||
type Buffer struct {
|
||||
|
||||
+17
-5
@@ -6,7 +6,10 @@
|
||||
//
|
||||
package makeybutton
|
||||
|
||||
import "machine"
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ButtonState represents the state of a MakeyButton.
|
||||
type ButtonState int
|
||||
@@ -36,9 +39,6 @@ type Button struct {
|
||||
|
||||
// NewButton creates a new Button.
|
||||
func NewButton(pin machine.Pin) *Button {
|
||||
pin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
pin.Set(false)
|
||||
|
||||
return &Button{
|
||||
pin: pin,
|
||||
state: NeverPressed,
|
||||
@@ -47,6 +47,18 @@ func NewButton(pin machine.Pin) *Button {
|
||||
}
|
||||
}
|
||||
|
||||
// Configure configures the Makey Button pin to have the correct settings to detect touches.
|
||||
func (b *Button) Configure() error {
|
||||
// Note that we have to first turn on the pullup, and then turn off the pullup,
|
||||
// in order for the pin to be properly floating.
|
||||
b.pin.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
b.pin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||
b.pin.Set(false)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Get returns a ButtonEvent based on the most recent state of the button,
|
||||
// and if it has changed by being pressed or released.
|
||||
func (b *Button) Get() ButtonEvent {
|
||||
@@ -61,7 +73,7 @@ func (b *Button) Get() ButtonEvent {
|
||||
b.readings.Put(pressed)
|
||||
|
||||
switch {
|
||||
case pressed && avg > 0:
|
||||
case pressed && avg > -1*bufferSize+2:
|
||||
if b.state == Press {
|
||||
return NotChanged
|
||||
}
|
||||
|
||||
+32
-1
@@ -1,6 +1,10 @@
|
||||
package rtl8720dn
|
||||
|
||||
import "io"
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
const maxUartRecvSize = 128
|
||||
|
||||
@@ -38,6 +42,33 @@ func New(r io.ReadWriter) *RTL8720DN {
|
||||
return ret
|
||||
}
|
||||
|
||||
func (r *RTL8720DN) Rpc_tcpip_adapter_init_with_timeout(d time.Duration) (int32, error) {
|
||||
timeout := make(chan bool)
|
||||
go func() {
|
||||
time.Sleep(d)
|
||||
timeout <- true
|
||||
}()
|
||||
|
||||
var ret int32
|
||||
var err error
|
||||
done := make(chan bool)
|
||||
go func() {
|
||||
ret, err = r.Rpc_tcpip_adapter_init()
|
||||
done <- true
|
||||
}()
|
||||
|
||||
select {
|
||||
case <-timeout:
|
||||
return ret, fmt.Errorf("Rpc_tcpip_adapter_init: timeout")
|
||||
case <-done:
|
||||
if err != nil {
|
||||
return ret, err
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func (r *RTL8720DN) SetSeq(s uint64) {
|
||||
r.seq = s
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user