Instrument Neutral Distributed Interface INDI  2.0.2
nfocus.h
Go to the documentation of this file.
1 /*
2  NFocus DC Relative Focuser
3 
4  Copyright (C) 2019 Jasem Mutlaq (mutlaqja@ikarustech.com)
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) any later version.
10 
11  This library is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  Lesser General Public License for more details.
15 
16  You should have received a copy of the GNU Lesser General Public
17  License along with this library; if not, write to the Free Software
18  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 
20 */
21 
22 #pragma once
23 
24 #include "indifocuser.h"
25 
46 class NFocus : public INDI::Focuser
47 {
48  public:
49  NFocus();
50 
51  virtual bool Handshake() override;
52  const char *getDefaultName() override;
53  virtual bool initProperties() override;
54  virtual bool updateProperties() override;
55  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
56 
57  protected:
58  virtual void TimerHit() override;
59  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
60  virtual bool AbortFocuser() override;
61 
62  bool saveConfigItems(FILE *fp) override;
63 
64  private:
65  bool readTemperature();
66  bool readMotorSettings();
67  bool setMotorSettings(double onTime, double offTime, double fastDelay);
68 
69  // Utility
70  bool sendCommand(const char * cmd, char * res = nullptr, int cmd_len = -1, int res_len = -1);
71  bool getStartupValues();
72  void hexDump(char * buf, const char * data, int size);
73  bool isMoving();
74 
78  INumber TemperatureN[1];
79  INumberVectorProperty TemperatureNP;
80 
81  INumber SettingsN[3];
82  INumberVectorProperty SettingsNP;
83  enum
84  {
85  SETTING_ON_TIME,
86  SETTING_OFF_TIME,
87  SETTING_MODE_DELAY,
88  };
89 
93  uint16_t m_TargetPosition { 0 };
94  uint16_t m_TemperatureCounter { 0 };
95 
99  static constexpr const char * SETTINGS_TAB = "Settings";
100  // '#' is the stop char
101  static const char NFOCUS_STOP_CHAR { 0x23 };
102  // Update temperature every 10x POLLMS. For 500ms, we would
103  // update the temperature one every 5 seconds.
104  static constexpr const uint8_t NFOCUS_TEMPERATURE_FREQ {10};
105  // Wait up to a maximum of 3 seconds for serial input
106  static constexpr const uint8_t NFOCUS_TIMEOUT {3};
107  // Maximum buffer for sending/receving.
108  static constexpr const uint8_t NFOCUS_LEN {64};
109 };
The NFocus class Handles communication and control with nFocus DC focuser.
Definition: nfocus.h:47
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: nfocus.cpp:229
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: nfocus.cpp:307
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: nfocus.cpp:314
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: nfocus.cpp:319
virtual bool Handshake() override
perform handshake with device to check communication
Definition: nfocus.cpp:92
bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: nfocus.cpp:377
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: nfocus.cpp:38
const char * getDefaultName() override
Definition: nfocus.cpp:87
NFocus()
Definition: nfocus.cpp:32
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: nfocus.cpp:65
IPState
Property state.
Definition: indiapi.h:160
__u8 cmd[4]
Definition: pwc-ioctl.h:2
One number descriptor.
Number vector property descriptor.
Definition: indiapi.h:319