Instrument Neutral Distributed Interface INDI  1.9.5
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 { 0, 0 };
108  float focusMoveRequest { 0 };
109 
110  INumber TemperatureN[1];
111  INumberVectorProperty TemperatureNP;
112 
113  INumber AccelerationN[1];
114  INumberVectorProperty AccelerationNP;
115 
116  INumber TemperatureSettingN[2];
117  INumberVectorProperty TemperatureSettingNP;
118 
119  ISwitch TemperatureCompensateS[2];
120  ISwitchVectorProperty TemperatureCompensateSP;
121 
122  ISwitch ModelS[5];
123  ISwitchVectorProperty ModelSP;
124 
125  INumber CustomSettingN[2];
126  INumberVectorProperty CustomSettingNP;
127 
128  INumber SyncN[1];
129  INumberVectorProperty SyncNP;
130 
131  IText VersionT[2] {};
132  ITextVectorProperty VersionTP;
133 
134  FocusCustomSetting fSettings[5];
135 };
SteelDrive::getDefaultName
const char * getDefaultName() override
Definition: steeldrive.cpp:185
SteelDrive::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: steeldrive.cpp:128
SteelDrive::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: steeldrive.cpp:1249
IPState
IPState
Property state.
Definition: indiapi.h:158
ISwitch
One switch descriptor.
INumber
One number descriptor.
SteelDrive
Definition: steeldrive.h:25
SteelDrive::SetFocuserSpeed
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: steeldrive.cpp:1232
SteelDrive::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: steeldrive.cpp:1474
SteelDrive::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: steeldrive.cpp:1274
SteelDrive::FocusCustomSetting::maxTrip
double maxTrip
Definition: steeldrive.h:33
indifocuser.h
_ITextVectorProperty
Text vector property descriptor.
Definition: indiapi.h:244
SteelDrive::FOCUS_MAX_TRIP
@ FOCUS_MAX_TRIP
Definition: steeldrive.h:40
SteelDrive::SteelDrive
SteelDrive()
Definition: steeldrive.cpp:43
SteelDrive::FOCUS_FULL_STEP
@ FOCUS_FULL_STEP
Definition: steeldrive.h:37
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
SteelDrive::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: steeldrive.cpp:49
IText
One text descriptor.
SteelDrive::FocusCustomSetting
Definition: steeldrive.h:31
SteelDrive::~SteelDrive
virtual ~SteelDrive()=default
SteelDrive::FOCUS_HALF_STEP
@ FOCUS_HALF_STEP
Definition: steeldrive.h:37
SteelDrive::debugTriggered
void debugTriggered(bool enable) override
Inform driver that the debug option was triggered. This function is called after setDebug is triggere...
Definition: steeldrive.cpp:1513
SteelDrive::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: steeldrive.cpp:1023
SteelDrive::FOCUS_T_SAMPLES
@ FOCUS_T_SAMPLES
Definition: steeldrive.h:46
SteelDrive::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: steeldrive.cpp:1076
SteelDrive::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: steeldrive.cpp:1312
name
const char * name
Definition: indiserver.c:116
SteelDrive::FOCUS_T_COEFF
@ FOCUS_T_COEFF
Definition: steeldrive.h:45
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
ISState
ISState
Switch state.
Definition: indiapi.h:148
SteelDrive::FocusStepMode
FocusStepMode
Definition: steeldrive.h:37
INDI::Focuser
Definition: indifocuser.h:43
SteelDrive::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: steeldrive.cpp:1421
SteelDrive::FOCUS_GEAR_RATIO
@ FOCUS_GEAR_RATIO
Definition: steeldrive.h:41
SteelDrive::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
Definition: steeldrive.cpp:1290
SteelDrive::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: steeldrive.cpp:168
SteelDrive::FocusCustomSetting::gearRatio
double gearRatio
Definition: steeldrive.h:34
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365