Instrument Neutral Distributed Interface INDI  2.0.2
teenastro.h
Go to the documentation of this file.
1 /*
2  TeenAstro Focuser
3  Copyright (C) 2021 Markus Noga
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 #ifndef TEENASTRO_FOCUSER_H
22 #define TEENASTRO_FOCUSER_H
23 
24 #include "indifocuser.h"
25 
27 {
28  public:
31 
32  const char * getDefaultName();
33  virtual bool Handshake();
34 
35  virtual bool ISNewNumber (const char *dev, const char *name, double values[], char *names[], int n);
36  virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n);
37 
38  protected:
39  // Helper function to update NP with the values if res is true and display status IPS_OK, else display status IPS_ALERT. Returns res for convenience.
40  bool ISNewNumberHelper(INumberVectorProperty *NP, double values[], char *names[], int n, bool res);
41 
42  virtual bool initProperties();
43 
44  // Initializes value ranges and steps for position UI controls based on maxPos.
45  // Does not force redraw via deleteMainControlProperties() and defineMainControlProperties()
46  void initPositionPropertiesRanges(uint32_t maxPos);
47 
48  virtual bool updateProperties();
50  void defineOtherProperties();
52  void deleteOtherProperties();
53 
54  virtual IPState MoveAbsFocuser(uint32_t ticks);
55  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks);
56  virtual bool AbortFocuser();
57  virtual void TimerHit();
58 
59  // Syncs device focuser position to given value. Returns true on success else false.
60  virtual bool SyncFocuser(uint32_t value);
61 
62  bool SetFocuserMaxPosition(uint32_t value);
63 
64  bool ReverseFocuser(bool enable);
65 
66  bool saveConfigItems(FILE *fp);
67 
68 
69  // Sends a command to the focuser. Returns true on success and false on failure.
70  bool send(const char *const msg);
71 
72  // Sends a command to the focuser, and waits for a response terminated by '#'. Returns true on success and false on failure.
73  bool sendAndReceive(const char *const msg, char *resp, int bufsize);
74 
75  // Sends a command to the focuser, and waits for a single character response. Returns true if successful and response is '1', otherwise false.
76  bool sendAndReceiveBool(const char *const msg);
77 
78  // Sends a command to the focuser, and expects a timeout. Returns true if timeout happens, else false
79  bool sendAndExpectTimeout(const char *const msg, char *resp, int bufsize);
80 
81  // Updates device version string from device
82  bool updateDeviceVersion();
83 
84  // Updates current state from device, consisting of position, speed, and temperature. Returns true on success and false on failure.
85  bool updateState();
86 
87  // Returns true if focuser is moving, else false.
88  bool isMoving();
89 
90  // Updates motion configuration from device. Returns true on success and false on failure.
91  bool updateMotionConfig();
92 
93  // Sets given configuration item on to device to provided value in device native units. Returns true on success and false on failure.
94  bool setConfigItem(char item, uint32_t deviceValue);
95  bool setParkPos(uint32_t value);
96  bool SetFocuserSpeed(int value); // sets TeenAstro GoTo speed
97  bool setManualSpeed(uint32_t value);
98  bool setGoToAcc(uint32_t value);
99  bool setManualAcc(uint32_t value);
100  bool setManualDec(uint32_t value);
101 
102  // Updates motor configuration from device. Returns true on success and false on failure.
103  bool updateMotorConfig();
104 
105  bool setMotorMicrosteps(uint32_t value);
106  bool setMotorResolution(uint32_t value);
107  bool setMotorCurrent(uint32_t value);
108  bool setMotorStepsPerRevolution(uint32_t value);
109 
110  // Starts movement of focuser towards the given absolute position. Returns immediately, true on success else false.
111  bool goTo(uint32_t position);
112 
113  // Starts movement of focuser towards the parking position. Returns immediately, true on success else false.
114  bool goToPark();
115 
116  // Stop focuser movement. Returns immediately, true on success else false.
117  bool stop();
118 
119  // Reboots the device microcontroller
120  bool rebootDevice();
121 
122  // Clears the device EEPROM
123  bool eraseDeviceEEPROM();
124 
125  // Main control tab
126  //
127 
128  // Focuser park position
131 
132  // Go to park button
135 
136  // Focuser max position is inherited from superclass as FocusMaxPosN, FocusMaxPosNP
137  // Sync current focuser position to given value inherited from superclass as FocusSyncN, FocusSyncNP
138 
139  // Current focuser speed
142 
143  // Focuser temperature
146 
147  // Focuser current position is inherited from superclass as FocusAbsPosN, FocusAbsPosNP
148 
149 
150  // Focuser configuration tab: motion configuration
151  //
152 
153  // Device version string
156 
157  // Focuser goto speed: FocusSpeedNP and FocusSpeedN[1] from superclass
158 
159  // Focuser manual speed
162 
163  // Go-to acceleration
166 
167  // Manual acceleration
170 
171  // Manual deceleration
174 
175 
176  // Focuser configuration tab: motor configuration
177  //
178 
179  // Reverse motor direction: FocusReverseSP and FocusReverseS[2] from superclass. [0] is enable, [1] is disable (i.e. normal)
180 
181  // Configuration element: Motor microsteps
182  enum
183  {
185  };
188 
189  // Configuration element: Impulse resolution (???)
192 
193  // Configuration element: Motor current
196 
197  // Configuration element: Motor steps per revolution
200 
201  // Reboot device microcontroller button
204 
205  // Erase device EEPROM button
208 };
209 
210 #endif // TEENASTRROFOCUSER_H
ISwitchVectorProperty RebootDeviceSP
Definition: teenastro.h:203
bool setManualSpeed(uint32_t value)
Definition: teenastro.cpp:717
void deleteOtherProperties()
Definition: teenastro.cpp:308
ISwitchVectorProperty CfgMotorMicrostepsSP
Definition: teenastro.h:187
INumberVectorProperty CfgMotorResolutionNP
Definition: teenastro.h:191
bool setMotorCurrent(uint32_t value)
Definition: teenastro.cpp:806
bool setManualAcc(uint32_t value)
Definition: teenastro.cpp:732
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
Definition: teenastro.cpp:326
bool sendAndReceiveBool(const char *const msg)
Definition: teenastro.cpp:560
bool setConfigItem(char item, uint32_t deviceValue)
Definition: teenastro.cpp:700
void deleteMainControlProperties()
Definition: teenastro.cpp:277
void defineOtherProperties()
Definition: teenastro.cpp:285
virtual bool AbortFocuser()
AbortFocuser all focus motion.
Definition: teenastro.cpp:502
INumber CfgManualAccN[1]
Definition: teenastro.h:168
virtual void TimerHit()
Callback function to be called once SetTimer duration elapses.
Definition: teenastro.cpp:493
bool saveConfigItems(FILE *fp)
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: teenastro.cpp:857
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
Definition: teenastro.cpp:389
bool setMotorStepsPerRevolution(uint32_t value)
Definition: teenastro.cpp:811
bool send(const char *const msg)
Definition: teenastro.cpp:523
INumberVectorProperty TempNP
Definition: teenastro.h:145
void initPositionPropertiesRanges(uint32_t maxPos)
Definition: teenastro.cpp:225
bool ReverseFocuser(bool enable)
ReverseFocuser Reverse focuser motion direction.
Definition: teenastro.cpp:787
virtual bool SyncFocuser(uint32_t value)
SyncFocuser Set current position to ticks without moving the focuser.
Definition: teenastro.cpp:816
void defineMainControlProperties()
Definition: teenastro.cpp:258
INumberVectorProperty CfgManualSpeedNP
Definition: teenastro.h:161
bool updateMotorConfig()
Definition: teenastro.cpp:743
INumber TempN[1]
Definition: teenastro.h:144
bool eraseDeviceEEPROM()
Definition: teenastro.cpp:849
bool setMotorMicrosteps(uint32_t value)
Definition: teenastro.cpp:792
INumberVectorProperty CfgGoToAccNP
Definition: teenastro.h:165
bool setMotorResolution(uint32_t value)
Definition: teenastro.cpp:801
ITextVectorProperty DeviceVersionTP
Definition: teenastro.h:155
ISwitchVectorProperty GoToParkSP
Definition: teenastro.h:134
ISwitch RebootDeviceS[1]
Definition: teenastro.h:202
const char * getDefaultName()
Definition: teenastro.cpp:77
bool SetFocuserMaxPosition(uint32_t value)
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
Definition: teenastro.cpp:712
INumber CurSpeedN[1]
Definition: teenastro.h:140
bool sendAndReceive(const char *const msg, char *resp, int bufsize)
Definition: teenastro.cpp:541
ISwitchVectorProperty EraseEEPROMSP
Definition: teenastro.h:207
bool updateDeviceVersion()
Definition: teenastro.cpp:601
ISwitch GoToParkS[1]
Definition: teenastro.h:133
bool sendAndExpectTimeout(const char *const msg, char *resp, int bufsize)
Definition: teenastro.cpp:581
INumberVectorProperty CfgMotorStepsPerRevolutionNP
Definition: teenastro.h:199
INumber CfgMotorStepsPerRevolutionN[1]
Definition: teenastro.h:198
INumber CfgMotorCurrentN[1]
Definition: teenastro.h:194
ISwitch CfgMotorMicrostepsS[TAF_MICROS_N]
Definition: teenastro.h:186
IText DeviceVersionT[1]
Definition: teenastro.h:154
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks)
MoveFocuser the focuser to an relative position.
Definition: teenastro.cpp:480
bool ISNewNumberHelper(INumberVectorProperty *NP, double values[], char *names[], int n, bool res)
Definition: teenastro.cpp:380
INumber CfgParkPosN[1]
Definition: teenastro.h:129
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: teenastro.cpp:231
INumberVectorProperty CfgManualDecNP
Definition: teenastro.h:173
bool SetFocuserSpeed(int value)
SetFocuserSpeed Set Focuser speed.
Definition: teenastro.cpp:722
bool setParkPos(uint32_t value)
Definition: teenastro.cpp:707
INumberVectorProperty CfgParkPosNP
Definition: teenastro.h:130
ISwitch EraseEEPROMS[1]
Definition: teenastro.h:206
bool setManualDec(uint32_t value)
Definition: teenastro.cpp:737
INumber CfgMotorResolutionN[1]
Definition: teenastro.h:190
INumberVectorProperty CurSpeedNP
Definition: teenastro.h:141
virtual IPState MoveAbsFocuser(uint32_t ticks)
MoveFocuser the focuser to an absolute position.
Definition: teenastro.cpp:461
INumber CfgGoToAccN[1]
Definition: teenastro.h:164
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
Definition: teenastro.cpp:115
virtual bool Handshake()
perform handshake with device to check communication
Definition: teenastro.cpp:82
INumber CfgManualSpeedN[1]
Definition: teenastro.h:160
bool updateMotionConfig()
Definition: teenastro.cpp:658
INumberVectorProperty CfgMotorCurrentNP
Definition: teenastro.h:195
INumberVectorProperty CfgManualAccNP
Definition: teenastro.h:169
INumber CfgManualDecN[1]
Definition: teenastro.h:172
bool goTo(uint32_t position)
Definition: teenastro.cpp:824
bool setGoToAcc(uint32_t value)
Definition: teenastro.cpp:727
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