Instrument Neutral Distributed Interface INDI 2.2.5
wanderer_eta.h
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2025 cfuture81. All rights reserved.
3
4 Wanderer ETA M54 - Electronic Tilt Adjuster
5
6 This program is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 2 of the License, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 more details.
15
16 You should have received a copy of the GNU Library General Public License
17 along with this library; see the file COPYING.LIB. If not, write to
18 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 Boston, MA 02110-1301, USA.
20
21 The full GNU General Public License is included in this distribution in the
22 file called LICENSE.
23*******************************************************************************/
24
25#pragma once
26
27#include "defaultdevice.h"
28#include <mutex>
29
30namespace Connection
31{
32class Serial;
33}
34
36{
37 public:
39 virtual ~WandererETA() = default;
40
41 virtual bool initProperties() override;
42 virtual bool updateProperties() override;
43 virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
44 virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
45
46 protected:
47 const char *getDefaultName() override;
48 virtual void TimerHit() override;
49 virtual bool saveConfigItems(FILE *fp) override;
50
51 private:
52 // Serial communication
53 bool sendCommand(std::string command);
54 bool getData();
55 bool parseDeviceData(const char *data);
56
57 // State
58 int firmware = 0;
59
60 // Motor position targets (RW) - individual properties for independent control
61 INDI::PropertyNumber Position1NP{1};
62 INDI::PropertyNumber Position2NP{1};
63 INDI::PropertyNumber Position3NP{1};
64
65 enum
66 {
67 POINT_1,
68 POINT_2,
69 POINT_3,
70 };
71
72 // Motor position readback (RO) - what the encoders report
73 INDI::PropertyNumber PositionReadNP{3};
74
75 // Firmware information
76 INDI::PropertyText FirmwareTP{1};
77 enum
78 {
79 FIRMWARE_VERSION,
80 };
81
82 // Zero all points
83 INDI::PropertySwitch ZeroAllSP{1};
84 enum
85 {
86 ZERO_ALL,
87 };
88
89 // Backfocus offset - apply uniform offset to all points
90 INDI::PropertyNumber BackfocusOffsetNP{1};
91 INDI::PropertySwitch ApplyOffsetSP{1};
92 enum
93 {
94 APPLY_OFFSET,
95 };
96
97 int PortFD{ -1 };
98 Connection::Serial *serialConnection{ nullptr };
99
100 // Mutex for thread safety
101 std::timed_mutex serialPortMutex;
102 bool m_Initializing {true};
103 bool m_FirstRead {true};
104
105 // Non-blocking move state machine
106 struct MoveState
107 {
108 bool active {false};
109 double target[3] {0, 0, 0};
110 bool pending[3] {false, false, false};
111 int currentPoint {0};
112 double startPosition[3] {0, 0, 0}; // Position when move started
113 int graceCount {0};
114 int timeoutCount[3] {0, 0, 0}; // Polls remaining before timeout
115 bool isZeroAll {false};
116 bool isApplyOffset {false};
117 };
118 MoveState m_Move;
119 static constexpr double POSITION_TOLERANCE = 0.005; // mm
120 static constexpr double MOTOR_SPEED_MMS = 0.015; // mm/s (conservative estimate)
121 static constexpr int TIMEOUT_SAFETY_S = 25; // extra seconds added to calculated timeout
122
123 void startMove(int pointIndex, double target);
124 void startMultiPointMove(double targets[3], bool isZeroAll, bool isApplyOffset);
125 void checkMoveProgress();
126 void sendPointCommand(int pointIndex, double target);
127
128 void setPositionNP(int index, double values[], char *names[], int n, IPState state);
129 void setPositionState(int index, IPState state);
130 void updateAllTargets(double targets[3]);
131};
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
Class to provide extended functionality for devices in addition to the functionality provided by INDI...
virtual bool saveConfigItems(FILE *fp) override
Save config items.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Handle new number values (position targets)
virtual ~WandererETA()=default
WandererETA()
Constructor.
const char * getDefaultName() override
Device name.
virtual bool initProperties() override
Init properties.
virtual void TimerHit() override
Timer callback - poll device status.
virtual bool updateProperties() override
Update properties on connect/disconnect.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Handle new switch values (Zero All)
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
Combines all INDI Connection Plugins. Each INDI connection plugin is responsible of managing communic...
Definition arduino_st4.h:34