st-4-esp32/examples/pulse_guide/pulse_guide.ino
Ryan Malloy 35ec6dfdb5 Harden safety-critical paths from Hamilton review
- Fix lock hierarchy: stopAll() cancels pulse before touching axes
- Add configASSERT bounds checks on axis index in move/pulseGuide
- Enforce ST4Pulse singleton with configASSERT
- Check esp_timer_start_once return, rollback hardware on failure
- Validate SYNC coordinates (reject garbage → silent 0.0)
- Discard truncated serial commands on buffer overflow
- Guard WiFi update()/broadcastState() against null ws_ pointer
- Report connection errors to WebSocket clients on move/pulse
- Remove redundant Serial.begin() from pulse_guide example
2026-02-17 20:18:14 -07:00

47 lines
1.4 KiB
C++

// ST4-ESP32 Pulse Guide Example
// Demonstrates hardware-timer pulse guiding with position tracking
//
// Send via serial (57600 baud):
// CONNECT# - connect to mount
// PULSE RA+ 500# - pulse RA+ for 500ms
// PULSE DEC- 1000# - pulse DEC- for 1 second
// POS?# - read current position
// STATUS?# - full status report
#include <ST4.h>
ST4Controller controller;
ST4Serial st4Serial;
void setup() {
controller.begin(
ST4_PIN_RA_PLUS, ST4_PIN_RA_MINUS,
ST4_PIN_DEC_PLUS, ST4_PIN_DEC_MINUS,
ST4_PIN_LED
);
// st4Serial.begin() opens Serial at 57600 baud and prints INITIALIZED#
st4Serial.begin(controller, Serial);
controller.connect();
Serial.println("Ready. Try: PULSE RA+ 500#");
}
void loop() {
st4Serial.update();
// Print position every 5 seconds while moving
static uint32_t lastPrint = 0;
if (millis() - lastPrint > 5000) {
lastPrint = millis();
if (controller.axisActive(ST4AxisId::RA) ||
controller.axisActive(ST4AxisId::DECLINATION) ||
controller.isPulseActive()) {
Serial.print("RA: ");
Serial.print(controller.position(ST4AxisId::RA), 6);
Serial.print(" DEC: ");
Serial.println(controller.position(ST4AxisId::DECLINATION), 6);
}
}
}