Instrument Neutral Distributed Interface INDI  2.0.2
steeldrive.h
Go to the documentation of this file.
1 /*
2  Baader Steeldrive Focuser
3  Copyright (C) 2014 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 class SteelDrive : public INDI::Focuser
26 {
27  public:
28  SteelDrive();
29  virtual ~SteelDrive() = default;
30 
31  typedef struct
32  {
33  double maxTrip;
34  double gearRatio;
36 
38  enum
39  {
42  };
43  enum
44  {
47  };
48 
49  virtual bool Handshake() override;
50  const char *getDefaultName() override;
51  virtual bool initProperties() override;
52  virtual bool updateProperties() override;
53  virtual bool saveConfigItems(FILE *fp) override;
54 
55  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
56  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
57 
58  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
59  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
60  virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override;
61  virtual bool SetFocuserSpeed(int speed) override;
62  virtual bool AbortFocuser() override;
63  virtual void TimerHit() override;
64 
65  void debugTriggered(bool enable) override;
66 
67  private:
68  // Get functions
69  bool updateVersion();
70  bool updateTemperature();
71  bool updateTemperatureSettings();
72  bool updatePosition();
73  bool updateSpeed();
74  bool updateAcceleration();
75  bool updateCustomSettings();
76 
77  // Set functions
78  bool setStepMode(FocusStepMode mode);
79  bool setSpeed(unsigned short speed);
80  bool setCustomSettings(double maxTrip, double gearRatio);
81  bool setAcceleration(unsigned short accel);
82  bool setTemperatureSamples(unsigned int targetSamples, unsigned int *finalSample);
83  bool setTemperatureCompensation();
84 
85  bool Sync(unsigned int position);
86 
87  // Motion functions
88  bool moveFocuser(unsigned int position);
89  bool stop();
90  bool startMotion(FocusDirection dir);
91 
92  // Misc functions
93  bool saveFocuserConfig();
94  bool Ack();
95  void GetFocusParams();
96  float CalcTimeLeft(timeval, float);
97  void updateFocusMaxRange(double maxTrip, double gearRatio);
98 
99  double targetPos { 0 };
100  double lastPos { 0 };
101  double lastTemperature { 0 };
102  double simPosition { 0 };
103  unsigned int currentSpeed { 0 };
104  unsigned int temperatureUpdateCounter { 0 };
105  bool sim { false };
106 
107  struct timeval focusMoveStart
108  {
109  0, 0
110  };
111  float focusMoveRequest { 0 };
112 
113  INumber TemperatureN[1];
114  INumberVectorProperty TemperatureNP;
115 
116  INumber AccelerationN[1];
117  INumberVectorProperty AccelerationNP;
118 
119  INumber TemperatureSettingN[2];
120  INumberVectorProperty TemperatureSettingNP;
121 
122  ISwitch TemperatureCompensateS[2];
123  ISwitchVectorProperty TemperatureCompensateSP;
124 
125  ISwitch ModelS[5];
126  ISwitchVectorProperty ModelSP;
127 
128  INumber CustomSettingN[2];
129  INumberVectorProperty CustomSettingNP;
130 
131  INumber SyncN[1];
132  INumberVectorProperty SyncNP;
133 
134  IText VersionT[2] {};
135  ITextVectorProperty VersionTP;
136 
137  FocusCustomSetting fSettings[5];
138 };
void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
@ FOCUS_FULL_STEP
Definition: steeldrive.h:37
@ FOCUS_HALF_STEP
Definition: steeldrive.h:37
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 ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: steeldrive.cpp:128
@ FOCUS_T_COEFF
Definition: steeldrive.h:45
@ FOCUS_T_SAMPLES
Definition: steeldrive.h:46
virtual ~SteelDrive()=default
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
const char * getDefaultName() override
Definition: steeldrive.cpp:185
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: steeldrive.cpp:49
@ FOCUS_MAX_TRIP
Definition: steeldrive.h:40
@ FOCUS_GEAR_RATIO
Definition: steeldrive.h:41
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
virtual bool Handshake() override
perform handshake with device to check communication
Definition: steeldrive.cpp:168
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
One number descriptor.
One switch descriptor.
One text descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367
Text vector property descriptor.
Definition: indiapi.h:246