Instrument Neutral Distributed Interface INDI 2.2.5
myfocuserpro2.h
Go to the documentation of this file.
1/*
2 ORIGINAL
3 MyFocuserPro2 Focuser
4 Copyright (C) 2019 Alan Townshend
5
6 Based on Moonlite Focuser
7 Copyright (C) 2013-2019 Jasem Mutlaq ([email protected])
8
9 This library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU Lesser General Public
11 License as published by the Free Software Foundation; either
12 version 2.1 of the License, or (at your option) any later version.
13
14 This library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public
20 License along with this library; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22
23*/
24
25#pragma once
26
27#include "indifocuser.h"
28
29#include <time.h> // for nsleep() R Brown June 2021
30#include <errno.h> // for nsleep() R Brown June 2021
31
32#include <chrono>
33
34#define STEPMODE_FULL 1
35#define STEPMODE_HALF 2
36#define STEPMODE_QUARTER 4
37#define STEPMODE_EIGHTH 8
38#define STEPMODE_SIXTEENTH 16
39#define STEPMODE_THIRTYSECOND 32
40#define STEPMODE_SIXTYFOUR 64
41#define STEPMODE_ONEHUNDREDTWENTYEIGHT 128
42#define STEPMODE_TWOHUNDREDFIFTYSIX 256
43
44#define CDRIVER_VERSION_MAJOR 1
45#define CDRIVER_VERSION_MINOR 0
46
47
49{
50 public:
52 virtual ~MyFocuserPro2() override = default;
53
54 // add step modes for TMC driver R Brown June 2021
58
60
62
63 //typedef enum {TEMP_COMPENSATE_ENABLE, TEMP_COMPENSATE_DISABLE } TemperatureCompensate;
65
66 const char * getDefaultName() override;
67 virtual bool initProperties() override;
68 virtual bool updateProperties() override;
69 virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
70 virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
71
72 static void timedMoveHelper(void * context);
73
74 protected:
79 virtual bool Handshake() override;
80
88 virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
89
95 virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
96
103 virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
104
110 virtual bool SyncFocuser(uint32_t ticks) override;
111 virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
112 virtual bool SetFocuserSpeed(int speed) override;
113 virtual bool ReverseFocuser(bool enabled) override;
114 virtual bool AbortFocuser() override;
115 virtual void TimerHit() override;
116 virtual bool saveConfigItems(FILE * fp) override;
117
118 private:
119 bool Ack();
127 bool sendCommand(const char * cmd, char * res = nullptr);
128
129 // Get initial focuser parameter when we first connect
130 void getStartupValues();
131
132 // Read and update Step Mode
133 bool readStepMode();
134
135 // Read Temperature Probe availability
136 bool readTempProbeAvailability();
137
138 // Read and update Temperature
139 bool readTemperature();
140
141 // Read and Update T.Compensate
142 bool readTempCompensateEnable();
143
144 //Read and Update the Temperature Coefficient
145 bool readTemperatureCoefficient();
146
147 // Read and update Position
148 bool readPosition();
149
150 // Read and update speed
151 bool readSpeed();
152
153 //Read and Update Maximum step position
154 bool readMaxPos();
155
156 // Are we moving?
157 bool isMoving();
158
159 bool readCoilPowerState();
160
161 bool readReverseDirection();
162
163 bool readDisplayVisible();
164
165 bool readBacklashInEnabled();
166 bool readBacklashOutEnabled();
167
168 bool readBacklashInSteps();
169 bool readBacklashOutSteps();
170
171 bool setBacklashInSteps(int16_t steps);
172 bool setBacklashOutSteps(int16_t steps);
173
174 bool setBacklashInEnabled(bool enabled);
175 bool setBacklashOutEnabled(bool enabled);
176
177 bool MoveFocuser(uint32_t position);
178
179 bool setStepMode(FocusStepMode mode);
180
181 bool setSpeed(uint16_t speed);
182
183 bool setDisplayVisible(DisplayMode enable);
184
185 bool setGotoHome();
186
187 bool setCoilPowerState(CoilPower enable);
188
189 bool setTemperatureCelsius();
190
191 bool setTemperatureCalibration(double calibration);
192
193 bool setTemperatureCoefficient(double coefficient);
194
195 bool setTemperatureCompensation(bool enable);
196
197 void timedMoveCallback();
198
199 double targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 };
200
201 int msleep(long milliseconds);
202
203 void clearbufferonerror();
204
205 // Read Only Temperature Reporting
206 INumber TemperatureN[1];
207 INumberVectorProperty TemperatureNP;
208
209 // Full/Half...256th Step modes
210 ISwitch StepModeS[9];
211 ISwitchVectorProperty StepModeSP;
212
213 // Backlash In settings
214 INumber BacklashInStepsN[1];
215 INumberVectorProperty BacklashInStepsNP;
216
217 // Backlash Out Setting
218 INumber BacklashOutStepsN[1];
219 INumberVectorProperty BacklashOutStepsNP;
220
221 // Temperature Settings
222 INumber TemperatureSettingN[1];
223 INumberVectorProperty TemperatureSettingNP;
224
225 // Temperature Compensation Enable/Disable
226 ISwitch TemperatureCompensateS[2];
227 ISwitchVectorProperty TemperatureCompensateSP;
228
229 //Display On Off
230 ISwitch DisplayS[2];
231 ISwitchVectorProperty DisplaySP;
232
233 //Goto Home Position
234 ISwitch GotoHomeS[1];
235 ISwitchVectorProperty GotoHomeSP;
236
237 //CoilPower On Off
238 ISwitch CoilPowerS[2];
239 ISwitchVectorProperty CoilPowerSP;
240
241 ISwitch BacklashInS[2];
242 ISwitchVectorProperty BacklashInSP;
243
244 //Backlash Out Enable
245 ISwitch BacklashOutS[2];
246 ISwitchVectorProperty BacklashOutSP;
247
248 //Focus Speed
249 ISwitch FocusSpeedS[3];
250 ISwitchVectorProperty FocusSpeedSP;
251
252 // MyFocuserPro2 Buffer
253 static const uint8_t ML_RES { 32 };
254
255 // MyFocuserPro2 Delimiter
256 static const char ML_DEL { '#' };
257
258 // mutex controls access to serial port
259 pthread_mutex_t cmdlock;
260
261 // MyFocuserPro2 Timeouts
262 static const uint8_t MYFOCUSERPRO2_SERIAL_TIMEOUT { 5 };
263 static const uint8_t MYFOCUSERPRO2_TCPIP_TIMEOUT { 10 };
264 static const long MYFOCUSERPRO2_SMALL_DELAY { 50 }; // 50ms delay from send command to read response
265 static const long MYFOCUSERPRO2_RECOVER_DELAY { 200 };
266
267 // update the temperature one every 5 seconds.
268 static constexpr const uint8_t GET_TEMPERATURE_FREQ{ 10 };
269 uint16_t Temperature_Counter { 0 };
270
271 // Update position every second
272 static constexpr const uint8_t GET_POSITION_FREQ{ 1 };
273 uint16_t Position_Counter { 0 };
274
275 static constexpr const char *SETTINGS_TAB {"Settings"};
276};
virtual bool saveConfigItems(FILE *fp) override
virtual ~MyFocuserPro2() override=default
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser Move focuser in a specific direction and speed for period of time.
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set the supplied position as the current focuser position.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
virtual bool Handshake() override
Handshake Try to communicate with Focuser and see if there is a valid response.
static void timedMoveHelper(void *context)
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
const char * getDefaultName() override
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365