Instrument Neutral Distributed Interface INDI  2.0.2
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 <stdint.h>
32 #include <termios.h>
33 #include <unistd.h>
34 #include <memory>
35 #include <cmath>
36 #include <cstring>
37 
38 #define LYNXFOCUS_MAX_RETRIES 1
39 #define LYNXFOCUS_TIMEOUT 3
40 #define LYNXFOCUS_MAXBUF 16
41 #define LYNXFOCUS_TEMPERATURE_FREQ 20 /* Update every 20 POLLMS cycles. For POLLMS 500ms = 10 seconds freq */
42 #define LYNXFOCUS_POSITION_THRESHOLD 5 /* Only send position updates to client if the diff exceeds 5 steps */
43 
44 #define FOCUS_SETTINGS_TAB "Settings"
45 #define FOCUS_STATUS_TAB "Status"
46 #define HUB_SETTINGS_TAB "Device"
47 
48 #define VERSION 1
49 #define SUBVERSION 46
50 
52 {
53  public:
54  FocusLynxBase();
55  FocusLynxBase(const char *target);
56 
57  enum
58  {
65  };
66  typedef enum
67  {
78  enum
79  {
81  GOTO_HOME
82  };
83 
84  virtual bool Handshake() override;
85  virtual const char *getDefaultName() override;
86  virtual bool initProperties() override;
87  virtual void ISGetProperties(const char *dev) override;
88  virtual bool updateProperties() override;
89  virtual bool saveConfigItems(FILE *fp) override;
90  virtual bool loadConfig(bool silent, const char *property) override;
91 
92  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
93  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
94  virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override;
95 
96  virtual IPState MoveAbsFocuser(uint32_t targetPosition) override;
97  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
98  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
99  virtual bool AbortFocuser() override;
100  virtual void TimerHit() override;
101  virtual int getVersion(int *major, int *minor, int *sub);
102 
103  void setFocusTarget(const char *target);
104  const char *getFocusTarget();
105  virtual void debugTriggered(bool enable) override;
106 
107  // Device
108  bool setDeviceType(int index);
109  uint32_t DBG_FOCUS;
110 
111  // Misc functions
112  bool ack();
113  bool isResponseOK();
114 
115  protected:
116  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
117  virtual bool ReverseFocuser(bool enabled) override;
118  virtual bool SyncFocuser(uint32_t ticks) override;
119 
120  virtual bool SetFocuserBacklash(int32_t steps) override;
121  virtual bool SetFocuserBacklashEnabled(bool enabled) override;
122 
123  // Move from private to public to validate
125 
126  // List all supported models
129 
130  // Led Intensity Value
133 
134  // Store version of the firmware from the HUB
135  char version[16];
136 
137  private:
138  uint32_t simPosition;
139  uint32_t targetPosition;
140 
141  ISState simStatus[8];
142  bool simCompensationOn;
143  char focusTarget[8];
144 
145  std::map<std::string, std::string> lynxModels;
146 
147  struct timeval focusMoveStart;
148  float focusMoveRequest;
149 
150  // Get functions
151  bool getFocusConfig();
152  bool getFocusStatus();
153  bool getFocusTemp();
154 
155  // Set functions
156 
157  // Position
158  bool setStepSize(uint16_t stepsize);
159 
160  // Temperature
161  bool setTemperatureCompensation(bool enable);
162  bool setTemperatureCompensationMode(char mode);
163  bool setTemperatureCompensationCoeff(char mode, int16_t coeff);
164  bool setTemperatureInceptions(char mode, int32_t inter);
165  bool setTemperatureCompensationOnStart(bool enable);
166 
167  // Motion functions
168  bool stop();
169  bool home();
170  bool center();
171 
172  // Led level
173  bool setLedLevel(int level);
174 
175  // Device Nickname
176  bool setDeviceNickname(const char *nickname);
177 
178  // Misc functions
179  bool resetFactory();
180  float calcTimeLeft(timeval, float);
181 
182  // Properties
183 
184  // Set/Get Temperature
185  INumber TemperatureN[1];
186  INumberVectorProperty TemperatureNP;
187 
188  // Enable/Disable temperature compensation
189  ISwitch TemperatureCompensateS[2];
190  ISwitchVectorProperty TemperatureCompensateSP;
191 
192  // Enable/Disable temperature compensation on start
193  ISwitch TemperatureCompensateOnStartS[2];
194  ISwitchVectorProperty TemperatureCompensateOnStartSP;
195 
196  // Temperature Coefficient Mode
197  ISwitch TemperatureCompensateModeS[5];
198  ISwitchVectorProperty TemperatureCompensateModeSP;
199 
200  // Temperature coefficient and Intercept for selected mode
201  INumber TemperatureParamN[2];
202  INumberVectorProperty TemperatureParamNP;
203 
204  // Reset to Factory setting
205  ISwitch ResetS[1];
206  ISwitchVectorProperty ResetSP;
207 
208  // Go to home/center
209  ISwitch GotoS[2];
210  ISwitchVectorProperty GotoSP;
211 
212  // Status indicators
213  ILight StatusL[8];
214  ILightVectorProperty StatusLP;
215 
216  // Max Travel for relative focusers
217  // INumber MaxTravelN[1];
218  // INumberVectorProperty MaxTravelNP;
219 
220  // Focuser Step Size
221  INumber StepSizeN[1];
222  INumberVectorProperty StepSizeNP;
223 
224  // Focus name configure in the HUB
225  IText HFocusNameT[1] {};
226  ITextVectorProperty HFocusNameTP;
227 
228  bool canHome;
229  bool isHoming;
230  // TODO add property for this.
231  bool m_HomeOnStart {false};
232 
233  static const uint8_t LYNX_MAX { 64 };
234 };
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
INumberVectorProperty LedNP
virtual int getVersion(int *major, int *minor, int *sub)
virtual const char * getDefaultName() override
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...
INumber LedN[1]
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
ISwitchVectorProperty ModelSP
char version[16]
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
ISwitch * ModelS
virtual void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
uint32_t DBG_FOCUS
bool configurationComplete
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
bool setDeviceType(int index)
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual IPState MoveAbsFocuser(uint32_t targetPosition) override
MoveFocuser the focuser to an absolute position.
void setFocusTarget(const char *target)
const char * getFocusTarget()
virtual bool loadConfig(bool silent, const char *property) override
Load the last saved configuration file.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
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.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool Handshake() override
perform handshake with device to check communication
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
virtual bool SetFocuserBacklashEnabled(bool enabled) override
SetFocuserBacklashEnabled Enables or disables the focuser backlash compensation.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
Implementations for common driver routines.
One light descriptor.
One number descriptor.
One switch descriptor.
One text descriptor.
Light vector property descriptor.
Definition: indiapi.h:417
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246