Instrument Neutral Distributed Interface INDI  2.0.2
sestosenso2.h
Go to the documentation of this file.
1 /*
2  SestoSenso 2 Focuser
3  Copyright (C) 2020 Piotr Zyziuk
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 #include "inditimer.h"
25 #include "primalucacommandset.h"
26 
27 class SestoSenso2 : public INDI::Focuser
28 {
29  public:
30  SestoSenso2();
31  virtual ~SestoSenso2() override = default;
32 
33  const char *getDefaultName() override;
34  virtual bool initProperties() override;
35  virtual bool updateProperties() override;
36  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
37  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
38 
39  protected:
40  virtual bool Handshake() override;
41  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
42  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
43  virtual bool ReverseFocuser(bool enabled) override;
44  virtual bool AbortFocuser() override;
45  virtual void TimerHit() override;
46  virtual bool SetFocuserBacklash(int32_t steps) override;
47 
48  virtual bool saveConfigItems(FILE *fp) override;
49 
50  private:
51  bool Ack();
52  bool setMinLimit(uint32_t limit);
53  bool setMaxLimit(uint32_t limit);
54  bool updateMaxLimit();
55 
56  bool updateTemperature();
57  bool updatePosition();
58  bool updateVoltageIn();
59  bool fetchMotorSettings();
60  bool applyMotorRates();
61  bool applyMotorCurrents();
62  void setConnectionParams();
63  bool initCommandSet();
64  void checkMotionProgressCallback();
65  void checkHallSensorCallback();
66 
67  bool getStartupValues();
68  void hexDump(char * buf, const char * data, int size);
69  bool isMotionComplete();
70 
71  FocusDirection backlashDirection { FOCUS_INWARD };
72  FocusDirection oldbacklashDirection { FOCUS_INWARD };
73 
74  int32_t startPos { 0 };
75  uint32_t backlashTicks { 0 };
76  uint32_t targetPos { 0 };
77  uint32_t lastPos { 0 };
78  int32_t previousPos { 0 };
79  double lastVoltageIn { 0 };
80  double lastTemperature { 0 };
81  uint16_t m_TemperatureCounter { 0 };
82 
83  INDI::PropertyNumber TemperatureNP {2};
84  enum
85  {
86  TEMPERATURE_EXTERNAL,
87  TEMPERATURE_MOTOR,
88  };
89 
90  INDI::PropertyNumber SpeedNP {1};
91 
92  INDI::PropertyText FirmwareTP {2};
93  enum
94  {
95  FIRMWARE_SN,
96  FIRMWARE_VERSION,
97  };
98 
99  INDI::PropertyNumber VoltageInNP {1};
100 
101  INDI::PropertySwitch CalibrationSP {2};
102  enum
103  {
104  CALIBRATION_START,
105  CALIBRATION_NEXT
106  };
107 
108  INDI::PropertySwitch FastMoveSP {3};
109  enum
110  {
111  FASTMOVE_IN,
112  FASTMOVE_OUT,
113  FASTMOVE_STOP
114  };
115 
116  enum
117  {
118  CMD_OK = true,
119  CMD_FALSE = false
120  };
121 
122  INDI::PropertyNumber MotorRateNP {3};
123  enum
124  {
125  MOTOR_RATE_ACC,
126  MOTOR_RATE_RUN,
127  MOTOR_RATE_DEC
128  };
129 
130  INDI::PropertyNumber MotorCurrentNP {4};
131  enum
132  {
133  MOTOR_CURR_ACC,
134  MOTOR_CURR_RUN,
135  MOTOR_CURR_DEC,
136  MOTOR_CURR_HOLD
137  };
138 
139  INDI::PropertySwitch MotorHoldSP {2};
140  enum
141  {
142  MOTOR_HOLD_ON,
143  MOTOR_HOLD_OFF
144  };
145 
146  INDI::PropertySwitch MotorApplyPresetSP {3};
147  enum
148  {
149  MOTOR_APPLY_LIGHT,
150  MOTOR_APPLY_MEDIUM,
151  MOTOR_APPLY_HEAVY,
152  };
153 
154  INDI::PropertySwitch MotorApplyUserPresetSP {3};
155  enum
156  {
157  MOTOR_APPLY_USER1,
158  MOTOR_APPLY_USER2,
159  MOTOR_APPLY_USER3
160  };
161 
162  INDI::PropertySwitch MotorSaveUserPresetSP {3};
163  enum
164  {
165  MOTOR_SAVE_USER1,
166  MOTOR_SAVE_USER2,
167  MOTOR_SAVE_USER3
168  };
169 
170  INDI::PropertyText CalibrationMessageTP {1};
171  typedef enum { Idle, GoToMiddle, GoMinimum, GoDupa, GoMaximum, Complete } CalibrationStage;
172  CalibrationStage cStage { Idle };
173 
174  INDI::Timer m_MotionProgressTimer;
175  INDI::Timer m_HallSensorTimer;
176  bool m_IsSestoSenso2 { true };
177 
178  std::unique_ptr<PrimalucaLabs::SestoSenso2> m_SestoSenso2;
182  // CR is the stop char
183  static const char SESTO_STOP_CHAR { 0xD };
184  // Update temperature every 10x POLLMS. For 500ms, we would
185  // update the temperature one every 5 seconds.
186  static constexpr const uint8_t SESTO_TEMPERATURE_FREQ {10};
187  // Wait up to a maximum of 3 seconds for serial input
188  static constexpr const uint8_t SESTO_TIMEOUT {5};
189  // Maximum buffer for sending/receving.
190  static constexpr const int SESTO_LEN {1024};
191 
192 };
The Timer class provides repetitive and single-shot timers.
Definition: inditimer.h:41
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: sestosenso2.cpp:62
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
const char * getDefaultName() override
virtual ~SestoSenso2() override=default
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
virtual bool Handshake() override
perform handshake with device to check communication
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160