Instrument Neutral Distributed Interface INDI  1.9.5
moonlite.h
Go to the documentation of this file.
1 /*
2  Moonlite Focuser
3  Copyright (C) 2013-2019 Jasem Mutlaq (mutlaqja@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 "indifocuser.h"
24 
25 #include <chrono>
26 
27 class MoonLite : public INDI::Focuser
28 {
29  public:
30  MoonLite();
31  virtual ~MoonLite() override = default;
32 
34 
35  const char * getDefaultName() override;
36  virtual bool initProperties() override;
37  virtual bool updateProperties() override;
38  virtual bool ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) override;
39  virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
40 
41  static void timedMoveHelper(void * context);
42 
43  protected:
48  virtual bool Handshake() override;
49 
57  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
58 
64  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
65 
72  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
73 
79  virtual bool SyncFocuser(uint32_t ticks) override;
80 
81  virtual bool SetFocuserSpeed(int speed) override;
82  virtual bool AbortFocuser() override;
83  virtual void TimerHit() override;
84  virtual bool saveConfigItems(FILE * fp) override;
85 
86  private:
87  bool Ack();
97  bool sendCommand(const char * cmd, char * res = nullptr, bool silent = false, int nret = 0);
98 
99  // Get initial focuser parameter when we first connect
100  void GetFocusParams();
101  // Read and update Step Mode
102  bool readStepMode();
103  // Read and update Temperature
104  bool readTemperature();
105  // Read and update Position
106  bool readPosition();
107  // Read and update speed
108  bool readSpeed();
109  // Read version
110  bool readVersion();
111  // Are we moving?
112  bool isMoving();
113 
114  bool MoveFocuser(uint32_t position);
115  bool setStepMode(FocusStepMode mode);
116  bool setSpeed(int speed);
117  bool setTemperatureCalibration(double calibration);
118  bool setTemperatureCoefficient(double coefficient);
119  bool setTemperatureCompensation(bool enable);
120  void timedMoveCallback();
121 
122  uint32_t targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 };
123 
124  // Read Only Temperature Reporting
125  INumber TemperatureN[1];
126  INumberVectorProperty TemperatureNP;
127 
128  // Full/Half Step modes
129  ISwitch StepModeS[2];
130  ISwitchVectorProperty StepModeSP;
131 
132  // Temperature Settings
133  INumber TemperatureSettingN[2];
134  INumberVectorProperty TemperatureSettingNP;
135 
136  // Temperature Compensation Enable/Disable
137  ISwitch TemperatureCompensateS[2];
138  ISwitchVectorProperty TemperatureCompensateSP;
139 
140  // MoonLite Buffer
141  static const uint8_t ML_RES { 32 };
142  // MoonLite Delimeter
143  static const char ML_DEL { '#' };
144  // MoonLite Tiemout
145  static const uint8_t ML_TIMEOUT { 3 };
146 };
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
MoonLite
Definition: moonlite.h:27
IPState
IPState
Property state.
Definition: indiapi.h:158
ISwitch
One switch descriptor.
MoonLite::SetFocuserSpeed
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: moonlite.cpp:435
INumber
One number descriptor.
indifocuser.h
MoonLite::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: moonlite.cpp:503
MoonLite::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: moonlite.cpp:91
MoonLite::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: moonlite.cpp:43
MoonLite::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveRelFocuser Move focuser for a relative amount of ticks in a specific direction.
Definition: moonlite.cpp:486
MoonLite::MoonLite
MoonLite()
Definition: moonlite.cpp:34
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
MoonLite::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveAbsFocuser Move to an absolute target position.
Definition: moonlite.cpp:476
MoonLite::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: moonlite.cpp:335
MoonLite::timedMoveHelper
static void timedMoveHelper(void *context)
Definition: moonlite.cpp:459
MoonLite::FOCUS_HALF_STEP
@ FOCUS_HALF_STEP
Definition: moonlite.h:33
MoonLite::Handshake
virtual bool Handshake() override
Handshake Try to communicate with Focuser and see if there is a valid response.
Definition: moonlite.cpp:117
MoonLite::getDefaultName
const char * getDefaultName() override
Definition: moonlite.cpp:130
MoonLite::FocusStepMode
FocusStepMode
Definition: moonlite.h:33
name
const char * name
Definition: indiserver.c:116
MoonLite::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set the supplied position as the current focuser position.
Definition: moonlite.cpp:291
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
MoonLite::FOCUS_FULL_STEP
@ FOCUS_FULL_STEP
Definition: moonlite.h:33
MoonLite::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: moonlite.cpp:549
MoonLite::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: moonlite.cpp:440
ISState
ISState
Switch state.
Definition: indiapi.h:148
INDI::Focuser
Definition: indifocuser.h:43
MoonLite::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: moonlite.cpp:395
MoonLite::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: moonlite.cpp:544
MoonLite::~MoonLite
virtual ~MoonLite() override=default
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365