Instrument Neutral Distributed Interface INDI 2.2.5
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
27static 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
74
78void GIOTTO::ISGetProperties(const char *dev)
79{
81
82 // Get Light box properties
84}
85
90{
91 m_GIOTTO->setLightEnabled(false);
93}
94
99{
100 PortFD = serialConnection->getPortFD();
101 m_GIOTTO.reset(new PrimalucaLabs::GIOTTO(getDeviceName(), PortFD));
102 uint16_t max = 0;
103 if (m_GIOTTO->getMaxBrightness(max))
104 {
105 LightIntensityNP[0].setMax(max);
106 LOGF_INFO("%s is online.", getDeviceName());
107
108 uint16_t value = 0;
109 if (m_GIOTTO->getBrightness(value))
110 LightIntensityNP[0].setValue(value);
111
112 auto lightEnabled = m_GIOTTO->isLightEnabled();
113 LightSP[0].setState(lightEnabled ? ISS_ON : ISS_OFF);
114 LightSP[1].setState(lightEnabled ? ISS_OFF : ISS_ON);
115
116 return true;
117 }
118
119 LOG_INFO("Error retrieving data from device, please ensure GIOTTO is powered and the port is correct.");
120 return false;
121}
122
123
128{
129 return "GIOTTO";
130}
131
135bool GIOTTO::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
136{
137 if (LI::processNumber(dev, name, values, names, n))
138 return true;
139
140 return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n);
141}
142
146bool GIOTTO::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
147{
148 if (LI::processText(dev, name, texts, names, n))
149 return true;
150
151 return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n);
152}
153
157bool GIOTTO::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
158{
159 if (LI::processSwitch(dev, name, states, names, n))
160 return true;
161
162 return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n);
163}
164
169{
170 LI::snoop(root);
171
173}
174
179{
180 return m_GIOTTO->setBrightness(value);
181}
182
186bool GIOTTO::EnableLightBox(bool enable)
187{
188 return m_GIOTTO->setLightEnabled(enable);
189}
190
195{
197
198 return LI::saveConfigItems(fp);
199}
void registerHandshake(std::function< bool()> callback)
registerHandshake Register a handshake function to be called once the initial connection to the devic...
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...
virtual bool initProperties() override
Initialize 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 implemented in the child class, if supported.
Definition giotto.cpp:178
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:135
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:168
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:78
virtual bool EnableLightBox(bool enable) override
EnableLightBox Turn on/off on a light box. Must be implemented in the child class.
Definition giotto.cpp:186
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:194
const char * getDefaultName() override
Definition giotto.cpp:127
bool Disconnect() override
Disconnect from device.
Definition giotto.cpp:89
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override
Process the client newSwitch command.
Definition giotto.cpp:146
bool Handshake()
Definition giotto.cpp:98
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:157
bool isConnected() const
const char * getDeviceName() const
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 setDriverInterface(uint32_t value)
setInterface Set driver interface. By default the driver interface is set to GENERAL_DEVICE....
void setVersion(uint16_t vMajor, uint16_t vMinor)
Set driver version information to be defined in DRIVER_INFO property as vMajor.vMinor.
virtual bool saveConfigItems(FILE *fp)
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
virtual bool initProperties()
Initialize 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.
virtual bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process the client newSwitch command.
void initProperties(const char *group, uint32_t capabilities)
Initialize light box properties. It is recommended to call this function within initProperties() of y...
void ISGetProperties(const char *deviceName)
isGetLightBoxProperties Get light box properties
INDI::PropertyNumber LightIntensityNP
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process light box switch properties.
bool processText(const char *dev, const char *name, char *texts[], char *names[], int n)
Process light box text properties.
bool processNumber(const char *dev, const char *name, double values[], char *names[], int n)
Process light box number properties.
void setState(IPState state)
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:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_INFO(txt)
Definition indilogger.h:74