Instrument Neutral Distributed Interface INDI 2.2.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-2023 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
77{
78 public:
79 USBFocusV3();
80 virtual ~USBFocusV3() = default;
81
87
88 virtual bool Handshake() override;
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 INDI::PropertyNumber TemperatureNP{1};
162 INDI::PropertySwitch StepModeSP{2};
163 INDI::PropertySwitch RotDirSP{2};
164 INDI::PropertyNumber MaxPositionNP{1};
165 INDI::PropertyNumber TemperatureSettingNP{2};
166 INDI::PropertySwitch TempCompSignSP{2};
167 INDI::PropertySwitch TemperatureCompensateSP{2};
168 INDI::PropertySwitch ResetSP{1};
169 INDI::PropertyNumber FWversionNP{1};
170};
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 void TimerHit() override
Callback function to be called once SetTimer duration elapses.
bool getControllerStatus()
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual ~USBFocusV3()=default
@ FOCUS_FULL_STEP
Definition usbfocusv3.h:85
@ FOCUS_HALF_STEP
Definition usbfocusv3.h:84
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
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 updateProperties() override
Updates the state and definition of properties based on the current connection status....
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
virtual const char * getDefaultName() override
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
uint8_t cmd[4]
Definition pwc-ioctl.h:2