Instrument Neutral Distributed Interface INDI  2.0.2
giotto.cpp
Go to the documentation of this file.
1 /*
2  Giotto driver
3  Copyright (C) 2023 Jasem Mutlaq
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) any later version.
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  Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public
16  License along with this library; if not, write to the Free Software
17  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 
19 */
20 
21 #include "giotto.h"
22 
23 #include <memory>
24 #include <unistd.h>
26 
27 static std::unique_ptr<GIOTTO> sesto(new GIOTTO());
28 
30 {
31  setVersion(1, 0);
32 }
33 
35 {
36  if (isConnected())
37  Disconnect();
38 }
39 
44 {
45 
47 
49 
51 
53 
54  serialConnection = new Connection::Serial(this);
56  serialConnection->registerHandshake([&]()
57  {
58  return Handshake();
59  });
60  registerConnection(serialConnection);
61 
62  return true;
63 }
64 
69 {
71 
72  if (isConnected())
73  {
77  }
78  else
79  {
82  }
83 
84  return true;
85 }
86 
90 void GIOTTO::ISGetProperties(const char *dev)
91 {
93 
94  // Get Light box properties
96 }
97 
102 {
103  m_GIOTTO->setLightEnabled(false);
105 }
106 
111 {
112  PortFD = serialConnection->getPortFD();
113  m_GIOTTO.reset(new PrimalucaLabs::GIOTTO(getDeviceName(), PortFD));
114  uint16_t max = 0;
115  if (m_GIOTTO->getMaxBrightness(max))
116  {
117  LightIntensityNP.np[0].max = max;
118  LOGF_INFO("%s is online.", getDeviceName());
119 
120  uint16_t value = 0;
121  if (m_GIOTTO->getBrightness(value))
122  LightIntensityNP.np[0].value = value;
123 
124  auto lightEnabled = m_GIOTTO->isLightEnabled();
125  LightS[0].s = lightEnabled ? ISS_ON : ISS_OFF;
126  LightS[1].s = lightEnabled ? ISS_OFF : ISS_ON;
127 
128  return true;
129  }
130 
131  LOG_INFO("Error retrieving data from device, please ensure GIOTTO is powered and the port is correct.");
132  return false;
133 }
134 
135 
140 {
141  return "GIOTTO";
142 }
143 
147 bool GIOTTO::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
148 {
149  if (processLightBoxNumber(dev, name, values, names, n))
150  return true;
151 
152  return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n);
153 }
154 
158 bool GIOTTO::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
159 {
160  if (processLightBoxText(dev, name, texts, names, n))
161  return true;
162 
163  return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n);
164 }
165 
169 bool GIOTTO::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
170 {
171  if (processLightBoxSwitch(dev, name, states, names, n))
172  return true;
173 
174  return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n);
175 }
176 
181 {
182  snoopLightBox(root);
183 
185 }
186 
190 bool GIOTTO::SetLightBoxBrightness(uint16_t value)
191 {
192  return m_GIOTTO->setBrightness(value);
193 }
194 
198 bool GIOTTO::EnableLightBox(bool enable)
199 {
200  return m_GIOTTO->setLightEnabled(enable);
201 }
202 
207 {
209 
210  return saveLightBoxConfigItems(fp);
211 }
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the intial connection to the device...
The Serial class manages connection with serial devices including Bluetooth. Serial communication is ...
void setDefaultBaudRate(BaudRate newRate)
setDefaultBaudRate Set default baud rate. The default baud rate is 9600 unless otherwise changed by t...
Definition: giotto.h:28
virtual bool initProperties() override
Initilize properties initial state and value. The child class must implement this function.
Definition: giotto.cpp:43
virtual bool SetLightBoxBrightness(uint16_t value) override
setBrightness Set light level. Must be impelemented in the child class, if supported.
Definition: giotto.cpp:190
virtual ~GIOTTO()
Definition: giotto.cpp:34
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
Definition: giotto.cpp:147
virtual bool ISSnoopDevice(XMLEle *root) override
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
Definition: giotto.cpp:180
virtual void ISGetProperties(const char *dev) override
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
Definition: giotto.cpp:90
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be impelemented in the child class.
Definition: giotto.cpp:198
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
Definition: giotto.cpp:68
virtual bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
Definition: giotto.cpp:206
const char * getDefaultName() override
Definition: giotto.cpp:139
bool Disconnect() override
Disconnect from device.
Definition: giotto.cpp:101
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition: giotto.cpp:158
bool Handshake()
Definition: giotto.cpp:110
GIOTTO()
Definition: giotto.cpp:29
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
Definition: giotto.cpp:169
bool isConnected() const
Definition: basedevice.cpp:520
const char * getDeviceName() const
Definition: basedevice.cpp:821
virtual bool updateProperties()
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process the client newSwitch command.
virtual bool Disconnect()
Disconnect from device.
void registerConnection(Connection::Interface *newConnection)
registerConnection Add new connection plugin to the existing connection pool. The connection type sha...
virtual void ISGetProperties(const char *dev)
define the driver's properties to the client. Usually, only a minimum set of properties are defined t...
virtual bool ISSnoopDevice(XMLEle *root)
Process a snoop event from INDI server. This function is called when a snooped property is updated in...
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initilize properties initial state and value. The child class must implement this function.
void addAuxControls()
Add Debug, Simulation, and Configuration options to the driver.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process the client newNumber command.
void setDriverInterface(uint16_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
INumberVectorProperty LightIntensityNP
bool processLightBoxNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process light box number properties.
ISwitchVectorProperty LightSP
bool processLightBoxSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process light box switch properties.
void initLightBoxProperties(const char *deviceName, const char *groupNam)
Initilize light box properties. It is recommended to call this function within initProperties() of yo...
bool processLightBoxText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process light box text properties.
void isGetLightBoxProperties(const char *deviceName)
isGetLightBoxProperties Get light box properties
Provides interface to implement controllable light box/switch device.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
double max(void)
ISState
Switch state.
Definition: indiapi.h:150
@ ISS_OFF
Definition: indiapi.h:151
@ ISS_ON
Definition: indiapi.h:152
#define LOGF_INFO(fmt,...)
Definition: indilogger.h:82
#define LOG_INFO(txt)
Definition: indilogger.h:74
char name[MAXINDINAME]
Definition: indiapi.h:323
char name[MAXINDINAME]
Definition: indiapi.h:371