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

44 lines
1.1 KiB
C++

// SPDX-License-Identifier: LGPL-3.0-or-later
// ST4-ESP32: Hardware timer pulse guiding (non-blocking)
// Uses esp_timer one-shot with deferred stop via FreeRTOS task
#pragma once
#include <esp_timer.h>
#include <freertos/FreeRTOS.h>
#include <freertos/semphr.h>
#include <freertos/task.h>
#include "ST4Axis.h"
#include "ST4Tracker.h"
class ST4Pulse {
// Static instance for timer callback (standard embedded ISR pattern)
static ST4Pulse* instance_;
esp_timer_handle_t timer_;
SemaphoreHandle_t pulseDoneSem_;
SemaphoreHandle_t mutex_;
TaskHandle_t pulseTaskHandle_;
ST4Axis* activeAxis_;
ST4Tracker* activeTracker_;
volatile bool active_;
volatile bool shutdown_;
static constexpr uint32_t MAX_PULSE_MS = 10000;
void cancelLocked();
static void timerCallback(void* arg);
static void pulseTaskFunc(void* arg);
public:
ST4Pulse();
~ST4Pulse();
void begin();
bool pulse(ST4Axis& axis, ST4Tracker& tracker,
ST4Direction dir, double slewRate, uint32_t ms);
bool isActive() const;
void cancel();
};