mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-14 20:03:40 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f94ef9e535 |
@@ -15,8 +15,8 @@ var (
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
|
button.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||||||
key = makeybutton.NewButton(button)
|
key = makeybutton.NewButton(button)
|
||||||
key.Configure()
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
switch key.Get() {
|
switch key.Get() {
|
||||||
@@ -25,6 +25,6 @@ func main() {
|
|||||||
case makeybutton.Released:
|
case makeybutton.Released:
|
||||||
led.Low()
|
led.Low()
|
||||||
}
|
}
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(30 * time.Millisecond)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// You can override the setting with the init() in another source code.
|
// You can override the setting with the init() in another source code.
|
||||||
@@ -53,12 +52,6 @@ CAUw7C29C79Fv1C5qfPrmAESrciIxpg0X40KPMbp1ZWVbd4=
|
|||||||
-----END CERTIFICATE-----
|
-----END CERTIFICATE-----
|
||||||
`
|
`
|
||||||
|
|
||||||
var buf [0x1000]byte
|
|
||||||
|
|
||||||
var lastRequestTime time.Time
|
|
||||||
var conn net.Conn
|
|
||||||
var adaptor *rtl8720dn.RTL8720DN
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := run()
|
err := run()
|
||||||
for err != nil {
|
for err != nil {
|
||||||
@@ -68,26 +61,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
rtl8720dn.Debug(debug)
|
||||||
|
rtl, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
rtl.SetRootCA(&test_root_ca)
|
rtl.SetRootCA(&test_root_ca)
|
||||||
net.UseDriver(rtl)
|
|
||||||
http.SetBuf(buf[:])
|
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Printf("IP Address : %s\r\n", ip)
|
|
||||||
fmt.Printf("Mask : %s\r\n", subnet)
|
|
||||||
fmt.Printf("Gateway : %s\r\n", gateway)
|
|
||||||
|
|
||||||
// You can send and receive cookies in the following way
|
// You can send and receive cookies in the following way
|
||||||
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
waitSerial()
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -7,7 +7,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
"tinygo.org/x/tinyfont/proggy"
|
"tinygo.org/x/tinyfont/proggy"
|
||||||
"tinygo.org/x/tinyterm"
|
"tinygo.org/x/tinyterm"
|
||||||
@@ -30,7 +30,7 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
terminal = tinyterm.NewTerminal(display)
|
terminal *tinyterm.Terminal
|
||||||
|
|
||||||
black = color.RGBA{0, 0, 0, 255}
|
black = color.RGBA{0, 0, 0, 255}
|
||||||
white = color.RGBA{255, 255, 255, 255}
|
white = color.RGBA{255, 255, 255, 255}
|
||||||
@@ -41,12 +41,10 @@ var (
|
|||||||
font = &proggy.TinySZ8pt7b
|
font = &proggy.TinySZ8pt7b
|
||||||
)
|
)
|
||||||
|
|
||||||
var buf [0x400]byte
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
display.FillScreen(black)
|
display.FillScreen(black)
|
||||||
backlight.High()
|
|
||||||
|
|
||||||
|
terminal = tinyterm.NewTerminal(display)
|
||||||
terminal.Configure(&tinyterm.Config{
|
terminal.Configure(&tinyterm.Config{
|
||||||
Font: font,
|
Font: font,
|
||||||
FontHeight: 10,
|
FontHeight: 10,
|
||||||
@@ -65,29 +63,14 @@ func run() error {
|
|||||||
if debug {
|
if debug {
|
||||||
fmt.Fprintf(terminal, "Running in debug mode.\r\n")
|
fmt.Fprintf(terminal, "Running in debug mode.\r\n")
|
||||||
fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n")
|
fmt.Fprintf(terminal, "A serial connection is required to continue execution.\r\n")
|
||||||
|
rtl8720dn.Debug(true)
|
||||||
}
|
}
|
||||||
rtl, err := setupRTL8720DN()
|
_, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
net.UseDriver(rtl)
|
|
||||||
http.SetBuf(buf[:])
|
|
||||||
|
|
||||||
fmt.Fprintf(terminal, "ConnectToAP()\r\n")
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
fmt.Fprintf(terminal, "connected\r\n\r\n")
|
fmt.Fprintf(terminal, "connected\r\n\r\n")
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Fprintf(terminal, "IP Address : %s\r\n", ip)
|
|
||||||
fmt.Fprintf(terminal, "Mask : %s\r\n", subnet)
|
|
||||||
fmt.Fprintf(terminal, "Gateway : %s\r\n", gateway)
|
|
||||||
|
|
||||||
// You can send and receive cookies in the following way
|
// You can send and receive cookies in the following way
|
||||||
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
||||||
// jar, err := cookiejar.New(nil)
|
// jar, err := cookiejar.New(nil)
|
||||||
|
|||||||
@@ -4,95 +4,15 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"device/sam"
|
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/ili9341"
|
"tinygo.org/x/drivers/ili9341"
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
uart UARTx
|
display *ili9341.Device
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
display = ili9341.NewSPI(
|
|
||||||
machine.SPI3,
|
|
||||||
machine.LCD_DC,
|
|
||||||
machine.LCD_SS_PIN,
|
|
||||||
machine.LCD_RESET,
|
|
||||||
)
|
|
||||||
|
|
||||||
backlight = machine.LCD_BACKLIGHT
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
machine.SPI3.Configure(machine.SPIConfig{
|
display = initdisplay.InitDisplay()
|
||||||
SCK: machine.LCD_SCK_PIN,
|
display.SetRotation(ili9341.Rotation0)
|
||||||
SDO: machine.LCD_SDO_PIN,
|
|
||||||
SDI: machine.LCD_SDI_PIN,
|
|
||||||
Frequency: 40000000,
|
|
||||||
})
|
|
||||||
display.Configure(ili9341.Config{})
|
|
||||||
|
|
||||||
backlight.Configure(machine.PinConfig{machine.PinOutput})
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
if debug {
|
|
||||||
waitSerial()
|
|
||||||
}
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"tinygo.org/x/drivers/net"
|
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,8 +25,6 @@ var (
|
|||||||
debug = false
|
debug = false
|
||||||
)
|
)
|
||||||
|
|
||||||
var buf [0x400]byte
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
err := run()
|
err := run()
|
||||||
for err != nil {
|
for err != nil {
|
||||||
@@ -36,25 +34,10 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
_, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
net.UseDriver(rtl)
|
|
||||||
http.SetBuf(buf[:])
|
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
ip, subnet, gateway, err := rtl.GetIP()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
fmt.Printf("IP Address : %s\r\n", ip)
|
|
||||||
fmt.Printf("Mask : %s\r\n", subnet)
|
|
||||||
fmt.Printf("Gateway : %s\r\n", gateway)
|
|
||||||
|
|
||||||
// You can send and receive cookies in the following way
|
// You can send and receive cookies in the following way
|
||||||
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
// import "tinygo.org/x/drivers/net/http/cookiejar"
|
||||||
|
|||||||
@@ -1,72 +0,0 @@
|
|||||||
//go:build wioterminal
|
|
||||||
// +build wioterminal
|
|
||||||
|
|
||||||
package main
|
|
||||||
|
|
||||||
import (
|
|
||||||
"device/sam"
|
|
||||||
"machine"
|
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
uart UARTx
|
|
||||||
)
|
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
|
||||||
// should reset IRQ
|
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
waitSerial()
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
|
||||||
@@ -2,11 +2,15 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image/color"
|
||||||
"machine"
|
"machine"
|
||||||
"strconv"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/examples/rtl8720dn"
|
||||||
"tinygo.org/x/drivers/net/http"
|
"tinygo.org/x/drivers/net/http"
|
||||||
|
"tinygo.org/x/tinyfont"
|
||||||
|
"tinygo.org/x/tinyfont/freemono"
|
||||||
)
|
)
|
||||||
|
|
||||||
// You can override the setting with the init() in another source code.
|
// You can override the setting with the init() in another source code.
|
||||||
@@ -23,11 +27,9 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var led = machine.LED
|
var led = machine.LED
|
||||||
var backlight = machine.LCD_BACKLIGHT
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||||
backlight.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
|
|
||||||
err := run()
|
err := run()
|
||||||
for err != nil {
|
for err != nil {
|
||||||
@@ -37,13 +39,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func run() error {
|
func run() error {
|
||||||
rtl, err := setupRTL8720DN()
|
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 5, 15, "setup...", color.RGBA{0x00, 0x00, 0x00, 0xFF})
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
http.UseDriver(rtl)
|
|
||||||
|
|
||||||
err = rtl.ConnectToAccessPoint(ssid, password, 10*time.Second)
|
rtl, err := rtl8720dn.SetupAndConnectToAccessPoint(ssid, password, 10*time.Second)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -55,6 +53,8 @@ func run() error {
|
|||||||
fmt.Printf("IP Address : %s\r\n", ip)
|
fmt.Printf("IP Address : %s\r\n", ip)
|
||||||
fmt.Printf("Mask : %s\r\n", subnet)
|
fmt.Printf("Mask : %s\r\n", subnet)
|
||||||
fmt.Printf("Gateway : %s\r\n", gateway)
|
fmt.Printf("Gateway : %s\r\n", gateway)
|
||||||
|
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 5, 15, "setup...done", color.RGBA{0x00, 0x00, 0x00, 0xFF})
|
||||||
|
tinyfont.WriteLine(display, &freemono.Regular9pt7b, 5, 30, fmt.Sprintf("listen:\nhttp://%s/", ip), color.RGBA{0x00, 0x00, 0x00, 0xFF})
|
||||||
|
|
||||||
http.HandleFunc("/", root)
|
http.HandleFunc("/", root)
|
||||||
http.HandleFunc("/hello", hello)
|
http.HandleFunc("/hello", hello)
|
||||||
@@ -154,14 +154,12 @@ func sixlines(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func LED_ON(w http.ResponseWriter, r *http.Request) {
|
func LED_ON(w http.ResponseWriter, r *http.Request) {
|
||||||
led.High()
|
led.High()
|
||||||
backlight.High()
|
|
||||||
w.Header().Set(`Content-Type`, `text/plain; charset=UTF-8`)
|
w.Header().Set(`Content-Type`, `text/plain; charset=UTF-8`)
|
||||||
fmt.Fprintf(w, "led.High()")
|
fmt.Fprintf(w, "led.High()")
|
||||||
}
|
}
|
||||||
|
|
||||||
func LED_OFF(w http.ResponseWriter, r *http.Request) {
|
func LED_OFF(w http.ResponseWriter, r *http.Request) {
|
||||||
led.Low()
|
led.Low()
|
||||||
backlight.Low()
|
|
||||||
w.Header().Set(`Content-Type`, `text/plain; charset=UTF-8`)
|
w.Header().Set(`Content-Type`, `text/plain; charset=UTF-8`)
|
||||||
fmt.Fprintf(w, "led.Low()")
|
fmt.Fprintf(w, "led.Low()")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,71 +4,20 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"device/sam"
|
|
||||||
"machine"
|
"machine"
|
||||||
"runtime/interrupt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
"tinygo.org/x/drivers/examples/ili9341/initdisplay"
|
||||||
|
"tinygo.org/x/drivers/ili9341"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
uart UARTx
|
display *ili9341.Device
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
func init() {
|
||||||
// should reset IRQ
|
display = initdisplay.InitDisplay()
|
||||||
uart.Receive(byte((uart.Bus.DATA.Get() & 0xFF)))
|
display.SetRotation(ili9341.Rotation270)
|
||||||
uart.Bus.INTFLAG.SetBits(sam.SERCOM_USART_INT_INTFLAG_RXC)
|
|
||||||
}
|
// override
|
||||||
|
led = machine.LCD_BACKLIGHT
|
||||||
func setupRTL8720DN() (*rtl8720dn.RTL8720DN, error) {
|
|
||||||
machine.RTL8720D_CHIP_PU.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
||||||
machine.RTL8720D_CHIP_PU.Low()
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
machine.RTL8720D_CHIP_PU.High()
|
|
||||||
time.Sleep(1000 * time.Millisecond)
|
|
||||||
if debug {
|
|
||||||
waitSerial()
|
|
||||||
}
|
|
||||||
|
|
||||||
uart = UARTx{
|
|
||||||
UART: &machine.UART{
|
|
||||||
Buffer: machine.NewRingBuffer(),
|
|
||||||
Bus: sam.SERCOM0_USART_INT,
|
|
||||||
SERCOM: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
uart.Interrupt = interrupt.New(sam.IRQ_SERCOM0_2, handleInterrupt)
|
|
||||||
uart.Configure(machine.UARTConfig{TX: machine.PB24, RX: machine.PC24, BaudRate: 614400})
|
|
||||||
|
|
||||||
rtl := rtl8720dn.New(uart)
|
|
||||||
rtl.Debug(debug)
|
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rtl, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for user to open serial console
|
|
||||||
func waitSerial() {
|
|
||||||
for !machine.Serial.DTR() {
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
type UARTx struct {
|
|
||||||
*machine.UART
|
|
||||||
}
|
|
||||||
|
|
||||||
func (u UARTx) Read(p []byte) (n int, err error) {
|
|
||||||
if u.Buffered() == 0 {
|
|
||||||
time.Sleep(1 * time.Millisecond)
|
|
||||||
return 0, nil
|
|
||||||
}
|
|
||||||
return u.UART.Read(p)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,15 @@ import (
|
|||||||
"runtime/interrupt"
|
"runtime/interrupt"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers/net"
|
||||||
|
"tinygo.org/x/drivers/net/http"
|
||||||
"tinygo.org/x/drivers/rtl8720dn"
|
"tinygo.org/x/drivers/rtl8720dn"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
uart UARTx
|
uart UARTx
|
||||||
debug bool
|
debug bool
|
||||||
|
buf [0x1000]byte
|
||||||
)
|
)
|
||||||
|
|
||||||
func handleInterrupt(interrupt.Interrupt) {
|
func handleInterrupt(interrupt.Interrupt) {
|
||||||
@@ -47,7 +50,7 @@ func Setup() (*rtl8720dn.RTL8720DN, error) {
|
|||||||
rtl := rtl8720dn.New(uart)
|
rtl := rtl8720dn.New(uart)
|
||||||
rtl.Debug(debug)
|
rtl.Debug(debug)
|
||||||
|
|
||||||
_, err := rtl.Rpc_tcpip_adapter_init_with_timeout(10 * time.Second)
|
_, err := rtl.Rpc_tcpip_adapter_init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -55,6 +58,24 @@ func Setup() (*rtl8720dn.RTL8720DN, error) {
|
|||||||
return rtl, nil
|
return rtl, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func SetupAndConnectToAccessPoint(ssid, pass string, timeout time.Duration) (*rtl8720dn.RTL8720DN, error) {
|
||||||
|
rtl, err := Setup()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = rtl.ConnectToAccessPoint(ssid, pass, 10*time.Second)
|
||||||
|
if err != nil {
|
||||||
|
return rtl, err
|
||||||
|
}
|
||||||
|
|
||||||
|
net.UseDriver(rtl)
|
||||||
|
http.UseDriver(rtl)
|
||||||
|
http.SetBuf(buf[:])
|
||||||
|
|
||||||
|
return rtl, nil
|
||||||
|
}
|
||||||
|
|
||||||
// Wait for user to open serial console
|
// Wait for user to open serial console
|
||||||
func waitSerial() {
|
func waitSerial() {
|
||||||
for !machine.Serial.DTR() {
|
for !machine.Serial.DTR() {
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ go 1.15
|
|||||||
require (
|
require (
|
||||||
github.com/eclipse/paho.mqtt.golang v1.2.0
|
github.com/eclipse/paho.mqtt.golang v1.2.0
|
||||||
github.com/frankban/quicktest v1.10.2
|
github.com/frankban/quicktest v1.10.2
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e
|
golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect
|
||||||
tinygo.org/x/tinyfont v0.3.0
|
tinygo.org/x/tinyfont v0.2.1
|
||||||
tinygo.org/x/tinyfs v0.2.0
|
tinygo.org/x/tinyfs v0.1.0
|
||||||
tinygo.org/x/tinyterm v0.1.0
|
tinygo.org/x/tinyterm v0.1.0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ 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/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 h1:X2ev0eStA3AbceY54o37/0PQ/UWqKEiiO2dKL5OPaFM=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
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 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
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/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 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
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=
|
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 h1:XpT3nA5TvE525Ne3hInMh6+GETgn27Zfm9dxsThnX2Q=
|
||||||
golang.org/x/net v0.0.0-20210614182718-04defd469f4e/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
|
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-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -27,12 +24,9 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
|
|||||||
tinygo.org/x/drivers v0.14.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
tinygo.org/x/drivers v0.14.0/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
||||||
tinygo.org/x/drivers v0.15.1/go.mod h1:uT2svMq3EpBZpKkGO+NQHjxjGf1f42ra4OnMMwQL2aI=
|
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.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.2.1/go.mod h1:eLqnYSrFRjt5STxWaMeOWJTzrKhXqpWw7nU3bPfKOAM=
|
||||||
tinygo.org/x/tinyfont v0.3.0 h1:HIRLQoI3oc+2CMhPcfv+Ig88EcTImE/5npjqOnMD4lM=
|
tinygo.org/x/tinyfs v0.1.0 h1:yx1Tq9L60rpCm6HURo45x+Tnag+O9RGSbQfgeCb6XYU=
|
||||||
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.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=
|
|
||||||
tinygo.org/x/tinyterm v0.1.0 h1:80i+j+KWoxCFa/Xfp6pWbh79x+8zUdMXC1vaKj2QhkY=
|
tinygo.org/x/tinyterm v0.1.0 h1:80i+j+KWoxCFa/Xfp6pWbh79x+8zUdMXC1vaKj2QhkY=
|
||||||
tinygo.org/x/tinyterm v0.1.0/go.mod h1:/DDhNnGwNF2/tNgHywvyZuCGnbH3ov49Z/6e8LPLRR4=
|
tinygo.org/x/tinyterm v0.1.0/go.mod h1:/DDhNnGwNF2/tNgHywvyZuCGnbH3ov49Z/6e8LPLRR4=
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package makeybutton
|
package makeybutton
|
||||||
|
|
||||||
const bufferSize = 6
|
const bufferSize = 10
|
||||||
|
|
||||||
// Buffer is a buffer to keep track of the most recent readings for a button.
|
// Buffer is a buffer to keep track of the most recent readings for a button.
|
||||||
type Buffer struct {
|
type Buffer struct {
|
||||||
|
|||||||
+5
-17
@@ -6,10 +6,7 @@
|
|||||||
//
|
//
|
||||||
package makeybutton
|
package makeybutton
|
||||||
|
|
||||||
import (
|
import "machine"
|
||||||
"machine"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
// ButtonState represents the state of a MakeyButton.
|
// ButtonState represents the state of a MakeyButton.
|
||||||
type ButtonState int
|
type ButtonState int
|
||||||
@@ -39,6 +36,9 @@ type Button struct {
|
|||||||
|
|
||||||
// NewButton creates a new Button.
|
// NewButton creates a new Button.
|
||||||
func NewButton(pin machine.Pin) *Button {
|
func NewButton(pin machine.Pin) *Button {
|
||||||
|
pin.Configure(machine.PinConfig{Mode: machine.PinInput})
|
||||||
|
pin.Set(false)
|
||||||
|
|
||||||
return &Button{
|
return &Button{
|
||||||
pin: pin,
|
pin: pin,
|
||||||
state: NeverPressed,
|
state: NeverPressed,
|
||||||
@@ -47,18 +47,6 @@ 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,
|
// Get returns a ButtonEvent based on the most recent state of the button,
|
||||||
// and if it has changed by being pressed or released.
|
// and if it has changed by being pressed or released.
|
||||||
func (b *Button) Get() ButtonEvent {
|
func (b *Button) Get() ButtonEvent {
|
||||||
@@ -73,7 +61,7 @@ func (b *Button) Get() ButtonEvent {
|
|||||||
b.readings.Put(pressed)
|
b.readings.Put(pressed)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case pressed && avg > -1*bufferSize+2:
|
case pressed && avg > 0:
|
||||||
if b.state == Press {
|
if b.state == Press {
|
||||||
return NotChanged
|
return NotChanged
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-24
@@ -20,11 +20,6 @@ func SetBuf(b []byte) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Do(req *Request) (*Response, error) {
|
func (c *Client) Do(req *Request) (*Response, error) {
|
||||||
if c.Jar != nil {
|
|
||||||
for _, cookie := range c.Jar.Cookies(req.URL) {
|
|
||||||
req.AddCookie(cookie)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
switch req.URL.Scheme {
|
switch req.URL.Scheme {
|
||||||
case "http":
|
case "http":
|
||||||
return c.doHTTP(req)
|
return c.doHTTP(req)
|
||||||
@@ -36,17 +31,15 @@ func (c *Client) Do(req *Request) (*Response, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) doHTTP(req *Request) (*Response, error) {
|
func (c *Client) doHTTP(req *Request) (*Response, error) {
|
||||||
// make TCP connection
|
if c.Jar != nil {
|
||||||
ip := net.ParseIP(req.URL.Hostname())
|
for _, cookie := range c.Jar.Cookies(req.URL) {
|
||||||
port := 80
|
req.AddCookie(cookie)
|
||||||
if req.URL.Port() != "" {
|
|
||||||
p, err := strconv.ParseUint(req.URL.Port(), 0, 64)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
port = int(p)
|
|
||||||
}
|
}
|
||||||
raddr := &net.TCPAddr{IP: ip, Port: port}
|
|
||||||
|
// make TCP connection
|
||||||
|
ip := net.ParseIP(req.URL.Host)
|
||||||
|
raddr := &net.TCPAddr{IP: ip, Port: 80}
|
||||||
laddr := &net.TCPAddr{Port: 8080}
|
laddr := &net.TCPAddr{Port: 8080}
|
||||||
|
|
||||||
conn, err := net.DialTCP("tcp", laddr, raddr)
|
conn, err := net.DialTCP("tcp", laddr, raddr)
|
||||||
@@ -185,17 +178,12 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
println("Read error: " + err.Error())
|
println("Read error: " + err.Error())
|
||||||
} else {
|
} else {
|
||||||
// Take care of the case where "\r\n\r\n" is on the boundary of a buffer
|
idx := bytes.Index(buf[ofs:ofs+n], []byte("\r\n\r\n"))
|
||||||
start := ofs
|
|
||||||
if start > 3 {
|
|
||||||
start -= 3
|
|
||||||
}
|
|
||||||
idx := bytes.Index(buf[start:ofs+n], []byte("\r\n\r\n"))
|
|
||||||
if idx == -1 {
|
if idx == -1 {
|
||||||
ofs += n
|
ofs += n
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
idx += start + 4
|
idx += ofs + 4
|
||||||
|
|
||||||
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
|
scanner = bufio.NewScanner(bytes.NewReader(buf[0 : ofs+n]))
|
||||||
if resp.Status == "" && scanner.Scan() {
|
if resp.Status == "" && scanner.Scan() {
|
||||||
@@ -273,9 +261,6 @@ func (c *Client) doResp(conn net.Conn, req *Request) (*Response, error) {
|
|||||||
return nil, fmt.Errorf("slice out of range : use http.SetBuf() to change the allocation to %d bytes or more", end)
|
return nil, fmt.Errorf("slice out of range : use http.SetBuf() to change the allocation to %d bytes or more", end)
|
||||||
}
|
}
|
||||||
n, err := conn.Read(buf[ofs : ofs+0x400])
|
n, err := conn.Read(buf[ofs : ofs+0x400])
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
if n == 0 {
|
if n == 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,9 +118,6 @@ func (r *RTL8720DN) ConnectSSLSocket(addr, port string) error {
|
|||||||
if r.debug {
|
if r.debug {
|
||||||
fmt.Printf("ConnectSSLSocket(%q, %q)\r\n", addr, port)
|
fmt.Printf("ConnectSSLSocket(%q, %q)\r\n", addr, port)
|
||||||
}
|
}
|
||||||
if r.root_ca == nil {
|
|
||||||
return fmt.Errorf("root_ca is not set")
|
|
||||||
}
|
|
||||||
|
|
||||||
client, err := r.Rpc_wifi_ssl_client_create()
|
client, err := r.Rpc_wifi_ssl_client_create()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-32
@@ -1,10 +1,6 @@
|
|||||||
package rtl8720dn
|
package rtl8720dn
|
||||||
|
|
||||||
import (
|
import "io"
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
"time"
|
|
||||||
)
|
|
||||||
|
|
||||||
const maxUartRecvSize = 128
|
const maxUartRecvSize = 128
|
||||||
|
|
||||||
@@ -42,33 +38,6 @@ func New(r io.ReadWriter) *RTL8720DN {
|
|||||||
return ret
|
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) {
|
func (r *RTL8720DN) SetSeq(s uint64) {
|
||||||
r.seq = s
|
r.seq = s
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user