Instrument Neutral Distributed Interface INDI  1.9.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
38  } MotorBits;
39 
40  // PWM Freq Commands
41  typedef enum
42  {
43  PWM_1_1 = 0x0,
44  PWM_1_4 = 0x1,
45  PWM_1_16 = 0x2
46  } PWMBits;
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 };
FCUSB::FCUSB
FCUSB()
Definition: fcusb.cpp:31
FCUSB::getDefaultName
const char * getDefaultName() override
Definition: fcusb.cpp:78
IPState
IPState
Property state.
Definition: indiapi.h:158
FCUSB::PWM_1_4
@ PWM_1_4
Definition: fcusb.h:62
ISwitch
One switch descriptor.
hidapi.h
FCUSB::timedMoveHelper
static void timedMoveHelper(void *context)
Definition: fcusb.cpp:388
FCUSB::ReverseFocuser
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition: fcusb.cpp:382
indifocuser.h
hid_device_
Definition: hid_libusb.c:93
FCUSB
Definition: fcusb.h:28
FCUSB::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: fcusb.cpp:314
FCUSB::Disconnect
virtual bool Disconnect() override
Disconnect from device.
Definition: fcusb.cpp:67
FCUSB::MOTOR_FWD
@ MOTOR_FWD
Definition: fcusb.h:73
FCUSB::MOTOR_OFF
@ MOTOR_OFF
Definition: fcusb.h:71
FCUSB::PWMBits
PWMBits
Definition: fcusb.h:59
FCUSB::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: fcusb.cpp:83
FCUSB::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: fcusb.cpp:373
FCUSB::updateProperties
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: fcusb.cpp:101
FCUSB::MOTOR_REV
@ MOTOR_REV
Definition: fcusb.h:72
FCUSB::PWM_1_16
@ PWM_1_16
Definition: fcusb.h:63
FCUSB::ISNewSwitch
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: fcusb.cpp:146
FCUSB::PWM_1_1
@ PWM_1_1
Definition: fcusb.h:61
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
ISState
ISState
Switch state.
Definition: indiapi.h:148
FCUSB::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: fcusb.cpp:117
FCUSB::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: fcusb.cpp:247
INDI::Focuser
Definition: indifocuser.h:43
FCUSB::MotorBits
MotorBits
Definition: fcusb.h:51
FCUSB::SetFocuserSpeed
virtual bool SetFocuserSpeed(int speed) override
SetFocuserSpeed Set Focuser speed.
Definition: fcusb.cpp:303
FCUSB::Connect
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: fcusb.cpp:39
_ISwitchVectorProperty
Switch vector property descriptor.
Definition: indiapi.h:365