Instrument Neutral Distributed Interface INDI  2.0.2
rainbowRSF.h
Go to the documentation of this file.
1 /*
2  Rainbow Astro Focuser
3  Copyright (C) 2020 Abdulaziz Bouland (boulandab@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 <memory>
24 #include "indifocuser.h"
25 #include "indielapsedtimer.h"
26 
27 class RainbowRSF : public INDI::Focuser
28 {
29  public:
30  RainbowRSF();
31 
32  const char *getDefaultName() override;
33  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
34 
35  protected:
36  virtual bool initProperties() override;
37  virtual bool updateProperties() override;
38  virtual void TimerHit() override;
39  virtual bool Handshake() override;
40 
44  // Move focuser to absolute position from 0 to 16000 (-8000 to 8000)
45  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
46  // Move focuser to a relative position from the current position
47  virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override;
48 
49 
50  // Get temperature in Celcius
51  bool updateTemperature();
52  // Find home
53  bool findHome();
54  // Update position
55  bool updatePosition();
56 
60  bool sendCommand(const char * cmd, char * res, int res_len);
61 
62  private:
63 
67  ISwitchVectorProperty GoHomeSP;
68  ISwitch GoHomeS[1];
69 
70  INumberVectorProperty TemperatureNP;
71  INumber TemperatureN[1];
72 
73  uint32_t m_TargetPosition { 0 };
74  uint32_t m_LastPosition { 0 };
75  double m_LastTemperature { 0 };
76  uint16_t m_TemperatureCounter { 0 };
77 
78  const static uint32_t homePosition { 8000 };
79 
80  // Timer used to timeout when waiting for requested movement to complete.
81  INDI::ElapsedTimer m_MovementTimer;
82  bool m_MovementTimerActive { false };
83 
87  // # is the stop char
88  static const char DRIVER_STOP_CHAR { '#' };
89  // Update temperature every 10x POLLMS. For 500ms, we would
90  // update the temperature one every 5 seconds.
91  static constexpr const uint8_t DRIVER_TEMPERATURE_FREQ {10};
92  // Wait up to a maximum of 3 seconds for serial input
93  static constexpr const uint8_t DRIVER_TIMEOUT {3};
94  // Maximum buffer for sending/receving.
95  static constexpr const uint8_t DRIVER_LEN {16};
96 };
The ElapsedTimer class provides a fast way to calculate elapsed times.
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
Focuser Command Functions.
Definition: rainbowRSF.cpp:355
bool updatePosition()
Definition: rainbowRSF.cpp:194
virtual bool Handshake() override
perform handshake with device to check communication
Definition: rainbowRSF.cpp:155
bool updateTemperature()
Definition: rainbowRSF.cpp:328
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: rainbowRSF.cpp:410
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: rainbowRSF.cpp:131
virtual IPState MoveRelFocuser(FocusDirection dir, unsigned int ticks) override
Definition: rainbowRSF.cpp:374
bool sendCommand(const char *cmd, char *res, int res_len)
Communication Functions.
Definition: rainbowRSF.cpp:452
bool findHome()
Definition: rainbowRSF.cpp:389
const char * getDefaultName() override
Definition: rainbowRSF.cpp:63
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: rainbowRSF.cpp:111
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: rainbowRSF.cpp:71
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
__u8 cmd[4]
Definition: pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
Number vector property descriptor.
Definition: indiapi.h:319
Switch vector property descriptor.
Definition: indiapi.h:367