Instrument Neutral Distributed Interface INDI  1.9.2
myfocuserpro2.h
Go to the documentation of this file.
1 /*
2  MyFocuserPro2 Focuser
3  Copyright (C) 2019 Alan Townshend
4 
5  Based on Moonlite Focuser
6  Copyright (C) 2013-2019 Jasem Mutlaq (mutlaqja@ikarustech.com)
7 
8  This library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Lesser General Public
10  License as published by the Free Software Foundation; either
11  version 2.1 of the License, or (at your option) any later version.
12 
13  This library is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public
19  License along with this library; if not, write to the Free Software
20  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 
22 */
23 
24 #pragma once
25 
26 #include "indifocuser.h"
27 
28 #include <chrono>
29 
31 {
32  public:
33  MyFocuserPro2();
34  virtual ~MyFocuserPro2() override = default;
35 
37 
39 
41 
43 
44  const char * getDefaultName() override;
45  virtual bool initProperties() override;
46  virtual bool updateProperties() override;
47  virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
48  virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
49 
50  static void timedMoveHelper(void * context);
51 
52  protected:
57  virtual bool Handshake() override;
58 
66  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
67 
73  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
74 
81  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
82 
88  virtual bool SyncFocuser(uint32_t ticks) override;
89  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
90  virtual bool SetFocuserSpeed(int speed) override;
91  virtual bool ReverseFocuser(bool enabled) override;
92  virtual bool AbortFocuser() override;
93  virtual void TimerHit() override;
94  virtual bool saveConfigItems(FILE * fp) override;
95 
96  private:
97  bool Ack();
105  bool sendCommand(const char * cmd, char * res = nullptr);
106 
107  // Get initial focuser parameter when we first connect
108  void getStartupValues();
109 
110  // Read and update Step Mode
111  bool readStepMode();
112 
113  // Read and update Temperature
114  bool readTemperature();
115 
116  // Read and Update T.Compensate
117  bool readTempCompensateEnable();
118 
119  //Read and Update teh Temperature Coefficient
120  bool readTempeartureCoefficient();
121 
122  // Read and update Position
123  bool readPosition();
124 
125  // Read and update speed
126  bool readSpeed();
127 
128  //Read and Update Maximum step position
129  bool readMaxPos();
130 
131  // Are we moving?
132  bool isMoving();
133 
134  bool readCoilPowerState();
135 
136  bool readDisplayVisible();
137 
138  bool readReverseDirection();
139 
140  bool readBacklashInEnabled();
141  bool readBacklashOutEnabled();
142 
143  bool readBacklashInSteps();
144  bool readBacklashOutSteps();
145 
146  bool setBacklashInSteps(int16_t steps);
147  bool setBacklashOutSteps(int16_t steps);
148 
149  bool setBacklashInEnabled(bool enabled);
150  bool setBacklashOutEnabled(bool enabled);
151 
152  bool MoveFocuser(uint32_t position);
153 
154  bool setStepMode(FocusStepMode mode);
155 
156  bool setSpeed(uint16_t speed);
157 
158  bool setDisplayVisible(DisplayMode enable);
159 
160  bool setGotoHome();
161 
162  bool setCoilPowerState(CoilPower enable);
163 
164  bool setTemperatureCelsius();
165 
166  bool setTemperatureCalibration(double calibration);
167 
168  bool setTemperatureCoefficient(double coefficient);
169 
170  bool setTemperatureCompensation(bool enable);
171 
172  void timedMoveCallback();
173 
174  double targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 };
175 
176  // Read Only Temperature Reporting
177  INumber TemperatureN[1];
178  INumberVectorProperty TemperatureNP;
179 
180  // Full/Half...32th Step modes
181  ISwitch StepModeS[6];
182  ISwitchVectorProperty StepModeSP;
183 
184  // Backlash In settings
185  INumber BacklashInStepsN[1];
186  INumberVectorProperty BacklashInStepsNP;
187 
188  // Backlash Out Setting
189  INumber BacklashOutStepsN[1];
190  INumberVectorProperty BacklashOutStepsNP;
191 
192  // Temperature Settings
193  INumber TemperatureSettingN[1];
194  INumberVectorProperty TemperatureSettingNP;
195 
196  // Temperature Compensation Enable/Disable
197  ISwitch TemperatureCompensateS[2];
198  ISwitchVectorProperty TemperatureCompensateSP;
199 
200  //Display On Off
201  ISwitch DisplayS[2];
202  ISwitchVectorProperty DisplaySP;
203 
204  //Goto Home Position
205  ISwitch GotoHomeS[1];
206  ISwitchVectorProperty GotoHomeSP;
207 
208  //CoilPower On Off
209  ISwitch CoilPowerS[2];
210  ISwitchVectorProperty CoilPowerSP;
211 
212  //Backlash In Enable
213  ISwitch BacklashInS[2];
214  ISwitchVectorProperty BacklashInSP;
215 
216  //Backlash Out Enable
217  ISwitch BacklashOutS[2];
218  ISwitchVectorProperty BacklashOutSP;
219 
220  //Focus Speed
221  ISwitch FocusSpeedS[3];
222  ISwitchVectorProperty FocusSpeedSP;
223 
224  // MyFocuserPro2 Buffer
225  static const uint8_t ML_RES { 32 };
226 
227  // MyFocuserPro2 Delimeter
228  static const char ML_DEL { '#' };
229 
230  // MyFocuserPro2 Timeout
231  static const uint8_t ML_TIMEOUT { 5 };
232 
233  // MyFocuserPro2 minimum supported firmware
234  static const int32_t MINIMUM_FIRMWARE_VERSION { 291 };
235 };
MyFocuserPro2::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
Definition: myfocuserpro2.cpp:1144
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
MyFocuserPro2::DISPLAY_ON
@ DISPLAY_ON
Definition: myfocuserpro2.h:40
IPState
IPState
Property state.
Definition: indiapi.h:158
MyFocuserPro2::TemperatureCompensate
TemperatureCompensate
Definition: myfocuserpro2.h:42
ISwitch
One switch descriptor.
MyFocuserPro2::timedMoveHelper
static void timedMoveHelper(void *context)
Definition: myfocuserpro2.cpp:1127
MyFocuserPro2
Definition: myfocuserpro2.h:30
MyFocuserPro2::getDefaultName
const char * getDefaultName() override
Definition: myfocuserpro2.cpp:211
INumber
One number descriptor.
MyFocuserPro2::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: myfocuserpro2.cpp:1012
MyFocuserPro2::TEMP_COMPENSATE_ENABLE
@ TEMP_COMPENSATE_ENABLE
Definition: myfocuserpro2.h:42
MyFocuserPro2::Handshake
virtual bool Handshake() override
Handshake Try to communicate with Focuser and see if there is a valid response.
Definition: myfocuserpro2.cpp:195
MyFocuserPro2::FOCUS_SIXTEENTH_STEP
@ FOCUS_SIXTEENTH_STEP
Definition: myfocuserpro2.h:36
MyFocuserPro2::MyFocuserPro2
MyFocuserPro2()
Definition: myfocuserpro2.cpp:37
MyFocuserPro2::FOCUS_HALF_STEP
@ FOCUS_HALF_STEP
Definition: myfocuserpro2.h:36
indifocuser.h
MyFocuserPro2::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: myfocuserpro2.cpp:1223
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
MyFocuserPro2::COIL_POWER_OFF
@ COIL_POWER_OFF
Definition: myfocuserpro2.h:38
MyFocuserPro2::SetFocuserSpeed
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: myfocuserpro2.cpp:1087
MyFocuserPro2::~MyFocuserPro2
virtual ~MyFocuserPro2() override=default
MyFocuserPro2::TEMP_COMPENSATE_DISABLE
@ TEMP_COMPENSATE_DISABLE
Definition: myfocuserpro2.h:42
MyFocuserPro2::MoveFocuser
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser Move focuser in a specific direction and speed for period of time.
Definition: myfocuserpro2.cpp:1108
MyFocuserPro2::COIL_POWER_ON
@ COIL_POWER_ON
Definition: myfocuserpro2.h:38
MyFocuserPro2::FOCUS_THIRTYSECOND_STEP
@ FOCUS_THIRTYSECOND_STEP
Definition: myfocuserpro2.h:36
MyFocuserPro2::FOCUS_QUARTER_STEP
@ FOCUS_QUARTER_STEP
Definition: myfocuserpro2.h:36
MyFocuserPro2::FOCUS_FULL_STEP
@ FOCUS_FULL_STEP
Definition: myfocuserpro2.h:36
MyFocuserPro2::FocusStepMode
FocusStepMode
Definition: myfocuserpro2.h:36
MyFocuserPro2::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: myfocuserpro2.cpp:1218
MyFocuserPro2::DisplayMode
DisplayMode
Definition: myfocuserpro2.h:40
MyFocuserPro2::FOCUS_EIGHTH_STEP
@ FOCUS_EIGHTH_STEP
Definition: myfocuserpro2.h:36
MyFocuserPro2::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: myfocuserpro2.cpp:155
MyFocuserPro2::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: myfocuserpro2.cpp:766
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
MyFocuserPro2::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: myfocuserpro2.cpp:814
MyFocuserPro2::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set the supplied position as the current focuser position.
Definition: myfocuserpro2.cpp:712
MyFocuserPro2::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
Definition: myfocuserpro2.cpp:1154
ISState
ISState
Switch state.
Definition: indiapi.h:148
MyFocuserPro2::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: myfocuserpro2.cpp:49
MyFocuserPro2::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: myfocuserpro2.cpp:1174
INDI::Focuser
Definition: indifocuser.h:43
MyFocuserPro2::CoilPower
CoilPower
Definition: myfocuserpro2.h:38
MyFocuserPro2::DISPLAY_OFF
@ DISPLAY_OFF
Definition: myfocuserpro2.h:40
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
MyFocuserPro2::SetFocuserMaxPosition
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
Definition: myfocuserpro2.cpp:1093