st-4-esp32/include/ST4WiFi.h
Ryan Malloy 4c91fd4811 ESP32 ST-4 autoguider library with thread-safe pulse guiding
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.
2026-02-17 19:46:03 -07:00

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