Public Access
36 lines
1.0 KiB
C++
36 lines
1.0 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
#include <Arduino.h>
|
||
|
|
#include <WiFi.h>
|
||
|
|
|
||
|
|
// WiFi to serial bridge for flashing the Nano from the PC (pio run -e nano_ota -t upload).
|
||
|
|
//
|
||
|
|
// When a TCP client connects, onStart() is called to restart the Nano into its bootloader.
|
||
|
|
// After that, bytes are copied between the TCP connection and the Nano's serial port
|
||
|
|
// until the client disconnects or is idle too long. onEnd() is then called.
|
||
|
|
// The uploader on the PC side is tools/nano_net_upload.py.
|
||
|
|
class NanoFlashBridge
|
||
|
|
{
|
||
|
|
public:
|
||
|
|
NanoFlashBridge(uint16_t port, HardwareSerial &serial, void (*onStart)(), void (*onEnd)());
|
||
|
|
|
||
|
|
void begin();
|
||
|
|
|
||
|
|
// Call from loop(). Returns true while a flash session is running; the caller must not
|
||
|
|
// send anything to the Nano then.
|
||
|
|
bool handle();
|
||
|
|
|
||
|
|
private:
|
||
|
|
// Give up when no data moves in either direction for this long
|
||
|
|
static const uint32_t IDLE_TIMEOUT = 10000;
|
||
|
|
|
||
|
|
WiFiServer _server;
|
||
|
|
WiFiClient _client;
|
||
|
|
HardwareSerial &_serial;
|
||
|
|
void (*_onStart)();
|
||
|
|
void (*_onEnd)();
|
||
|
|
bool _active = false;
|
||
|
|
uint32_t _last_activity = 0;
|
||
|
|
|
||
|
|
void _end();
|
||
|
|
};
|