Port of arduino-st4 (Kevin Ferrare) to ESP32/PlatformIO with: - FreeRTOS mutex protection at every layer (Pin, Axis, Pulse, Controller) - Hardware timer pulse guiding with ISR-safe deferred stop pattern - Backward-compatible serial protocol (57600 baud, #-terminated) - Extended commands: PULSE, POS?, SYNC, STATUS?, VERSION? - Optional WiFi/WebSocket control (gated by ST4_WIFI_ENABLED) - Dead-reckoning position tracker using esp_timer microsecond precision All 4 examples build clean against esp32dev target.
50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
// SPDX-License-Identifier: LGPL-3.0-or-later
|
|
// ST4-ESP32: WiFi + WebSocket server (optional)
|
|
// Enable by defining ST4_WIFI_ENABLED before including ST4.h
|
|
|
|
#pragma once
|
|
|
|
#ifdef ST4_WIFI_ENABLED
|
|
|
|
#include <WiFi.h>
|
|
#include <ESPAsyncWebServer.h>
|
|
#include <ArduinoJson.h>
|
|
#include "ST4Controller.h"
|
|
|
|
struct ST4WiFiConfig {
|
|
const char* ssid;
|
|
const char* password;
|
|
bool apMode;
|
|
uint16_t httpPort;
|
|
uint32_t broadcastIntervalMs;
|
|
};
|
|
|
|
class ST4WiFi {
|
|
ST4Controller* controller_;
|
|
AsyncWebServer* server_;
|
|
AsyncWebSocket* ws_;
|
|
ST4WiFiConfig config_;
|
|
|
|
uint32_t lastBroadcast_;
|
|
ST4Direction lastRaDir_;
|
|
ST4Direction lastDecDir_;
|
|
|
|
void handleWebSocketEvent(AsyncWebSocket* server,
|
|
AsyncWebSocketClient* client,
|
|
AwsEventType type, void* arg,
|
|
uint8_t* data, size_t len);
|
|
void processCommand(AsyncWebSocketClient* client,
|
|
uint8_t* data, size_t len);
|
|
void broadcastState();
|
|
String stateJson() const;
|
|
|
|
public:
|
|
ST4WiFi();
|
|
~ST4WiFi();
|
|
|
|
void begin(ST4Controller& controller, const ST4WiFiConfig& config);
|
|
void update();
|
|
};
|
|
|
|
#endif // ST4_WIFI_ENABLED
|