Instrument Neutral Distributed Interface INDI  2.0.2
microtouch.h
Go to the documentation of this file.
1 /*
2  Microtouch Focuser
3  Copyright (C) 2016 Marco Peters (mpeters@rzpeters.de)
4  Copyright (C) 2013 Jasem Mutlaq (mutlaqja@ikarustech.com)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 */
21 
22 #pragma once
23 
24 #include "indifocuser.h"
25 
26 #define CMD_GET_STATUS 0x80
27 #define CMD_RESET_POSITION 0x81
28 #define CMD_IS_MOVING 0x82
29 #define CMD_HALT 0x83
30 #define CMD_GET_TEMPERATURE 0x84
31 #define CMD_SET_COEFF 0x85
32 #define CMD_GET_COEFF 0x86
33 #define CMD_TEMPCOMP_ON 0x87
34 #define CMD_TEMPCOMP_OFF 0x88
35 #define CMD_UPDATE_POSITION 0x8c
36 #define CMD_GET_POSITION 0x8d
37 #define CMD_SET_MOTOR_SPEED 0x9d
38 #define CMD_GET_MOTOR_SPEED 0x9e
39 #define CMD_SET_TEMP_OFFSET 0x9f
40 
41 #define FOCUS_MOTORSPEED_NORMAL 8
42 #define FOCUS_MOTORSPEED_FAST 4
43 
44 class Microtouch : public INDI::Focuser
45 {
46  public:
47  Microtouch();
48  virtual ~Microtouch() override = default;
49 
50  virtual bool Handshake() override;
51  const char *getDefaultName() override;
52  virtual bool initProperties() override;
53  virtual bool updateProperties() override;
54  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
55  virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override;
56  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
57  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
58  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
59  virtual bool SetFocuserSpeed(int speed) override;
60  virtual bool SyncFocuser(uint32_t ticks) override;
61  virtual bool AbortFocuser() override;
62  virtual void TimerHit() override;
63 
64  private:
65  void GetFocusParams();
66  // bool reset();
67  // bool reset(double pos);
68  bool updateMotorSpeed();
69  bool updateTemperature();
70  bool updatePosition();
71  bool updateSpeed();
72  bool isMoving();
73  bool Ack();
74 
75  bool MoveFocuser(unsigned int position);
76  bool setMotorSpeed(char speed);
77  bool setSpeed(unsigned short speed);
78  bool setTemperatureCalibration(double calibration);
79  bool setTemperatureCoefficient(double coefficient);
80  bool setTemperatureCompensation(bool enable);
81  float CalcTimeLeft(timeval, float);
82  bool WriteCmd(char cmd);
83  bool WriteCmdGetResponse(char cmd, char *readbuffer, char numbytes);
84  char WriteCmdGetByte(char cmd);
85  bool WriteCmdSetByte(char cmd, char val);
86  bool WriteCmdSetShortInt(char cmd, short int val);
87  int WriteCmdGetInt(char cmd);
88  bool WriteCmdSetInt(char cmd, int val);
89  bool WriteCmdSetIntAsDigits(char cmd, int val);
90 
91  double targetPos { 0 };
92  double lastPos { 0 };
93  double lastTemperature { 0 };
94  unsigned int currentSpeed { 0 };
95 
96  struct timeval focusMoveStart
97  {
98  0, 0
99  };
100  float focusMoveRequest { 0 };
101 
102  INumber TemperatureN[1];
103  INumberVectorProperty TemperatureNP;
104 
105  ISwitch MotorSpeedS[2];
106  ISwitchVectorProperty MotorSpeedSP;
107 
108  // INumber MaxTravelN[1];
109  // INumberVectorProperty MaxTravelNP;
110 
111  INumber TemperatureSettingN[2];
112  INumberVectorProperty TemperatureSettingNP;
113 
114  ISwitch TemperatureCompensateS[2];
115  ISwitchVectorProperty TemperatureCompensateSP;
116 
117  // ISwitch ResetS[1];
118  // ISwitchVectorProperty ResetSP;
119 
120  // INumber ResetToPosN[1];
121  // INumberVectorProperty ResetToPosNP;
122 };
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: microtouch.cpp:556
virtual bool Handshake() override
perform handshake with device to check communication
Definition: microtouch.cpp:138
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: microtouch.cpp:651
virtual ~Microtouch() override=default
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: microtouch.cpp:448
const char * getDefaultName() override
Definition: microtouch.cpp:153
virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override
MoveFocuser the focuser in a particular direction with a specific speed for a finite duration.
Definition: microtouch.cpp:528
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: microtouch.cpp:371
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: microtouch.cpp:511
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: microtouch.cpp:572
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: microtouch.cpp:106
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: microtouch.cpp:44
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: microtouch.cpp:305
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: microtouch.cpp:593
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