st-4-esp32/include/ST4Types.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.5 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-later
// ST4-ESP32: ESP32 ST-4 autoguider port controller
// Based on arduino-st4 by Kevin Ferrare
#pragma once
#include <cstdint>
enum class ST4Direction : uint8_t {
PLUS,
MINUS,
STOP
};
enum class ST4AxisId : uint8_t {
RA = 0,
DECLINATION = 1
};
enum class ST4PinLogic : uint8_t {
ACTIVE_HIGH,
ACTIVE_LOW
};
// Sidereal rate constants (from ASCOM ArduinoST4 Constants.cs)
namespace ST4Constants {
constexpr double DEGREES_PER_SECOND = 360.0 / (24.0 * 3600.0);
constexpr double RA_PER_SECOND = 1.0 / 3600.0;
// Default sidereal rate multipliers (from ASCOM Driver.cs)
// RA+: 8x slew + 1x earth rotation = 9x
// RA-: 8x slew - 1x earth rotation = 7x
// DEC: symmetric 8x
constexpr double DEFAULT_RA_RATE_PLUS = 9.0;
constexpr double DEFAULT_RA_RATE_MINUS = 7.0;
constexpr double DEFAULT_DEC_RATE_PLUS = 8.0;
constexpr double DEFAULT_DEC_RATE_MINUS = 8.0;
constexpr uint32_t DEFAULT_BAUD_RATE = 57600;
constexpr uint16_t DEFAULT_WS_PORT = 81;
constexpr uint16_t DEFAULT_HTTP_PORT = 80;
constexpr char VERSION[] = "2026.02.17";
}
struct ST4AxisState {
bool active;
ST4Direction direction;
double position;
};
struct ST4State {
bool connected;
ST4AxisState ra;
ST4AxisState dec;
};
struct ST4RateConfig {
double raPlusMultiplier;
double raMinusMultiplier;
double decPlusMultiplier;
double decMinusMultiplier;
};