Instrument Neutral Distributed Interface INDI  1.9.5
usbfocusv3.h
Go to the documentation of this file.
1 /*
2  USB Focus V3
3  Copyright (C) 2016 G. Schmidt
4  Copyright (C) 2018 Jarno Paananen
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 */
21 
22 #pragma once
23 
24 #include "indifocuser.h"
25 
26 /***************************** USB Focus V3 Commands **************************/
27 
28 #define UFOCREADPARAM "SGETAL"
29 #define UFOCDEVID "SWHOIS"
30 #define UFOCREADPOS "FPOSRO"
31 #define UFOCREADTEMP "FTMPRO"
32 #define UFOCMOVEOUT "O%05u"
33 #define UFOCMOVEIN "I%05u"
34 #define UFOCABORT "FQUITx"
35 #define UFOCSETMAX "M%05u"
36 #define UFOCSETSPEED "SMO%03u"
37 #define UFOCSETTCTHR "SMA%03u"
38 #define UFOCSETSDIR "SMROTH"
39 #define UFOCSETRDIR "SMROTT"
40 #define UFOCSETFSTEPS "SMSTPF"
41 #define UFOCSETHSTEPS "SMSTPD"
42 #define UFOCSETSTDEG "FLA%03u"
43 #define UFOCGETSIGN "FTAXXA"
44 #define UFOCSETSIGN "FZAXX%1u"
45 #define UFOCSETAUTO "FAMODE"
46 #define UFOCSETMANU "FMMODE"
47 #define UFOCRESET "SEERAZ"
48 
49 /**************************** USB Focus V3 Constants **************************/
50 
51 #define UFOID "UFO"
52 
53 #define UFORSACK '*'
54 #define UFORSAUTO "AP"
55 #define UFORSDONE "DONE"
56 #define UFORSERR "ER=1"
57 #define UFORSRESET "EEPROM RESET"
58 
59 #define UFOPSDIR 0 // standard direction
60 #define UFOPRDIR 1 // reverse direction
61 #define UFOPFSTEPS 0 // full steps
62 #define UFOPHSTEPS 1 // half steps
63 #define UFOPPSIGN 0 // positive temp. comp. sign
64 #define UFOPNSIGN 1 // negative temp. comp. sign
65 
66 #define UFOPSPDERR 0 // invalid speed
67 #define UFOPSPDAV 2 // average speed
68 #define UFOPSPDSL 3 // slow speed
69 #define UFOPSPDUS 4 // ultra slow speed
70 
71 #define UFORESLEN 32 // maximum length of returned response with some margin (28 characters is actual maximum)
72 #define UFOCMDLEN 6 // length of all commands
73 
74 /******************************************************************************/
75 
76 class USBFocusV3 : public INDI::Focuser
77 {
78  public:
79  USBFocusV3();
80  virtual ~USBFocusV3() = default;
81 
82  typedef enum
83  {
86  } FocusStepMode;
87 
88  virtual bool Handshake() override;
89  bool getControllerStatus();
90  virtual const char *getDefaultName() override;
91  virtual bool initProperties() override;
92  virtual bool updateProperties() override;
93  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
94  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
95  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
96  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
97  virtual bool SetFocuserSpeed(int speed) override;
98  virtual bool AbortFocuser() override;
99  virtual void TimerHit() override;
100  //virtual bool saveConfigItems(FILE *fp) override;
101 
102  virtual bool SetFocuserBacklash(int32_t steps) override;
103 
104  private:
105  bool sendCommand(const char *cmd, char *response);
106  bool sendCommandSpecial(const char *cmd, char *response);
107 
108  pthread_mutex_t cmdlock;
109 
110  void GetFocusParams();
111  bool reset();
112  bool updateStepMode();
113  bool updateRotDir();
114  bool updateTemperature();
115  bool updatePosition();
116  bool updateMaxPos();
117  bool updateTempCompSettings();
118  bool updateTempCompSign();
119  bool updateSpeed();
120  bool updateFWversion();
121 
122  bool Ack();
123  bool Resync();
124 
125  bool MoveFocuserUF(FocusDirection dir, unsigned int rticks);
126  bool setStepMode(FocusStepMode mode);
127  bool setRotDir(unsigned int dir);
128  bool setMaxPos(unsigned int maxp);
129  bool setSpeed(unsigned short drvspeed);
130  bool setAutoTempCompThreshold(unsigned int thr);
131  bool setTemperatureCoefficient(unsigned int coefficient);
132  bool setTempCompSign(unsigned int sign);
133  bool setTemperatureCompensation(bool enable);
134  float CalcTimeLeft(timeval, float);
135 
136  unsigned int direction{ 0 }; // 0 standard, 1 reverse
137  unsigned int stepmode{ 0 }; // 0 full steps, 1 half steps
138  unsigned int speed{ 0 }; // 2 average, 3 slow, 4 ultra slow
139  unsigned int stepsdeg{ 0 }; // steps per degree for temperature compensation
140  unsigned int tcomp_thr{ 0 }; // temperature compensation threshold
141  unsigned int firmware{ 0 }; // firmware version
142  unsigned int maxpos{ 0 }; // maximum step position (0..65535)
143 
144  double targetPos{ 0 };
145  double backlashTargetPos{ 0 };
146  double lastPos{ 0 };
147  int backlashSteps{ 0 };
148  bool backlashIn{ false };
149  bool backlashMove{ false };
150  bool moving{ false };
151 
152  double lastTemperature{ 0 };
153  unsigned int currentSpeed{ 0 };
154 
155  struct timeval focusMoveStart
156  {
157  0, 0
158  };
159  float focusMoveRequest{ 0 };
160 
161  INumber TemperatureN[1];
162  INumberVectorProperty TemperatureNP;
163 
164  ISwitch StepModeS[2];
165  ISwitchVectorProperty StepModeSP;
166 
167  ISwitch RotDirS[2];
168  ISwitchVectorProperty RotDirSP;
169 
170  INumber MaxPositionN[1];
171  INumberVectorProperty MaxPositionNP;
172 
173  INumber TemperatureSettingN[2];
174  INumberVectorProperty TemperatureSettingNP;
175 
176  ISwitch TempCompSignS[2];
177  ISwitchVectorProperty TempCompSignSP;
178 
179  ISwitch TemperatureCompensateS[2];
180  ISwitchVectorProperty TemperatureCompensateSP;
181 
182  // INumber BacklashSettingN[1];
183  // INumberVectorProperty BacklashSettingNP;
184 
185  typedef enum
186  {
187  BACKLASH_IN = 0,
188  BACKLASH_OUT = 1
189  } BacklashDirection;
190 
191  // ISwitch BacklashDirectionS[2];
192  // ISwitchVectorProperty BacklashDirectionSP;
193 
194  ISwitch ResetS[1];
195  ISwitchVectorProperty ResetSP;
196 
197  INumber FWversionN[1];
198  INumberVectorProperty FWversionNP;
199 };
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
USBFocusV3::SetFocuserBacklash
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: usbfocusv3.cpp:1219
IPState
IPState
Property state.
Definition: indiapi.h:158
ISwitch
One switch descriptor.
USBFocusV3::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: usbfocusv3.cpp:1086
INumber
One number descriptor.
USBFocusV3::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: usbfocusv3.cpp:196
USBFocusV3::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: usbfocusv3.cpp:1117
USBFocusV3::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: usbfocusv3.cpp:49
indifocuser.h
USBFocusV3::FocusStepMode
FocusStepMode
Definition: usbfocusv3.h:82
USBFocusV3::FOCUS_FULL_STEP
@ FOCUS_FULL_STEP
Definition: usbfocusv3.h:85
USBFocusV3
Definition: usbfocusv3.h:76
USBFocusV3::~USBFocusV3
virtual ~USBFocusV3()=default
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
USBFocusV3::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: usbfocusv3.cpp:956
USBFocusV3::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: usbfocusv3.cpp:816
USBFocusV3::FOCUS_HALF_STEP
@ FOCUS_HALF_STEP
Definition: usbfocusv3.h:84
name
const char * name
Definition: indiserver.c:116
USBFocusV3::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: usbfocusv3.cpp:1063
USBFocusV3::getDefaultName
virtual const char * getDefaultName() override
Definition: usbfocusv3.cpp:216
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
USBFocusV3::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: usbfocusv3.cpp:153
ISState
ISState
Switch state.
Definition: indiapi.h:148
USBFocusV3::SetFocuserSpeed
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: usbfocusv3.cpp:1046
INDI::Focuser
Definition: indifocuser.h:43
USBFocusV3::getControllerStatus
bool getControllerStatus()
Definition: usbfocusv3.cpp:366
USBFocusV3::USBFocusV3
USBFocusV3()
Definition: usbfocusv3.cpp:39
USBFocusV3::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: usbfocusv3.cpp:1187
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365