Instrument Neutral Distributed Interface INDI  1.9.5
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 { 0, 0 };
97  float focusMoveRequest { 0 };
98 
99  INumber TemperatureN[1];
100  INumberVectorProperty TemperatureNP;
101 
102  ISwitch MotorSpeedS[2];
103  ISwitchVectorProperty MotorSpeedSP;
104 
105 // INumber MaxTravelN[1];
106 // INumberVectorProperty MaxTravelNP;
107 
108  INumber TemperatureSettingN[2];
109  INumberVectorProperty TemperatureSettingNP;
110 
111  ISwitch TemperatureCompensateS[2];
112  ISwitchVectorProperty TemperatureCompensateSP;
113 
114 // ISwitch ResetS[1];
115 // ISwitchVectorProperty ResetSP;
116 
117 // INumber ResetToPosN[1];
118 // INumberVectorProperty ResetToPosNP;
119 };
Microtouch::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: microtouch.cpp:305
cmd
__u8 cmd[4]
Definition: pwc-ioctl.h:4
IPState
IPState
Property state.
Definition: indiapi.h:158
ISwitch
One switch descriptor.
INumber
One number descriptor.
Microtouch::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: microtouch.cpp:650
indifocuser.h
Microtouch::ISNewNumber
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: microtouch.cpp:447
Microtouch
Definition: microtouch.h:44
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
Microtouch::SetFocuserSpeed
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: microtouch.cpp:510
Microtouch::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: microtouch.cpp:44
Microtouch::MoveFocuser
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:527
Microtouch::~Microtouch
virtual ~Microtouch() override=default
Microtouch::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: microtouch.cpp:138
Microtouch::Microtouch
Microtouch()
Definition: microtouch.cpp:37
Microtouch::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: microtouch.cpp:555
name
const char * name
Definition: indiserver.c:116
Microtouch::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: microtouch.cpp:592
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
ISState
ISState
Switch state.
Definition: indiapi.h:148
Microtouch::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: microtouch.cpp:571
INDI::Focuser
Definition: indifocuser.h:43
Microtouch::getDefaultName
const char * getDefaultName() override
Definition: microtouch.cpp:153
Microtouch::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: microtouch.cpp:106
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365
Microtouch::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: microtouch.cpp:370