Instrument Neutral Distributed Interface INDI 2.2.5
nstep.h
Go to the documentation of this file.
1/*
2 NStep Focuser
3
4 Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
5
6 Thanks to Rigel Systems, especially Gene Nolan and Leon Palmer,
7 for their support in writing this driver.
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#pragma once
25
26#include "indifocuser.h"
27
28class NStep : public INDI::Focuser
29{
30 public:
31 NStep();
32
33 virtual bool Handshake() override;
34 const char *getDefaultName() override;
35
36 bool initProperties() override;
37 bool updateProperties() override;
38
39 bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
40 bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
41
42 protected:
43 void TimerHit() override;
44
45 IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
46 IPState MoveAbsFocuser(uint32_t targetTicks) override;
47 bool SetFocuserSpeed(int speed) override;
48 bool SyncFocuser(uint32_t ticks) override;
49 bool AbortFocuser() override;
50
51 bool saveConfigItems(FILE *fp) override;
52
53 private:
54
58
59 INumber TemperatureN[1];
60 INumberVectorProperty TemperatureNP;
61
62 ISwitch CompensationModeS[3];
63 ISwitchVectorProperty CompensationModeSP;
64 enum
65 {
66 COMPENSATION_MODE_OFF,
67 COMPENSATION_MODE_ONE_SHOT,
68 COMPENSATION_MODE_AUTO,
69 };
70
71 INumber CompensationSettingsN[4];
72 INumberVectorProperty CompensationSettingsNP;
73 enum
74 {
75 COMPENSATION_SETTING_CHANGE,
76 COMPENSATION_SETTING_STEP,
77 COMPENSATION_SETTING_BACKLASH,
78 COMPENSATION_SETTING_TIMER,
79 };
80
81 ISwitch PrimeManualS[1];
82 ISwitchVectorProperty PrimeManualSP;
83
84 ISwitch SteppingModeS[3];
85 ISwitchVectorProperty SteppingModeSP;
86 enum
87 {
88 STEPPING_WAVE,
89 STEPPING_HALF,
90 STEPPING_FULL,
91 };
92
93 ISwitch CoilStatusS[2];
94 ISwitchVectorProperty CoilStatusSP;
95 enum
96 {
97 COIL_ENERGIZED_OFF,
98 COIL_ENERGIZED_ON,
99 };
100
101 INumber SteppingPhaseN[1];
102 INumberVectorProperty SteppingPhaseNP;
103
104 INumber MaxSpeedN[1];
105 INumberVectorProperty MaxSpeedNP;
106
110 bool readTemperature();
111 bool readPosition();
112 bool readCompensationInfo();
113 bool readSpeedInfo();
114 bool readSteppingInfo();
115 bool readCoilStatus();
116
120 bool setCompensationMode(uint8_t mode);
121 bool setCompensationSettings(double change, double move, double backlash, double timer);
122 bool setSteppingPhase(uint8_t phase);
123 bool setCoilStatus(uint8_t status);
124 bool setMaxSpeed(uint8_t maxSpeed);
125
129 bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
130 bool getStartupValues();
131 void hexDump(char * buf, const char * data, int size);
132 bool isMoving();
133
137 int32_t m_TargetDiff { 0 };
138 uint16_t m_TemperatureCounter { 0 };
139
143 static constexpr const char * COMPENSATION_TAB = "Compensation";
144 static constexpr const char * STEPPING_TAB = "Stepping";
145 // '#' is the stop char
146 static const char NSTEP_STOP_CHAR { 0x23 };
147 // Update temperature every 10x POLLMS. For 500ms, we would
148 // update the temperature one every 5 seconds.
149 static constexpr const uint8_t NSTEP_TEMPERATURE_FREQ {10};
150 // Wait up to a maximum of 3 seconds for serial input
151 static constexpr const uint8_t NSTEP_TIMEOUT {3};
152 // Maximum buffer for sending/receiving.
153 static constexpr const uint8_t NSTEP_LEN {64};
154};
Definition nstep.h:29
NStep()
Definition nstep.cpp:33
bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
Definition nstep.cpp:43
bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition nstep.cpp:726
IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition nstep.cpp:439
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition nstep.cpp:456
bool saveConfigItems(FILE *fp) override
Definition nstep.cpp:793
IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition nstep.cpp:445
bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
Definition nstep.cpp:122
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Processes incoming new number values from the client for this device. Handles updates to FocuserInter...
Definition nstep.cpp:253
const char * getDefaultName() override
Definition nstep.cpp:117
virtual bool Handshake() override
Performs a device-specific handshake after a connection is established. This method should be overrid...
Definition nstep.cpp:171
bool AbortFocuser() override
AbortFocuser all focus motion.
Definition nstep.cpp:451
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
Definition nstep.cpp:338
bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition nstep.cpp:719
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158
uint8_t cmd[4]
Definition pwc-ioctl.h:2
One number descriptor.
One switch descriptor.
Number vector property descriptor.
Definition indiapi.h:317
Switch vector property descriptor.
Definition indiapi.h:365