Instrument Neutral Distributed Interface INDI 2.2.5
dust_cover_simulator.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Dust Cover Simulator
3
4 SPDX-FileCopyrightText: 2025 Jasem Mutlaq
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*******************************************************************************/
7
10
11#include <memory>
12
13static std::unique_ptr<DustCoverSimulator> simulator(new DustCoverSimulator());
14
19
21{
23
24 // Initialize the dust cap interface
26
27 // Set the driver interface
29
30 // Operation duration property
31 OperationDurationNP[0].fill("DURATION", "Duration (s)", "%.1f", 1, 60, 1, 5);
32 OperationDurationNP.fill(getDeviceName(), "OPERATION_DURATION", "Operation", MAIN_CONTROL_TAB, IP_RW, 0, IPS_IDLE);
33
35
36 return true;
37}
38
40{
42
43 if (isConnected())
44 {
48 defineProperty(OperationDurationNP);
49 }
50 else
51 {
52 deleteProperty(OperationDurationNP);
53 }
54
56
57 return true;
58}
59
60bool DustCoverSimulator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
61{
62 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
63 {
64 // Operation Duration
65 if (OperationDurationNP.isNameMatch(name))
66 {
67 OperationDurationNP.update(values, names, n);
68 OperationDurationNP.setState(IPS_OK);
69 OperationDurationNP.apply();
70 return true;
71 }
72 }
73
74 return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n);
75}
76
77bool DustCoverSimulator::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
78{
79 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
80 {
81 if (DI::processSwitch(dev, name, states, names, n))
82 return true;
83 }
84
85 return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n);
86}
87
89{
91
92 OperationDurationNP.save(fp);
93
94 return true;
95}
96
98{
100 {
101 LOG_WARN("Dust cover is already in motion.");
102 return IPS_BUSY;
103 }
104
105 // Set the timer to simulate the dust cover movement
106 double duration = OperationDurationNP[0].getValue();
107 LOGF_INFO("Parking dust cover. This will take %.1f seconds.", duration);
108
109 // Use INDI::Timer for the timer
110 INDI::Timer::singleShot(duration * 1000, [this]()
111 {
112 LOG_INFO("Dust cover parked successfully.");
115 });
116
117 return IPS_BUSY;
118}
119
121{
122 if (ParkCapSP.getState() == IPS_BUSY)
123 {
124 LOG_WARN("Dust cover is already in motion.");
125 return IPS_BUSY;
126 }
127
128 // Set the timer to simulate the dust cover movement
129 double duration = OperationDurationNP[0].getValue();
130 LOGF_INFO("Unparking dust cover. This will take %.1f seconds.", duration);
131
132 // Use INDI::Timer for the timer
133 INDI::Timer::singleShot(duration * 1000, [this]()
134 {
135 LOG_INFO("Dust cover unparked successfully.");
138 });
139
140 return IPS_BUSY;
141}
Provides interface to implement remotely controlled dust cover.
bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override
Process the client newSwitch command.
bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual IPState ParkCap() override
Park dust cap (close cover). Must be implemented by child.
virtual IPState UnParkCap() override
unPark dust cap (open cover). Must be implemented by child.
bool saveConfigItems(FILE *fp) override
saveConfigItems Save specific properties in the provide config file handler. Child class usually over...
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.
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 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()
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.
INDI::PropertySwitch ParkCapSP
bool updateProperties()
updateProperties Defines or Delete properties based on default device connection status
void initProperties(const char *group, uint32_t capabilities=0)
Initialize dust cap properties. It is recommended to call this function within initProperties() of yo...
bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n)
Process dust cap switch properties.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
void save(FILE *f) const
save Save property to configuration file.
bool isNameMatch(const char *otherName) const
bool update(const double values[], const char *const names[], int n)
void fill(const char *device, const char *name, const char *label, const char *group, IPerm permission, double timeout, IPState state)
static void singleShot(int msec, const std::function< void()> &callback)
This static function calls a the given function after a given time interval.
const char * MAIN_CONTROL_TAB
MAIN_CONTROL_TAB Where all the primary controls for the device are located.
ISState
Switch state.
Definition indiapi.h:148
@ ISS_OFF
Definition indiapi.h:149
@ ISS_ON
Definition indiapi.h:150
@ IP_RW
Definition indiapi.h:184
IPState
Property state.
Definition indiapi.h:158
@ IPS_BUSY
Definition indiapi.h:161
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
#define LOGF_INFO(fmt,...)
Definition indilogger.h:82
#define LOG_WARN(txt)
Definition indilogger.h:73
#define LOG_INFO(txt)
Definition indilogger.h:74