mirror of
https://github.com/jscrane/r65emu.git
synced 2024-06-10 06:29:30 +00:00
66 lines
1.1 KiB
C++
66 lines
1.1 KiB
C++
|
#include <Arduino.h>
|
||
|
#include <stdint.h>
|
||
|
#include "hardware.h"
|
||
|
#include "serialio.h"
|
||
|
#include "filer.h"
|
||
|
#include "socket_filer.h"
|
||
|
|
||
|
#if !defined(ESP32)
|
||
|
#pragma message "no socket filer"
|
||
|
#else
|
||
|
#include <WiFi.h>
|
||
|
|
||
|
static WiFiServer server(23);
|
||
|
static WiFiClient client;
|
||
|
|
||
|
static bool connected() {
|
||
|
if (client.connected())
|
||
|
return true;
|
||
|
client = server.available();
|
||
|
return client.connected();
|
||
|
}
|
||
|
|
||
|
// FIXME: hostname
|
||
|
bool socket_filer::start(const char *) {
|
||
|
|
||
|
#if defined(WIFI_SSID)
|
||
|
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
|
||
|
|
||
|
for (int i=0; i < 60 && WiFi.status() != WL_CONNECTED; i++)
|
||
|
delay(1000);
|
||
|
|
||
|
server.begin();
|
||
|
return WiFi.status() == WL_CONNECTED;
|
||
|
#else
|
||
|
return false;
|
||
|
#endif
|
||
|
}
|
||
|
|
||
|
void socket_filer::write(uint8_t b) {
|
||
|
if (connected())
|
||
|
client.write(b);
|
||
|
}
|
||
|
|
||
|
uint8_t socket_filer::read() {
|
||
|
if (connected())
|
||
|
return client.read();
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
bool socket_filer::more() {
|
||
|
return connected() && client.available() > 0;
|
||
|
}
|
||
|
|
||
|
#if !defined(NO_CHECKPOINT)
|
||
|
const char *socket_filer::checkpoint() {
|
||
|
// FIXME
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
void socket_filer::restore(const char *) {
|
||
|
// FIXME
|
||
|
}
|
||
|
#endif
|
||
|
|
||
|
#endif
|