Instrument Neutral Distributed Interface INDI  1.9.5
deepskydad_af3.h
Go to the documentation of this file.
1 /*
2  Deep Sky Dad AF3
3 
4  Copyright (C) 2019 Pavle Gartner
5 
6  Based on Moonline driver.
7  Copyright (C) 2013-2019 Jasem Mutlaq (mutlaqja@ikarustech.com)
8 
9  This library is free software; you can redistribute it and/or
10  modify it under the terms of the GNU Lesser General Public
11  License as published by the Free Software Foundation; either
12  version 2.1 of the License, or (at your option) any later version.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library; if not, write to the Free Software
21  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 
23 */
24 
25 #pragma once
26 
27 #include "indifocuser.h"
28 
29 #include <chrono>
30 
32 {
33  public:
34  DeepSkyDadAF3();
35  virtual ~DeepSkyDadAF3() override = default;
36 
37  typedef enum { S1, S2, S4, S8, S16, S32, S64, S128, S256 } FocusStepMode;
39 
40  const char * getDefaultName() override;
41  virtual bool initProperties() override;
42  virtual bool updateProperties() override;
43  virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
44  virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
45 
46  static void timedMoveHelper(void * context);
47  protected:
48  /*
49  * @brief Handshake Try to communicate with Focuser and see if there is a valid response.
50  * @return True if communication is successful, false otherwise.
51  */
52  virtual bool Handshake() override;
53 
61  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
62 
68  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
69 
76  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
77 
78  virtual bool SyncFocuser(uint32_t ticks) override;
79  virtual bool ReverseFocuser(bool enabled) override;
80  virtual bool AbortFocuser() override;
81  virtual void TimerHit() override;
82  virtual bool saveConfigItems(FILE * fp) override;
83  virtual bool SetFocuserBacklash(int32_t steps) override;
84  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
85 
86  private:
87  bool Ack();
95  bool sendCommand(const char * cmd, char * res = nullptr);
96  bool sendCommandSet(const char * cmd);
97 
98  // Get initial focuser parameter when we first connect
99  void GetFocusParams();
100  bool readStepMode();
101  bool readSpeedMode();
102  bool readPosition();
103  bool readMaxPosition();
104  bool readMaxMovement();
105  bool readSettleBuffer();
106  bool readMoveCurrentMultiplier();
107  bool readHoldCurrentMultiplier();
108  bool isMoving();
109  bool readTemperature();
110 
111  void timedMoveCallback();
112 
113  bool MoveFocuser(uint32_t position);
114 
115  double targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 }, backlashComp {0};
116 
117  bool moveAborted = false;
118 
119  // Step mode
120  ISwitch StepModeS[9];
121  ISwitchVectorProperty StepModeSP;
122 
123  // Speed mode
124  ISwitch SpeedModeS[5];
125  ISwitchVectorProperty SpeedModeSP;
126 
127  //Current move
128  INumber MoveCurrentMultiplierN[1];
129  INumberVectorProperty MoveCurrentMultiplierNP;
130 
131  //Current hold
132  INumber HoldCurrentMultiplierN[1];
133  INumberVectorProperty HoldCurrentMultiplierNP;
134 
135  // Max movement
136  INumber FocusMaxMoveN[1];
137  INumberVectorProperty FocusMaxMoveNP;
138 
139  // Settle buffer
140  INumber SettleBufferN[1];
141  INumberVectorProperty SettleBufferNP;
142 
143  INumber TemperatureN[1];
144  INumberVectorProperty TemperatureNP;
145 
146  // Response Buffer
147 
148  static const uint8_t DSD_RES { 32 };
149  static const char DSD_DEL { ')' };
150  static const uint8_t DSD_TIMEOUT { 3 };
151 };
DeepSkyDadAF3::S128
@ S128
Definition: deepskydad_af3.h:37
DeepSkyDadAF3::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: deepskydad_af3.cpp:853
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
DeepSkyDadAF3::MoveFocuser
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser Move focuser in a specific direction and speed for period of time.
Definition: deepskydad_af3.cpp:714
DeepSkyDadAF3::SLOW
@ SLOW
Definition: deepskydad_af3.h:38
DeepSkyDadAF3::S1
@ S1
Definition: deepskydad_af3.h:37
DeepSkyDadAF3::S2
@ S2
Definition: deepskydad_af3.h:37
IPState
IPState
Property state.
Definition: indiapi.h:158
DeepSkyDadAF3
Definition: deepskydad_af3.h:31
ISwitch
One switch descriptor.
INumber
One number descriptor.
DeepSkyDadAF3::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: deepskydad_af3.cpp:129
DeepSkyDadAF3::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: deepskydad_af3.cpp:582
DeepSkyDadAF3::SetFocuserBacklash
virtual bool SetFocuserBacklash(int32_t steps) override
SetFocuserBacklash Set the focuser backlash compensation value.
Definition: deepskydad_af3.cpp:911
DeepSkyDadAF3::VERY_SLOW
@ VERY_SLOW
Definition: deepskydad_af3.h:38
DeepSkyDadAF3::S8
@ S8
Definition: deepskydad_af3.h:37
indifocuser.h
DeepSkyDadAF3::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: deepskydad_af3.cpp:44
DeepSkyDadAF3::S16
@ S16
Definition: deepskydad_af3.h:37
DeepSkyDadAF3::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
Definition: deepskydad_af3.cpp:764
DeepSkyDadAF3::~DeepSkyDadAF3
virtual ~DeepSkyDadAF3() override=default
DeepSkyDadAF3::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: deepskydad_af3.cpp:446
DeepSkyDadAF3::VERY_FAST
@ VERY_FAST
Definition: deepskydad_af3.h:38
DeepSkyDadAF3::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: deepskydad_af3.cpp:161
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
DeepSkyDadAF3::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: deepskydad_af3.cpp:476
DeepSkyDadAF3::S64
@ S64
Definition: deepskydad_af3.h:37
DeepSkyDadAF3::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: deepskydad_af3.cpp:785
DeepSkyDadAF3::DeepSkyDadAF3
DeepSkyDadAF3()
Definition: deepskydad_af3.cpp:38
DeepSkyDadAF3::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: deepskydad_af3.cpp:438
DeepSkyDadAF3::SetFocuserMaxPosition
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
Definition: deepskydad_af3.cpp:917
DeepSkyDadAF3::FocusStepMode
FocusStepMode
Definition: deepskydad_af3.h:37
DeepSkyDadAF3::S4
@ S4
Definition: deepskydad_af3.h:37
DeepSkyDadAF3::timedMoveHelper
static void timedMoveHelper(void *context)
Definition: deepskydad_af3.cpp:728
name
const char * name
Definition: indiserver.c:116
DeepSkyDadAF3::FocusSpeedMode
FocusSpeedMode
Definition: deepskydad_af3.h:38
DeepSkyDadAF3::MEDIUM
@ MEDIUM
Definition: deepskydad_af3.h:38
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
DeepSkyDadAF3::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
Definition: deepskydad_af3.cpp:746
DeepSkyDadAF3::S256
@ S256
Definition: deepskydad_af3.h:37
ISState
ISState
Switch state.
Definition: indiapi.h:148
DeepSkyDadAF3::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: deepskydad_af3.cpp:847
INDI::Focuser
Definition: indifocuser.h:43
DeepSkyDadAF3::FAST
@ FAST
Definition: deepskydad_af3.h:38
DeepSkyDadAF3::getDefaultName
const char * getDefaultName() override
Definition: deepskydad_af3.cpp:174
DeepSkyDadAF3::S32
@ S32
Definition: deepskydad_af3.h:37
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365