Instrument Neutral Distributed Interface INDI 2.2.5
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
25#ifdef _USE_SYSTEM_HIDAPILIB
26#include <hidapi/hidapi.h>
27#else
28#include <indi_hidapi.h>
29#endif
30
31
32#include <map>
33
34class FCUSB : public INDI::Focuser
35{
36 public:
37
38 // Motor commands
39 typedef enum
40 {
41 MOTOR_OFF = 0x0,
42 MOTOR_REV = 0x1,
43 MOTOR_FWD = 0x2
45
46 // PWM Freq Commands
47 typedef enum
48 {
49 PWM_1_1 = 0x0,
50 PWM_1_4 = 0x1,
51 PWM_1_16 = 0x2
53
54 FCUSB();
55
56 const char *getDefaultName() override;
57 virtual bool initProperties() override;
58 virtual bool updateProperties() override;
59 virtual bool ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) override;
60
61 static void timedMoveHelper(void * context);
62
63 protected:
64 virtual bool Connect() override;
65 virtual bool Disconnect() override;
66
67 virtual void TimerHit() override;
68
69 virtual bool SetFocuserSpeed(int speed) override;
70 virtual IPState MoveFocuser(FocusDirection dir, int speed, uint16_t duration) override;
71 virtual bool AbortFocuser() override;
72 virtual bool ReverseFocuser(bool enabled) override;
73
74 virtual bool saveConfigItems(FILE * fp) override;
75
76 private:
77 // Gets the Motor, PWM, and LED states.
78 bool getStatus();
79
80 // Sets the Motor, PWM, and LED states
81 bool setStatus();
82
83 // Stop motor and set status as OK to signal motion is complete
84 bool stop();
85
86 void timedMoveCallback();
87
88 hid_device *handle { nullptr };
89
90 uint8_t motorStatus { MOTOR_OFF };
91 uint8_t pwmStatus { PWM_1_1 };
92 int targetSpeed { 1 };
93 struct timeval timedMoveEnd;
94
95 // PWM Scaler
96 INDI::PropertySwitch PWMScalerSP {3};
97 // Driver Timeout in ms
98 static const uint16_t FC_TIMEOUT { 1000 };
99
100 static const uint8_t FC_LED_RED { 0x10 };
101 static const uint8_t FC_LED_ON { 0x20 };
102};
Definition fcusb.h:35
virtual bool initProperties() override
Initializes the default properties for the focuser device. Sets up standard INDI properties,...
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:256
const char * getDefaultName() override
Definition fcusb.cpp:85
PWMBits
Definition fcusb.h:48
@ PWM_1_16
Definition fcusb.h:51
@ PWM_1_1
Definition fcusb.h:49
@ PWM_1_4
Definition fcusb.h:50
MotorBits
Definition fcusb.h:40
@ MOTOR_FWD
Definition fcusb.h:43
@ MOTOR_REV
Definition fcusb.h:42
@ MOTOR_OFF
Definition fcusb.h:41
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:312
virtual bool ReverseFocuser(bool enabled) override
ReverseFocuser Reverse focuser motion direction.
Definition fcusb.cpp:391
virtual bool saveConfigItems(FILE *fp) override
Definition fcusb.cpp:382
static void timedMoveHelper(void *context)
Definition fcusb.cpp:397
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Processes incoming new switch states from the client for this device. Handles updates to FocuserInter...
Definition fcusb.cpp:154
virtual bool updateProperties() override
Updates the state and definition of properties based on the current connection status....
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:323
FCUSB()
Definition fcusb.cpp:37
ISState
Switch state.
Definition indiapi.h:148
IPState
Property state.
Definition indiapi.h:158