Instrument Neutral Distributed Interface INDI  2.0.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,
39  SI_FAST_IN = 0x11,
40  SI_FAST_OUT = 0x12,
41  SI_HALT = 0xFF
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 };
Definition: si_efs.h:29
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: si_efs.cpp:127
virtual IPState MoveAbsFocuser(uint32_t targetTicks) override
MoveFocuser the focuser to an absolute position.
Definition: si_efs.cpp:178
virtual bool SetFocuserMaxPosition(uint32_t ticks) override
SetFocuserMaxPosition Update focuser maximum position. It only updates the PresetNP property limits.
Definition: si_efs.cpp:531
SI_COMMANDS
Definition: si_efs.h:33
@ SI_NOOP
Definition: si_efs.h:33
@ SI_FAST_OUT
Definition: si_efs.h:40
@ SI_OUT
Definition: si_efs.h:35
@ SI_FAST_IN
Definition: si_efs.h:39
@ SI_HALT
Definition: si_efs.h:41
@ SI_SET_POS
Definition: si_efs.h:37
@ SI_IN
Definition: si_efs.h:34
@ SI_MAX_POS
Definition: si_efs.h:38
@ SI_GOTO
Definition: si_efs.h:36
virtual bool SyncFocuser(uint32_t ticks) override
SyncFocuser Set current position to ticks without moving the focuser.
Definition: si_efs.cpp:517
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: si_efs.cpp:512
SIEFS()
Definition: si_efs.cpp:52
virtual bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
Definition: si_efs.cpp:60
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: si_efs.cpp:118
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: si_efs.cpp:197
virtual bool Disconnect() override
Disconnect from device.
Definition: si_efs.cpp:102
SI_MOTOR
Definition: si_efs.h:46
@ SI_MOVING_IN
Definition: si_efs.h:47
@ SI_MOVING_OUT
Definition: si_efs.h:48
@ SI_NOT_MOVING
Definition: si_efs.h:46
@ SI_LOCKED
Definition: si_efs.h:49
const char * getDefaultName() override
Definition: si_efs.cpp:113
IPState
Property state.
Definition: indiapi.h:160