Instrument Neutral Distributed Interface INDI 2.2.5
filter_simulator.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 Copyright(c) 2010 Gerry Rozema. 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#include "filter_simulator.h"
20
21#include <memory>
22#include <chrono>
23#include <random>
24#include <thread>
25
26// We declare an auto pointer to FilterSim.
27std::unique_ptr<FilterSim> filter_sim(new FilterSim());
28
30{
31 return "Filter Simulator";
32}
33
35{
37
38 DelayNP[0].fill("VALUE", "Seconds", "%.f", -1, 30, 1, 1);
39 DelayNP.fill(getDeviceName(), "DELAY", "Filter Delay", FILTER_TAB, IP_RW, 60, IPS_IDLE);
40 return true;
41}
42
44{
46
47 if (isConnected())
48 {
49 defineProperty(DelayNP);
50 }
51 else
52 {
53 deleteProperty(DelayNP);
54 }
55
56 return true;
57}
58
60{
61 CurrentFilter = 1;
62 FilterSlotNP[0].setMin(1);
63 FilterSlotNP[0].setMax(8);
64 return true;
65}
66
68{
69 return true;
70}
71
72bool FilterSim::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n)
73{
74 if (dev != nullptr && strcmp(dev, getDeviceName()) == 0)
75 {
76 if (DelayNP.isNameMatch(name))
77 {
78 DelayNP.update(values, names, n);
79 DelayNP.setState(IPS_OK);
80 DelayNP.apply();
81 return true;
82 }
83 }
84
85 return INDI::FilterWheel::ISNewNumber(dev, name, values, names, n);
86
87}
88
90{
91 int delay = DelayNP[0].getValue();
92 if (delay < 0)
93 return false;
94
95 std::this_thread::sleep_for(std::chrono::seconds(delay));
96
97 CurrentFilter = f;
98 SetTimer(10);
99 return true;
100}
101
The FilterSim class provides a simple simulator to change filters. The filter names are saved to a co...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
bool Disconnect() override
Disconnect from device.
bool Connect() override
Connect to the device. INDI::DefaultDevice implementation connects to appropriate connection interfac...
bool SelectFilter(int) override
Select a new filter position.
virtual const char * getDefaultName() override
void TimerHit() override
Callback function to be called once SetTimer duration elapses.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
bool isConnected() const
virtual bool deleteProperty(const char *propertyName)
Delete a property and unregister it. It will also be deleted from all clients.
void defineProperty(INumberVectorProperty *property)
int SetTimer(uint32_t ms)
Set a timer to call the function TimerHit after ms milliseconds.
INDI::PropertyNumber FilterSlotNP
void SelectFilterDone(int newpos)
The child class calls this function when the hardware successfully finished selecting a new filter wh...
virtual bool updateProperties() override
updateProperties is called whenever there is a change in the CONNECTION status of the driver....
virtual bool initProperties() override
Initialize properties initial state and value. The child class must implement this function.
virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override
Process the client newNumber command.
void setState(IPState state)
void apply(const char *format,...) const ATTRIBUTE_FORMAT_PRINTF(2
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)
const char * FILTER_TAB
FILTER_TAB Where all the properties for filter wheels are located.
std::unique_ptr< FilterSim > filter_sim(new FilterSim())
@ IP_RW
Definition indiapi.h:184
@ IPS_IDLE
Definition indiapi.h:159
@ IPS_OK
Definition indiapi.h:160
#define getDeviceName