Instrument Neutral Distributed Interface INDI  2.0.2
smartfocus.h
Go to the documentation of this file.
1 /*******************************************************************************
2  Copyright(c) 2015,2020 Camiel Severijns. All rights reserved.
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License version 2 as published by the Free Software Foundation.
7  .
8  This library is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11  Library General Public License for more details.
12  .
13  You should have received a copy of the GNU Library General Public License
14  along with this library; see the file COPYING.LIB. If not, write to
15  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
16  Boston, MA 02110-1301, USA.
17 *******************************************************************************/
18 
19 #pragma once
20 
21 #include "indifocuser.h"
22 
23 class SmartFocus : public INDI::Focuser
24 {
25  public:
26  SmartFocus();
27 
28  const char *getDefaultName() override;
29 
30  bool initProperties() override;
31  bool updateProperties() override;
32 
33  virtual bool Handshake() override;
34 
35  virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override;
36  //virtual bool ISNewSwitch (const char *dev, const char *name, ISState *states, char *names[], int n) override;
37 
38  virtual bool AbortFocuser() override;
39  virtual IPState MoveAbsFocuser(uint32_t targetPosition) override;
40  virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override;
41  virtual void TimerHit() override;
42 
43  typedef unsigned short Position;
44  protected:
45  virtual bool saveConfigItems(FILE *fp) override;
46 
47  private:
48  typedef unsigned char Flags;
49 
50  enum State
51  {
52  Idle,
53  MovingTo,
54  MovingIn,
55  MovingOut
56  };
57 
58  enum StatusFlags
59  {
60  STATUS_SERIAL_FRAMING_ERROR = 0,
61  STATUS_SERIAL_OVERRUN_ERROR,
62  STATUS_MOTOR_ENCODE_ERROR,
63  STATUS_AT_ZERO_POSITION,
64  STATUS_AT_MAX_POSITION,
65  STATUS_NUM_FLAGS
66  };
67 
68  enum FlagBits
69  {
70  SerFramingError = 0x02,
71  SerOverrunError = 0x04,
72  MotorEncoderError = 0x08,
73  AtZeroPosition = 0x40,
74  AtMaxPosition = 0x80
75  };
76 
77  bool SFacknowledge();
78  bool SFisIdle() const
79  {
80  return (state == Idle);
81  }
82  bool SFisMoving() const
83  {
84  return !SFisIdle();
85  }
86  Position SFgetPosition();
87  Flags SFgetFlags();
88  void SFgetState();
89 
90  bool send(const char *command, const size_t nbytes, const char *from, const bool log_error = true);
91  bool recv(char *respons, const size_t nbytes, const char *from, const bool log_error = true);
92 
93  Position position { 0 };
94  State state { Idle };
95  int timer_id { 0 };
96 
97  ILight FlagsL[5];
98  ILightVectorProperty FlagsLP;
99  INumber MotionErrorN[1];
100  INumberVectorProperty MotionErrorNP;
101 };
virtual bool Handshake() override
perform handshake with device to check communication
Definition: smartfocus.cpp:113
const char * getDefaultName() override
Definition: smartfocus.cpp:128
virtual IPState MoveAbsFocuser(uint32_t targetPosition) override
MoveFocuser the focuser to an absolute position.
Definition: smartfocus.cpp:164
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: smartfocus.cpp:57
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: smartfocus.cpp:152
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: smartfocus.cpp:214
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: smartfocus.cpp:273
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: smartfocus.cpp:245
unsigned short Position
Definition: smartfocus.h:43
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: smartfocus.cpp:94
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: smartfocus.cpp:133
IPState
Property state.
Definition: indiapi.h:160
State
Definition: lilxml.cpp:74
One light descriptor.
One number descriptor.
Light vector property descriptor.
Definition: indiapi.h:417
Number vector property descriptor.
Definition: indiapi.h:319