Instrument Neutral Distributed Interface INDI  1.9.5
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 { return (state == Idle); }
79  bool SFisMoving() const { return !SFisIdle(); }
80  Position SFgetPosition();
81  Flags SFgetFlags();
82  void SFgetState();
83 
84  bool send(const char *command, const size_t nbytes, const char *from, const bool log_error = true);
85  bool recv(char *respons, const size_t nbytes, const char *from, const bool log_error = true);
86 
87  Position position { 0 };
88  State state { Idle };
89  int timer_id { 0 };
90 
91  ILight FlagsL[5];
92  ILightVectorProperty FlagsLP;
93  INumber MotionErrorN[1];
94  INumberVectorProperty MotionErrorNP;
95 };
SmartFocus::saveConfigItems
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Saves the Device Port and Focuser Presets in the configuration file
Definition: smartfocus.cpp:273
IPState
IPState
Property state.
Definition: indiapi.h:158
SmartFocus::TimerHit
virtual void TimerHit() override
Callback function to be called once SetTimer duration elapses.
Definition: smartfocus.cpp:245
SmartFocus::ISNewNumber
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
_ILightVectorProperty
Light vector property descriptor.
Definition: indiapi.h:415
SmartFocus::MoveRelFocuser
virtual IPState MoveRelFocuser(FocusDirection dir, uint32_t ticks) override
MoveFocuser the focuser to an relative position.
Definition: smartfocus.cpp:214
INumber
One number descriptor.
SmartFocus::AbortFocuser
virtual bool AbortFocuser() override
AbortFocuser all focus motion.
Definition: smartfocus.cpp:152
indifocuser.h
ILight
One light descriptor.
_INumberVectorProperty
Number vector property descriptor.
Definition: indiapi.h:317
SmartFocus::SmartFocus
SmartFocus()
Definition: smartfocus.cpp:52
SmartFocus::initProperties
bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: smartfocus.cpp:57
SmartFocus::Position
unsigned short Position
Definition: smartfocus.h:59
name
const char * name
Definition: indiserver.c:116
SmartFocus::getDefaultName
const char * getDefaultName() override
Definition: smartfocus.cpp:128
INDI::FocuserInterface::FocusDirection
FocusDirection
Definition: indifocuserinterface.h:66
SmartFocus::updateProperties
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: smartfocus.cpp:94
State
State
Definition: lilxml.c:72
INDI::Focuser
Definition: indifocuser.h:43
SmartFocus
Definition: smartfocus.h:23
SmartFocus::Handshake
virtual bool Handshake() override
perform handshake with device to check communication
Definition: smartfocus.cpp:113
SmartFocus::MoveAbsFocuser
virtual IPState MoveAbsFocuser(uint32_t targetPosition) override
MoveFocuser the focuser to an absolute position.
Definition: smartfocus.cpp:164