Instrument Neutral Distributed Interface INDI  1.9.5
focuslynxbase.h
Go to the documentation of this file.
1 /*
2  Focus Lynx INDI driver
3  Copyright (C) 2015 Jasem Mutlaq (mutlaqja@ikarustech.com)
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
9 
10  This library is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
21 #pragma once
22 
23 #include "indifocuser.h"
24 
25 #include <indifocuser.h>
26 #include <indicom.h>
29 
30 #include <map>
31 #include <termios.h>
32 #include <unistd.h>
33 #include <memory>
34 #include <cmath>
35 #include <cstring>
36 
37 #define LYNXFOCUS_MAX_RETRIES 1
38 #define LYNXFOCUS_TIMEOUT 3
39 #define LYNXFOCUS_MAXBUF 16
40 #define LYNXFOCUS_TEMPERATURE_FREQ 20 /* Update every 20 POLLMS cycles. For POLLMS 500ms = 10 seconds freq */
41 #define LYNXFOCUS_POSITION_THRESHOLD 5 /* Only send position updates to client if the diff exceeds 5 steps */
42 
43 #define FOCUS_SETTINGS_TAB "Settings"
44 #define FOCUS_STATUS_TAB "Status"
45 #define HUB_SETTINGS_TAB "Device"
46 
47 #define VERSION 1
48 #define SUBVERSION 46
49 
51 {
52  public:
53  FocusLynxBase();
54  FocusLynxBase(const char *target);
55 
56  enum
57  {
64  };
65  typedef enum
66  {
76  } LYNX_STATUS;
77  enum
78  {
81  };
82 
83  virtual bool Handshake() override;
84  virtual const char *getDefaultName() override;
85  virtual bool initProperties() override;
86  virtual void ISGetProperties(const char *dev) override;
87  virtual bool updateProperties() override;
88  virtual bool saveConfigItems(FILE *fp) override;
89  virtual bool loadConfig(bool silent, const char *property) override;
90 
91  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
92  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
93  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
94 
95  virtual IPState MoveAbsFocuser(uint32_t targetPosition) override;
96  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
97  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
98  virtual bool AbortFocuser() override;
99  virtual void TimerHit() override;
100  virtual int getVersion(int *major, int *minor, int *sub);
101 
102  void setFocusTarget(const char *target);
103  const char *getFocusTarget();
104  virtual void debugTriggered(bool enable) override;
105 
106  // Device
107  bool setDeviceType(int index);
108  uint32_t DBG_FOCUS;
109 
110  // Misc functions
111  bool ack();
112  bool isResponseOK();
113 
114  protected:
115  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
116  virtual bool ReverseFocuser(bool enabled) override;
117  virtual bool SyncFocuser(uint32_t ticks) override;
118 
119  virtual bool SetFocuserBacklash(int32_t steps) override;
120  virtual bool SetFocuserBacklashEnabled(bool enabled) override;
121 
122  // Move from private to public to validate
124 
125  // List all supported models
128 
129  // Led Intensity Value
132 
133  // Store version of the firmware from the HUB
134  char version[16];
135 
136  private:
137  uint32_t simPosition;
138  uint32_t targetPosition;
139 
140  ISState simStatus[8];
141  bool simCompensationOn;
142  char focusTarget[8];
143 
144  std::map<std::string, std::string> lynxModels;
145 
146  struct timeval focusMoveStart;
147  float focusMoveRequest;
148 
149  // Get functions
150  bool getFocusConfig();
151  bool getFocusStatus();
152  bool getFocusTemp();
153 
154  // Set functions
155 
156  // Position
157  bool setStepSize(u_int16_t stepsize);
158 
159  // Temperature
160  bool setTemperatureCompensation(bool enable);
161  bool setTemperatureCompensationMode(char mode);
162  bool setTemperatureCompensationCoeff(char mode, int16_t coeff);
163  bool setTemperatureInceptions(char mode, int32_t inter);
164  bool setTemperatureCompensationOnStart(bool enable);
165 
166  // Motion functions
167  bool stop();
168  bool home();
169  bool center();
170 
171  // Led level
172  bool setLedLevel(int level);
173 
174  // Device Nickname
175  bool setDeviceNickname(const char *nickname);
176 
177  // Misc functions
178  bool resetFactory();
179  float calcTimeLeft(timeval, float);
180 
181  // Properties
182 
183  // Set/Get Temperature
184  INumber TemperatureN[1];
185  INumberVectorProperty TemperatureNP;
186 
187  // Enable/Disable temperature compensation
188  ISwitch TemperatureCompensateS[2];
189  ISwitchVectorProperty TemperatureCompensateSP;
190 
191  // Enable/Disable temperature compensation on start
192  ISwitch TemperatureCompensateOnStartS[2];
193  ISwitchVectorProperty TemperatureCompensateOnStartSP;
194 
195  // Temperature Coefficient Mode
196  ISwitch TemperatureCompensateModeS[5];
197  ISwitchVectorProperty TemperatureCompensateModeSP;
198 
199  // Temperature coefficient and Intercept for selected mode
200  INumber TemperatureParamN[2];
201  INumberVectorProperty TemperatureParamNP;
202 
203  // Reset to Factory setting
204  ISwitch ResetS[1];
205  ISwitchVectorProperty ResetSP;
206 
207  // Go to home/center
208  ISwitch GotoS[2];
209  ISwitchVectorProperty GotoSP;
210 
211  // Status indicators
212  ILight StatusL[8];
213  ILightVectorProperty StatusLP;
214 
215  // Max Travel for relative focusers
216  // INumber MaxTravelN[1];
217  // INumberVectorProperty MaxTravelNP;
218 
219  // Focuser Step Size
220  INumber StepSizeN[1];
221  INumberVectorProperty StepSizeNP;
222 
223  // Focus name configure in the HUB
224  IText HFocusNameT[1] {};
225  ITextVectorProperty HFocusNameTP;
226 
227  bool canHome;
228  bool isHoming;
229  // TODO add property for this.
230  bool m_HomeOnStart {false};
231 
232  static const uint8_t LYNX_MAX { 64 };
233 };
FocusLynxBase::DBG_FOCUS
uint32_t DBG_FOCUS
Definition: focuslynxbase.h:108
FocusLynxBase::STATUS_HNDCTRL
@ STATUS_HNDCTRL
Definition: focuslynxbase.h:73
FocusLynxBase::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: focuslynxbase.cpp:334
FocusLynxBase::FOCUS_D_COEFF
@ FOCUS_D_COEFF
Definition: focuslynxbase.h:61
FocusLynxBase::getFocusTarget
const char * getFocusTarget()
Definition: focuslynxbase.cpp:3485
IPState
IPState
Property state.
Definition: indiapi.h:158
FocusLynxBase::ISGetProperties
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: focuslynxbase.cpp:222
FocusLynxBase::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: focuslynxbase.cpp:309
FocusLynxBase::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetPosition) override
MoveFocuser the focuser to an absolute position.
Definition: focuslynxbase.cpp:3136
_ILightVectorProperty
Light vector property descriptor.
Definition: indiapi.h:415
ISwitch
One switch descriptor.
FocusLynxBase::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: focuslynxbase.cpp:3214
FocusLynxBase::FOCUS_F_COEFF
@ FOCUS_F_COEFF
Definition: focuslynxbase.h:63
indicom.h
Implementations for common driver routines.
connectiontcp.h
FocusLynxBase::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: focuslynxbase.cpp:116
INumber
One number descriptor.
FocusLynxBase::LedN
INumber LedN[1]
Definition: focuslynxbase.h:130
FocusLynxBase::version
char version[16]
Definition: focuslynxbase.h:134
FocusLynxBase::LedNP
INumberVectorProperty LedNP
Definition: focuslynxbase.h:131
FocusLynxBase::SetFocuserMaxPosition
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
Definition: focuslynxbase.cpp:2825
FocusLynxBase::loadConfig
virtual bool loadConfig(bool silent, const char *property) override
Load the last saved configuration file.
Definition: focuslynxbase.cpp:3434
FocusLynxBase::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: focuslynxbase.cpp:3414
FocusLynxBase::FOCUS_B_COEFF
@ FOCUS_B_COEFF
Definition: focuslynxbase.h:59
indifocuser.h
FocusLynxBase::getVersion
virtual int getVersion(int *major, int *minor, int *sub)
Definition: focuslynxbase.cpp:3494
FocusLynxBase::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: focuslynxbase.cpp:2703
FocusLynxBase::FOCUS_A_COEFF
@ FOCUS_A_COEFF
Definition: focuslynxbase.h:58
FocusLynxBase::STATUS_REMOTEIO
@ STATUS_REMOTEIO
Definition: focuslynxbase.h:72
FocusLynxBase::STATUS_REVERSE
@ STATUS_REVERSE
Definition: focuslynxbase.h:74
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
FocusLynxBase::FOCUS_E_COEFF
@ FOCUS_E_COEFF
Definition: focuslynxbase.h:62
FocusLynxBase::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: focuslynxbase.cpp:2762
FocusLynxBase::MoveFocuser
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser the focuser in a particular direction with a specific speed for a finite duration.
Definition: focuslynxbase.cpp:3068
ILight
One light descriptor.
FocusLynxBase::SetFocuserBacklashEnabled
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
Definition: focuslynxbase.cpp:2586
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
FocusLynxBase::setFocusTarget
void setFocusTarget(const char *target)
Definition: focuslynxbase.cpp:3476
IText
One text descriptor.
connectionserial.h
FocusLynxBase::STATUS_HOMED
@ STATUS_HOMED
Definition: focuslynxbase.h:69
FocusLynxBase::STATUS_MOVING
@ STATUS_MOVING
Definition: focuslynxbase.h:67
FocusLynxBase::debugTriggered
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
Definition: focuslynxbase.cpp:3467
FocusLynxBase::ModelS
ISwitch * ModelS
Definition: focuslynxbase.h:126
FocusLynxBase::SetFocuserBacklash
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: focuslynxbase.cpp:2645
FocusLynxBase::LYNX_STATUS
LYNX_STATUS
Definition: focuslynxbase.h:65
FocusLynxBase::STATUS_HOMING
@ STATUS_HOMING
Definition: focuslynxbase.h:68
FocusLynxBase::setDeviceType
bool setDeviceType(int index)
Definition: focuslynxbase.cpp:1968
FocusLynxBase::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: focuslynxbase.cpp:519
FocusLynxBase::getDefaultName
virtual const char * getDefaultName() override
Definition: focuslynxbase.cpp:325
FocusLynxBase::ISNewText
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: focuslynxbase.cpp:497
FocusLynxBase::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: focuslynxbase.cpp:237
name
const char * name
Definition: indiserver.c:116
FocusLynxBase
Definition: focuslynxbase.h:50
FocusLynxBase::GOTO_HOME
@ GOTO_HOME
Definition: focuslynxbase.h:80
FocusLynxBase::GOTO_CENTER
@ GOTO_CENTER
Definition: focuslynxbase.h:79
FocusLynxBase::FOCUS_C_COEFF
@ FOCUS_C_COEFF
Definition: focuslynxbase.h:60
FocusLynxBase::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: focuslynxbase.cpp:3199
FocusLynxBase::FocusLynxBase
FocusLynxBase()
Definition: focuslynxbase.cpp:33
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
FocusLynxBase::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: focuslynxbase.cpp:3321
ISState
ISState
Switch state.
Definition: indiapi.h:148
FocusLynxBase::isResponseOK
bool isResponseOK()
Definition: focuslynxbase.cpp:3013
FocusLynxBase::configurationComplete
bool configurationComplete
Definition: focuslynxbase.h:123
FocusLynxBase::STATUS_UNKNOWN
@ STATUS_UNKNOWN
Definition: focuslynxbase.h:75
FocusLynxBase::ack
bool ack()
Definition: focuslynxbase.cpp:641
INDI::Focuser
Definition: indifocuser.h:43
FocusLynxBase::STATUS_TMPPROBE
@ STATUS_TMPPROBE
Definition: focuslynxbase.h:71
FocusLynxBase::STATUS_FFDETECT
@ STATUS_FFDETECT
Definition: focuslynxbase.h:70
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
FocusLynxBase::ModelSP
ISwitchVectorProperty ModelSP
Definition: focuslynxbase.h:127