Instrument Neutral Distributed Interface INDI  1.9.2
si_efs.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2019 Jasem Mutlaq. All rights reserved.
3 
4  Starlight Instruments EFS 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 SIEFS : public INDI::Focuser
29 {
30  public:
31 
32  // SI EFS State
33  typedef enum { SI_NOOP,
34  SI_IN,
35  SI_OUT,
36  SI_GOTO,
37  SI_SET_POS,
38  SI_MAX_POS,
39  SI_FAST_IN = 0x11,
40  SI_FAST_OUT = 0x12,
41  SI_HALT = 0xFF
42  } SI_COMMANDS;
43 
44 
45  // SI EFS Motor State
46  typedef enum { SI_NOT_MOVING,
49  SI_LOCKED = 5,
50  } SI_MOTOR;
51 
52 
53  SIEFS();
54 
55  const char *getDefaultName() override;
56  virtual bool initProperties() override;
57 
58  virtual bool Connect() override;
59  virtual bool Disconnect() override;
60 
61  virtual void TimerHit() override;
62 
63  virtual IPState MoveAbsFocuser(uint32_t targetTicks) override;
64  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
65  virtual bool AbortFocuser() override;
66  virtual bool SyncFocuser(uint32_t ticks) override;
67  virtual bool SetFocuserMaxPosition(uint32_t ticks) override;
68 
69  private:
76  bool setPosition(uint32_t ticks, uint8_t cmdCode);
77 
84  bool getPosition(uint32_t *ticks, uint8_t cmdCode);
85 
86  // Set/Get Absolute Position
87  bool setAbsPosition(uint32_t ticks);
88  bool getAbsPosition(uint32_t *ticks);
89 
90  // Set/Get Maximum Position
91  bool setMaxPosition(uint32_t ticks);
92  bool getMaxPosition(uint32_t *ticks);
93 
94  bool sendCommand(SI_COMMANDS targetCommand);
95  bool getStatus();
96 
97  hid_device *handle { nullptr };
98  SI_MOTOR m_Motor { SI_NOT_MOVING };
99  int32_t simPosition { 0 };
100  uint32_t targetPosition { 0 };
101 
102  // Driver Timeout in ms
103  static const uint16_t SI_TIMEOUT { 1000 };
104 
105  static const std::map<SI_COMMANDS, std::string> CommandsMap;
106  static const std::map<SI_MOTOR, std::string> MotorMap;
107 };
SIEFS::SI_FAST_OUT
@ SI_FAST_OUT
Definition: si_efs.h:76
IPState
IPState
Property state.
Definition: indiapi.h:158
hidapi.h
SIEFS::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: si_efs.cpp:127
SIEFS::SI_NOOP
@ SI_NOOP
Definition: si_efs.h:69
indifocuser.h
SIEFS::SI_HALT
@ SI_HALT
Definition: si_efs.h:77
SIEFS::SI_MAX_POS
@ SI_MAX_POS
Definition: si_efs.h:74
hid_device_
Definition: hid_libusb.c:93
SIEFS::SI_GOTO
@ SI_GOTO
Definition: si_efs.h:72
SIEFS::Connect
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: si_efs.cpp:60
SIEFS::SI_LOCKED
@ SI_LOCKED
Definition: si_efs.h:67
SIEFS::getDefaultName
const char * getDefaultName() override
Definition: si_efs.cpp:113
SIEFS::SI_FAST_IN
@ SI_FAST_IN
Definition: si_efs.h:75
SIEFS::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: si_efs.cpp:178
SIEFS::SIEFS
SIEFS()
Definition: si_efs.cpp:52
SIEFS
Definition: si_efs.h:28
SIEFS::SI_MOVING_OUT
@ SI_MOVING_OUT
Definition: si_efs.h:66
SIEFS::SI_SET_POS
@ SI_SET_POS
Definition: si_efs.h:73
SIEFS::SetFocuserMaxPosition
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
Definition: si_efs.cpp:531
SIEFS::SI_COMMANDS
SI_COMMANDS
Definition: si_efs.h:51
SIEFS::SI_IN
@ SI_IN
Definition: si_efs.h:70
SIEFS::SI_NOT_MOVING
@ SI_NOT_MOVING
Definition: si_efs.h:64
SIEFS::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: si_efs.cpp:512
SIEFS::SyncFocuser
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: si_efs.cpp:517
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
SIEFS::SI_MOTOR
SI_MOTOR
Definition: si_efs.h:64
SIEFS::Disconnect
virtual bool Disconnect() override
Disconnect from device.
Definition: si_efs.cpp:102
SIEFS::SI_MOVING_IN
@ SI_MOVING_IN
Definition: si_efs.h:65
SIEFS::initProperties
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: si_efs.cpp:118
INDI::Focuser
Definition: indifocuser.h:43
SIEFS::SI_OUT
@ SI_OUT
Definition: si_efs.h:71
SIEFS::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: si_efs.cpp:197