st-4-esp32/include/ST4Controller.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

64 lines
1.7 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-later
// ST4-ESP32: High-level mount controller
// Owns axes, trackers, and pulse engine with configurable sidereal rates
// Controller-level mutex ensures composite operations are atomic across cores
#pragma once
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include "ST4Types.h"
#include "ST4Config.h"
#include "ST4Axis.h"
#include "ST4Tracker.h"
#include "ST4Pulse.h"
class ST4Controller {
ST4Axis axes_[2];
ST4Tracker trackers_[2];
ST4Pulse pulse_;
ST4RateConfig rateConfig_;
bool connected_;
int ledPin_;
mutable SemaphoreHandle_t mutex_;
double calculateSlewRate(ST4AxisId axis, ST4Direction dir) const;
public:
ST4Controller();
~ST4Controller();
void begin(int raPlusPin = ST4_PIN_RA_PLUS,
int raMinusPin = ST4_PIN_RA_MINUS,
int decPlusPin = ST4_PIN_DEC_PLUS,
int decMinusPin = ST4_PIN_DEC_MINUS,
int ledPin = ST4_PIN_LED,
ST4PinLogic logic = ST4PinLogic::ACTIVE_HIGH);
void setRates(const ST4RateConfig& config);
void connect();
void disconnect();
bool isConnected() const;
void move(ST4AxisId axis, ST4Direction dir);
void stopAxis(ST4AxisId axis);
void stopAll();
bool pulseGuide(ST4AxisId axis, ST4Direction dir, uint32_t ms);
bool isPulseActive() const;
double position(ST4AxisId axis) const;
void setPosition(ST4AxisId axis, double pos);
void sync(double ra, double dec);
ST4Direction axisDirection(ST4AxisId axis) const;
bool axisActive(ST4AxisId axis) const;
ST4State state() const;
ST4Axis& axis(ST4AxisId id);
ST4Tracker& tracker(ST4AxisId id);
};