Instrument Neutral Distributed Interface INDI  2.0.2
fcusb.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
3 
4  Shoestring FCUSB Focuser
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Library General Public
8  License version 2 as published by the Free Software Foundation.
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  Library General Public License for more details.
14  .
15  You should have received a copy of the GNU Library General Public License
16  along with this library; see the file COPYING.LIB. If not, write to
17  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18  Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20 
21 #pragma once
22 
23 #include "indifocuser.h"
24 #include "hidapi.h"
25 
26 #include <map>
27 
28 class FCUSB : public INDI::Focuser
29 {
30  public:
31 
32  // Motor commands
33  typedef enum
34  {
35  MOTOR_OFF = 0x0,
36  MOTOR_REV = 0x1,
37  MOTOR_FWD = 0x2
39 
40  // PWM Freq Commands
41  typedef enum
42  {
43  PWM_1_1 = 0x0,
44  PWM_1_4 = 0x1,
45  PWM_1_16 = 0x2
47 
48  FCUSB();
49 
50  const char *getDefaultName() override;
51  virtual bool initProperties() override;
52  virtual bool updateProperties() override;
53  virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
54 
55  static void timedMoveHelper(void * context);
56 
57  protected:
58  virtual bool Connect() override;
59  virtual bool Disconnect() override;
60 
61  virtual void TimerHit() override;
62 
63  virtual bool SetFocuserSpeed(int speed) override;
64  virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
65  virtual bool AbortFocuser() override;
66  virtual bool ReverseFocuser(bool enabled) override;
67 
68  virtual bool saveConfigItems(FILE * fp) override;
69 
70  private:
71  // Gets the Motor, PWM, and LED states.
72  bool getStatus();
73 
74  // Sets the Motor, PWM, and LED states
75  bool setStatus();
76 
77  // Stop motor and set status as OK to signal motion is complete
78  bool stop();
79 
80  void timedMoveCallback();
81 
82  hid_device *handle { nullptr };
83 
84  uint8_t motorStatus { MOTOR_OFF };
85  uint8_t pwmStatus { PWM_1_1 };
86  int targetSpeed { 1 };
87  struct timeval timedMoveEnd;
88 
89  // PWM Scaler
90  ISwitchVectorProperty PWMScalerSP;
91  ISwitch PWMScalerS[3];
92 
93  // Driver Timeout in ms
94  static const uint16_t FC_TIMEOUT { 1000 };
95 
96  static const uint8_t FC_LED_RED { 0x10 };
97  static const uint8_t FC_LED_ON { 0x20 };
98 };
Definition: fcusb.h:29
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: fcusb.cpp:90
virtual bool Disconnect() override
Disconnect from device.
Definition: fcusb.cpp:74
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: fcusb.cpp:255
const char * getDefaultName() override
Definition: fcusb.cpp:85
PWMBits
Definition: fcusb.h:42
@ PWM_1_16
Definition: fcusb.h:45
@ PWM_1_1
Definition: fcusb.h:43
@ PWM_1_4
Definition: fcusb.h:44
MotorBits
Definition: fcusb.h:34
@ MOTOR_FWD
Definition: fcusb.h:37
@ MOTOR_REV
Definition: fcusb.h:36
@ MOTOR_OFF
Definition: fcusb.h:35
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: fcusb.cpp:125
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: fcusb.cpp:45
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: fcusb.cpp:311
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: fcusb.cpp:390
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: fcusb.cpp:381
static void timedMoveHelper(void *context)
Definition: fcusb.cpp:396
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: fcusb.cpp:154
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: fcusb.cpp:109
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: fcusb.cpp:322
FCUSB()
Definition: fcusb.cpp:37
ISState
Switch state.
Definition: indiapi.h:150
IPState
Property state.
Definition: indiapi.h:160
One switch descriptor.
Switch vector property descriptor.
Definition: indiapi.h:367