From de351e5c79ded4d26de102768359abda804e3343 Mon Sep 17 00:00:00 2001 From: Jasem Mutlaq Date: Mon, 16 Sep 2024 07:41:27 +0300 Subject: [PATCH] Update light box and dust cap interfaces to new style (#2112) * Update light box and dust cap interfaces to new style * Fix order --- drivers/auxiliary/Excalibur.cpp | 146 ++++---- drivers/auxiliary/alto.cpp | 29 +- drivers/auxiliary/alto.h | 3 +- drivers/auxiliary/deepskydad_fp1.cpp | 79 ++--- drivers/auxiliary/dragonlight.cpp | 48 ++- drivers/auxiliary/flip_flat.cpp | 117 +++---- drivers/auxiliary/giotto.cpp | 39 +-- drivers/auxiliary/light_panel_simulator.cpp | 49 ++- drivers/auxiliary/light_panel_simulator.h | 2 + drivers/auxiliary/pegasus_flatmaster.cpp | 30 +- drivers/auxiliary/snapcap.cpp | 108 +++--- drivers/auxiliary/wanderer_cover.cpp | 79 ++--- drivers/auxiliary/wanderer_cover_v4_ec.cpp | 68 ++-- drivers/focuser/alluna_tcs2.cpp | 366 +++++++++++--------- drivers/focuser/alluna_tcs2.h | 3 +- libs/indibase/defaultdevice.h | 1 + libs/indibase/indidustcapinterface.cpp | 89 +++-- libs/indibase/indidustcapinterface.h | 49 ++- libs/indibase/indilightboxinterface.cpp | 328 +++++++++--------- libs/indibase/indilightboxinterface.h | 52 +-- 20 files changed, 872 insertions(+), 813 deletions(-) diff --git a/drivers/auxiliary/Excalibur.cpp b/drivers/auxiliary/Excalibur.cpp index 9b8f76cd97..5b6f813d06 100644 --- a/drivers/auxiliary/Excalibur.cpp +++ b/drivers/auxiliary/Excalibur.cpp @@ -18,7 +18,7 @@ static std::unique_ptr flatmaster(new Excalibur()); -Excalibur::Excalibur() : LightBoxInterface(this, true) +Excalibur::Excalibur() : LightBoxInterface(this), DustCapInterface(this) { setVersion(1, 0); } @@ -31,14 +31,14 @@ bool Excalibur::initProperties() IUFillText(&StatusT[1], "Light", "Light", nullptr); IUFillTextVector(&StatusTP, StatusT, 2, getDeviceName(), "Status", "Status", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); - initDustCapProperties(getDeviceName(), MAIN_CONTROL_TAB); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + DI::initProperties(MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE | DUSTCAP_INTERFACE); - LightIntensityN[0].min = 0; - LightIntensityN[0].max = 3000; - LightIntensityN[0].step = 1; + LightIntensityNP[0].setMin(0); + LightIntensityNP[0].setMax(3000); + LightIntensityNP[0].setStep(100); addAuxControls(); @@ -59,24 +59,20 @@ bool Excalibur::updateProperties() { INDI::DefaultDevice::updateProperties(); + DI::updateProperties(); + LI::updateProperties(); + if (isConnected()) { - defineProperty(&ParkCapSP); - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); defineProperty(&StatusTP); } else { - deleteProperty(ParkCapSP.name); - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); deleteProperty(StatusTP.name); } - updateLightBoxProperties(); return true; } @@ -96,9 +92,9 @@ bool Excalibur::Ack() { if(strstr("FLAT.FLAP!#", response) != nullptr) { - LightS[1].s = ISS_ON; - LightS[0].s = ISS_OFF; - IDSetSwitch(&LightSP, nullptr); + LightSP[1].setState(ISS_ON); + LightSP[0].setState(ISS_OFF); + LightSP.apply(); deviceStatus(); return true; @@ -115,92 +111,84 @@ bool Excalibur::Ack() bool Excalibur::EnableLightBox(bool enable) { - char response[20]= {0}; + char response[20] = {0}; char cmd[16] = {0}; - if (!enable){ + if (!enable) + { snprintf(cmd, 16, "L%d##", 0); - sendCommand(cmd,response); - IUSaveText(&StatusT[1], "Off"); - IDSetText(&StatusTP, nullptr); - return true; + sendCommand(cmd, response); + IUSaveText(&StatusT[1], "Off"); + IDSetText(&StatusTP, nullptr); + return true; } else { + snprintf(cmd, 16, "L%d##", (int)LightIntensityNP[0].getValue()); - snprintf(cmd, 16, "L%d##", (int)LightIntensityN[0].value); - - sendCommand(cmd,response); - IUSaveText(&StatusT[1], "On"); - IDSetText(&StatusTP, nullptr); - return true; + sendCommand(cmd, response); + IUSaveText(&StatusT[1], "On"); + IDSetText(&StatusTP, nullptr); + return true; } - return false; } bool Excalibur::SetLightBoxBrightness(uint16_t value) { - if(LightS[FLAT_LIGHT_ON].s != ISS_ON) + if(LightSP[FLAT_LIGHT_ON].getState() != ISS_ON) { LOG_ERROR("You must set On the Flat Light first."); return false; } - if( ParkCapS[0].s != ISS_ON) + if( ParkCapSP[0].getState() != ISS_ON) { LOG_ERROR("You must Park eXcalibur first."); return false; } //char response[20] = {0}; - char cmd[DRIVER_RES] = {0}; + char cmd[DRIVER_RES] = {0}; - snprintf(cmd, 30, "L%d##", value); - sendCommand(cmd); - return true; + snprintf(cmd, 30, "L%d##", value); + sendCommand(cmd); + return true; } IPState Excalibur::ParkCap() { - sendCommand("S1#"); - - //IUSaveText(&StatusT[0], "Closed"); - //IUSaveText(&StatusT[1], "On"); - IUResetSwitch(&ParkCapSP); - ParkCapS[0].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[0].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover closed."); - IDSetSwitch(&ParkCapSP, nullptr); - IDSetText(&StatusTP, nullptr); + ParkCapSP.apply(); return IPS_OK; } IPState Excalibur::UnParkCap() { - sendCommand("S0#"); - // Set cover status to random value outside of range to force it to refresh - //IUSaveText(&StatusT[0], "Open"); IUSaveText(&StatusT[1], "Off"); - IUResetSwitch(&ParkCapSP); - ParkCapS[1].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[1].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover open."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); IDSetText(&StatusTP, nullptr); return IPS_OK; } + void Excalibur::TimerHit() { if (!isConnected()) @@ -209,9 +197,9 @@ void Excalibur::TimerHit() deviceStatus(); // parking or unparking timed out, try again - if (ParkCapSP.s == IPS_BUSY && !strcmp(StatusT[0].text, "Timed out")) + if (ParkCapSP.getState() == IPS_BUSY && !strcmp(StatusT[0].text, "Timed out")) { - if (ParkCapS[0].s == ISS_ON) + if (ParkCapSP[0].getState() == ISS_ON) ParkCap(); else UnParkCap(); @@ -222,7 +210,7 @@ void Excalibur::TimerHit() bool Excalibur::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -232,7 +220,7 @@ bool Excalibur::ISNewText(const char *dev, const char *name, char *texts[], char { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; } @@ -243,9 +231,9 @@ bool Excalibur::ISNewSwitch(const char *dev, const char *name, ISState *states, { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processDustCapSwitch(dev, name, states, names, n)) + if (DI::processSwitch(dev, name, states, names, n)) return true; - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; } @@ -254,7 +242,7 @@ bool Excalibur::ISNewSwitch(const char *dev, const char *name, ISState *states, bool Excalibur::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -263,7 +251,7 @@ bool Excalibur::saveConfigItems(FILE *fp) { INDI::DefaultDevice::saveConfigItems(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } bool Excalibur::sendCommand(const char *command, char *res) @@ -315,50 +303,50 @@ void Excalibur::deviceStatus() if (rc > 0) { - LightIntensityN[0].value = pos; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(pos); + LightIntensityNP.apply(); } - if(LightIntensityN[0].value>0) + + if(LightIntensityNP[0].getValue() > 0) { IUSaveText(&StatusT[1], "On"); - if (LightS[1].s == ISS_ON) + if (LightSP[1].getState() == ISS_ON) { - LightS[0].s = ISS_ON; - LightS[1].s = ISS_OFF; - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_ON); + LightSP[1].setState(ISS_OFF); + LightSP.apply(); } } else { IUSaveText(&StatusT[1], "Off"); - } - sendCommand("P#", res); int32_t pos2; sscanf(res, "%d#", &pos2); - if(pos2<=0){ - IUSaveText(&StatusT[0], "Closed"); - if ( ParkCapS[0].s == ISS_OFF) + if(pos2 <= 0) + { + IUSaveText(&StatusT[0], "Closed"); + if (ParkCapSP[0].getState() == ISS_OFF) { - ParkCapS[0].s = ISS_ON; - IDSetSwitch(&LightSP, nullptr); + ParkCapSP[0].setState(ISS_ON); + LightSP.apply(); } } else { IUSaveText(&StatusT[0], "Open"); - if ( ParkCapS[1].s == ISS_OFF) - { - ParkCapS[1].s = ISS_ON; - IUSaveText(&StatusT[1], "Off"); - IDSetSwitch(&LightSP, nullptr); - } + if (ParkCapSP[1].getState() == ISS_OFF) + { + ParkCapSP[1].setState(ISS_ON); + IUSaveText(&StatusT[1], "Off"); + LightSP.apply(); + } } IDSetText(&StatusTP, nullptr); diff --git a/drivers/auxiliary/alto.cpp b/drivers/auxiliary/alto.cpp index bd5261b88c..5fcd665b31 100644 --- a/drivers/auxiliary/alto.cpp +++ b/drivers/auxiliary/alto.cpp @@ -22,7 +22,7 @@ static std::unique_ptr sesto(new ALTO()); -ALTO::ALTO() : DustCapInterface() +ALTO::ALTO() : DustCapInterface(this) { setVersion(1, 0); } @@ -35,7 +35,7 @@ bool ALTO::initProperties() INDI::DefaultDevice::initProperties(); - initDustCapProperties(getDeviceName(), MAIN_CONTROL_TAB); + DI::initProperties(MAIN_CONTROL_TAB, CAN_ABORT); setDriverInterface(AUX_INTERFACE | DUSTCAP_INTERFACE); @@ -88,9 +88,8 @@ bool ALTO::updateProperties() { if (m_ALTO->getPosition(value)) { - ParkCapS[CAP_PARK].s = value == 0 ? ISS_ON : ISS_OFF; - ParkCapS[CAP_UNPARK].s = value == 0 ? ISS_OFF : ISS_ON; - + ParkCapSP[CAP_PARK].setState(value == 0 ? ISS_ON : ISS_OFF); + ParkCapSP[CAP_UNPARK].setState(value == 0 ? ISS_OFF : ISS_ON); PositionNP[0].value = value; } } @@ -99,7 +98,6 @@ bool ALTO::updateProperties() LOGF_ERROR("%s %d", e.what(), e.id); } - defineProperty(&ParkCapSP); defineProperty(PositionNP); defineProperty(MotionSpeedSP); defineProperty(MotionCommandSP); @@ -107,13 +105,14 @@ bool ALTO::updateProperties() } else { - deleteProperty(ParkCapSP.name); deleteProperty(PositionNP); deleteProperty(MotionSpeedSP); deleteProperty(MotionCommandSP); deleteProperty(CalibrateToggleSP); } + DI::updateProperties(); + return true; } @@ -176,7 +175,7 @@ bool ALTO::ISNewNumber(const char *dev, const char *name, double values[], char //////////////////////////////////////////////////////////////////////////////////////////////////////// bool ALTO::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { - if (processDustCapSwitch(dev, name, states, names, n)) + if (DI::processSwitch(dev, name, states, names, n)) return true; // Motion Speed @@ -287,6 +286,14 @@ IPState ALTO::UnParkCap() return IPS_ALERT; } +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +IPState ALTO::AbortCap() +{ + return m_ALTO->stop() ? IPS_OK : IPS_ALERT; +} + //////////////////////////////////////////////////////////////////////////////////////////////////////// /// //////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -302,7 +309,7 @@ bool ALTO::saveConfigItems(FILE * fp) void ALTO::TimerHit() { // Check Park Cap status - if (ParkCapSP.s == IPS_BUSY) + if (ParkCapSP.getState() == IPS_BUSY) { json status; try @@ -311,8 +318,8 @@ void ALTO::TimerHit() std::string mst = status["MST"]; if (mst == "stop") { - ParkCapSP.s = IPS_OK; - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.setState(IPS_OK); + ParkCapSP.apply(); } } catch (json::exception &e) diff --git a/drivers/auxiliary/alto.h b/drivers/auxiliary/alto.h index 48d42b44ea..5e8f1c4c83 100644 --- a/drivers/auxiliary/alto.h +++ b/drivers/auxiliary/alto.h @@ -31,7 +31,7 @@ class ALTO : public INDI::DefaultDevice, public INDI::DustCapInterface virtual bool updateProperties() override; virtual bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; - virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; + virtual bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; protected: bool Handshake(); @@ -40,6 +40,7 @@ class ALTO : public INDI::DefaultDevice, public INDI::DustCapInterface // From Dust Cap virtual IPState ParkCap() override; virtual IPState UnParkCap() override; + virtual IPState AbortCap() override; virtual void TimerHit() override; virtual bool saveConfigItems(FILE *fp) override; diff --git a/drivers/auxiliary/deepskydad_fp1.cpp b/drivers/auxiliary/deepskydad_fp1.cpp index cd8e315dea..7eab5200ac 100644 --- a/drivers/auxiliary/deepskydad_fp1.cpp +++ b/drivers/auxiliary/deepskydad_fp1.cpp @@ -40,7 +40,7 @@ static std::unique_ptr dsdFp1(new DeepSkyDadFP1()); #define FLAT_RES 40 #define FLAT_TIMEOUT 3 -DeepSkyDadFP1::DeepSkyDadFP1() : LightBoxInterface(this, true) +DeepSkyDadFP1::DeepSkyDadFP1() : LightBoxInterface(this), DustCapInterface(this) { setVersion(1, 1); } @@ -67,12 +67,12 @@ bool DeepSkyDadFP1::initProperties() IUFillText(&FirmwareT[0], "Version", "Version", nullptr); IUFillTextVector(&FirmwareTP, FirmwareT, 1, getDeviceName(), "Firmware", "Firmware", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); - initDustCapProperties(getDeviceName(), MAIN_CONTROL_TAB); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + DI::initProperties(MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); - LightIntensityN[0].min = 0; - LightIntensityN[0].max = 4096; - LightIntensityN[0].step = 1; + LightIntensityNP[0].setMin(0); + LightIntensityNP[0].setMax(4096); + LightIntensityNP[0].setStep(1); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE | DUSTCAP_INTERFACE); @@ -93,36 +93,29 @@ void DeepSkyDadFP1::ISGetProperties(const char *dev) INDI::DefaultDevice::ISGetProperties(dev); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } bool DeepSkyDadFP1::updateProperties() { INDI::DefaultDevice::updateProperties(); + DI::updateProperties(); + LI::updateProperties(); + if (isConnected()) { - defineProperty(&ParkCapSP); - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); defineProperty(&HeaterModeSP); defineProperty(&StatusTP); defineProperty(&FirmwareTP); - updateLightBoxProperties(); - getStartupData(); } else { - deleteProperty(ParkCapSP.name); - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); deleteProperty(HeaterModeSP.name); deleteProperty(StatusTP.name); deleteProperty(FirmwareTP.name); - - updateLightBoxProperties(); } return true; @@ -150,7 +143,7 @@ bool DeepSkyDadFP1::Handshake() bool DeepSkyDadFP1::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -160,7 +153,7 @@ bool DeepSkyDadFP1::ISNewText(const char *dev, const char *name, char *texts[], { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; } @@ -171,10 +164,10 @@ bool DeepSkyDadFP1::ISNewSwitch(const char *dev, const char *name, ISState *stat { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processDustCapSwitch(dev, name, states, names, n)) + if (DI::processSwitch(dev, name, states, names, n)) return true; - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; if (strcmp(HeaterModeSP.name, name) == 0) @@ -217,7 +210,7 @@ bool DeepSkyDadFP1::ISNewSwitch(const char *dev, const char *name, ISState *stat bool DeepSkyDadFP1::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -228,7 +221,7 @@ bool DeepSkyDadFP1::saveConfigItems(FILE *fp) IUSaveConfigSwitch(fp, &HeaterModeSP); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } bool DeepSkyDadFP1::ping() @@ -375,27 +368,25 @@ bool DeepSkyDadFP1::getStatus() if(coverStatus == 0) { IUSaveText(&StatusT[0], "Open"); - if (ParkCapSP.s == IPS_BUSY || ParkCapSP.s == IPS_IDLE) + if (ParkCapSP.getState() == IPS_BUSY || ParkCapSP.getState() == IPS_IDLE) { - IUResetSwitch(&ParkCapSP); - ParkCapS[0].s = ISS_OFF; - ParkCapS[1].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[1].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover open."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } } else if(coverStatus == 270) { IUSaveText(&StatusT[0], "Closed"); - if (ParkCapSP.s == IPS_BUSY || ParkCapSP.s == IPS_IDLE) + if (ParkCapSP.getState() == IPS_BUSY || ParkCapSP.getState() == IPS_IDLE) { - IUResetSwitch(&ParkCapSP); - ParkCapS[0].s = ISS_ON; - ParkCapS[1].s = ISS_OFF; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[0].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover closed."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } } else @@ -420,16 +411,16 @@ bool DeepSkyDadFP1::getStatus() { case 0: IUSaveText(&StatusT[1], "Off"); - LightS[0].s = ISS_OFF; - LightS[1].s = ISS_ON; - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_OFF); + LightSP[1].setState(ISS_ON); + LightSP.apply(); break; case 1: IUSaveText(&StatusT[1], "On"); - LightS[0].s = ISS_ON; - LightS[1].s = ISS_OFF; - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_ON); + LightSP[1].setState(ISS_OFF); + LightSP.apply(); break; } } @@ -524,9 +515,9 @@ bool DeepSkyDadFP1::getBrightness() if (brightnessValue != prevBrightness) { - prevBrightness = brightnessValue; - LightIntensityN[0].value = brightnessValue; - IDSetNumber(&LightIntensityNP, nullptr); + prevBrightness = brightnessValue; + LightIntensityNP[0].setValue(brightnessValue); + LightIntensityNP.apply(); } return true; diff --git a/drivers/auxiliary/dragonlight.cpp b/drivers/auxiliary/dragonlight.cpp index 99818beb6d..48f060878b 100644 --- a/drivers/auxiliary/dragonlight.cpp +++ b/drivers/auxiliary/dragonlight.cpp @@ -35,7 +35,7 @@ static std::unique_ptr dragonlight(new DragonLIGHT()); -DragonLIGHT::DragonLIGHT() : LightBoxInterface(this, true) +DragonLIGHT::DragonLIGHT() : LightBoxInterface(this) { setVersion(1, 0); } @@ -54,13 +54,13 @@ bool DragonLIGHT::initProperties() DiscoverSwitchSP[0].fill("DISCOVER", "Discover", ISS_OFF); DiscoverSwitchSP.fill(getDeviceName(), "DISCOVER", "Discover", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE); - LightIntensityN[0].min = 0; - LightIntensityN[0].max = 255; - LightIntensityN[0].step = 1; + LightIntensityNP[0].setMin(0); + LightIntensityNP[0].setMax(255); + LightIntensityNP[0].setMax(1); addAuxControls(); @@ -75,7 +75,7 @@ void DragonLIGHT::ISGetProperties(const char *dev) defineProperty(DiscoverSwitchSP); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); loadConfig(IPAddressTP); } @@ -83,21 +83,17 @@ void DragonLIGHT::ISGetProperties(const char *dev) bool DragonLIGHT::updateProperties() { INDI::DefaultDevice::updateProperties(); + LI::updateProperties(); if (isConnected()) { - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); defineProperty(FirmwareTP); } else { - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); deleteProperty(FirmwareTP); } - updateLightBoxProperties(); return true; } @@ -126,14 +122,14 @@ bool DragonLIGHT::EnableLightBox(bool enable) bool DragonLIGHT::SetLightBoxBrightness(uint16_t value) { - if (LightS[FLAT_LIGHT_ON].s != ISS_ON) + if (LightSP[FLAT_LIGHT_ON].getState() != ISS_ON) { LOG_ERROR("You must set On the Flat Light first."); return false; } - LightIntensityN[0].value = value; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(value); + LightIntensityNP.apply(); httplib::Client cli(IPAddressTP[0].getText(), 80); @@ -161,7 +157,7 @@ bool DragonLIGHT::SetLightBoxBrightness(uint16_t value) bool DragonLIGHT::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -178,7 +174,7 @@ bool DragonLIGHT::ISNewText(const char *dev, const char *name, char *texts[], ch return true; } - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n); @@ -201,7 +197,7 @@ bool DragonLIGHT::ISNewSwitch(const char *dev, const char *name, ISState *states return true; } - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n); @@ -209,7 +205,7 @@ bool DragonLIGHT::ISNewSwitch(const char *dev, const char *name, ISState *states bool DragonLIGHT::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -220,7 +216,7 @@ bool DragonLIGHT::saveConfigItems(FILE *fp) IPAddressTP.save(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } bool DragonLIGHT::Connect() @@ -281,16 +277,16 @@ void DragonLIGHT::updateStatus() uint32_t brightness = j["brightness"]; - LightIntensityN[0].value = brightness; - LightIntensityNP.s = IPS_OK; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(brightness); + LightIntensityNP.setState(IPS_OK); + LightIntensityNP.apply(); bool isOn = j["isOn"]; - LightS[FLAT_LIGHT_ON].s = isOn ? ISS_ON : ISS_OFF; - LightS[FLAT_LIGHT_OFF].s = isOn ? ISS_OFF : ISS_ON; - LightSP.s = IPS_OK; - IDSetSwitch(&LightSP, nullptr); + LightSP[FLAT_LIGHT_ON].setState(isOn ? ISS_ON : ISS_OFF); + LightSP[FLAT_LIGHT_OFF].setState(isOn ? ISS_OFF : ISS_ON); + LightSP.setState(IPS_OK); + LightSP.apply(); } else { diff --git a/drivers/auxiliary/flip_flat.cpp b/drivers/auxiliary/flip_flat.cpp index 8492b654c9..870b0c2325 100644 --- a/drivers/auxiliary/flip_flat.cpp +++ b/drivers/auxiliary/flip_flat.cpp @@ -42,7 +42,7 @@ static std::unique_ptr flipflat(new FlipFlat()); #define FLAT_RES 8 #define FLAT_TIMEOUT 3 -FlipFlat::FlipFlat() : LightBoxInterface(this, true) +FlipFlat::FlipFlat() : LightBoxInterface(this), DustCapInterface(this) { setVersion(1, 1); } @@ -61,12 +61,12 @@ bool FlipFlat::initProperties() IUFillText(&FirmwareT[0], "Version", "Version", nullptr); IUFillTextVector(&FirmwareTP, FirmwareT, 1, getDeviceName(), "Firmware", "Firmware", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); - initDustCapProperties(getDeviceName(), MAIN_CONTROL_TAB); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + DI::initProperties(MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); - LightIntensityN[0].min = 0; - LightIntensityN[0].max = 255; - LightIntensityN[0].step = 10; + LightIntensityNP[0].setMin(0); + LightIntensityNP[0].setMax(255); + LightIntensityNP[0].setStep(10); // Set DUSTCAP_INTEFACE later on connect after we verify whether it's flip-flat (dust cover + light) or just flip-man (light only) setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE); @@ -88,7 +88,7 @@ void FlipFlat::ISGetProperties(const char *dev) INDI::DefaultDevice::ISGetProperties(dev); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } bool FlipFlat::updateProperties() @@ -98,26 +98,23 @@ bool FlipFlat::updateProperties() if (isConnected()) { if (m_Type == FLIP_FLAT || m_Type == ALNITAK_DUST_COVER) - defineProperty(&ParkCapSP); - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); + DI::updateProperties(); defineProperty(&StatusTP); defineProperty(&FirmwareTP); - updateLightBoxProperties(); + LI::updateProperties(); getStartupData(); } else { if (m_Type == FLIP_FLAT || m_Type == ALNITAK_DUST_COVER) - deleteProperty(ParkCapSP.name); - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); + DI::updateProperties(); + + LI::updateProperties(); deleteProperty(StatusTP.name); deleteProperty(FirmwareTP.name); - updateLightBoxProperties(); } return true; @@ -153,8 +150,8 @@ bool FlipFlat::Handshake() /* Try ping anyway, to allow flip-flat implementations using virtual serial ports to proceed */ if(ping()) { - LOG_DEBUG("Successfully connected to flip-flat without hardware IOCTL"); - return true; + LOG_DEBUG("Successfully connected to flip-flat without hardware IOCTL"); + return true; } LOGF_ERROR("IOCTL error %s.", strerror(errno)); return false; @@ -178,7 +175,7 @@ bool FlipFlat::Handshake() bool FlipFlat::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -188,7 +185,7 @@ bool FlipFlat::ISNewText(const char *dev, const char *name, char *texts[], char { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; } @@ -199,10 +196,10 @@ bool FlipFlat::ISNewSwitch(const char *dev, const char *name, ISState *states, c { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processDustCapSwitch(dev, name, states, names, n)) + if (DI::processSwitch(dev, name, states, names, n)) return true; - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; } @@ -211,7 +208,7 @@ bool FlipFlat::ISNewSwitch(const char *dev, const char *name, ISState *states, c bool FlipFlat::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -220,7 +217,7 @@ bool FlipFlat::saveConfigItems(FILE *fp) { INDI::DefaultDevice::saveConfigItems(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } bool FlipFlat::ping() @@ -331,7 +328,7 @@ bool FlipFlat::EnableLightBox(bool enable) char command[FLAT_CMD]; char response[FLAT_RES]; - if (m_Type == FLIP_FLAT && ParkCapS[1].s == ISS_ON) + if (m_Type == FLIP_FLAT && ParkCapSP[1].getState() == ISS_ON) { LOG_ERROR("Cannot control light while cap is unparked."); return false; @@ -365,14 +362,14 @@ bool FlipFlat::getStatus() if (isSimulation()) { - if (ParkCapSP.s == IPS_BUSY && --simulationWorkCounter <= 0) + if (ParkCapSP.getState() == IPS_BUSY && --simulationWorkCounter <= 0) { - ParkCapSP.s = IPS_OK; - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.setState(IPS_OK); + ParkCapSP.apply(); simulationWorkCounter = 0; } - if (ParkCapSP.s == IPS_BUSY) + if (ParkCapSP.getState() == IPS_BUSY) { response[4] = '1'; response[6] = '0'; @@ -381,13 +378,13 @@ bool FlipFlat::getStatus() { response[4] = '0'; // Parked/Closed - if (ParkCapS[CAP_PARK].s == ISS_ON) + if (ParkCapSP[CAP_PARK].getState() == ISS_ON) response[6] = '1'; else response[6] = '2'; } - response[5] = (LightS[FLAT_LIGHT_ON].s == ISS_ON) ? '1' : '0'; + response[5] = (LightSP[FLAT_LIGHT_ON].getState() == ISS_ON) ? '1' : '0'; } else { @@ -415,25 +412,25 @@ bool FlipFlat::getStatus() case 1: IUSaveText(&StatusT[0], "Closed"); - if (ParkCapSP.s == IPS_BUSY || ParkCapSP.s == IPS_IDLE) + if (ParkCapSP.getState() == IPS_BUSY || ParkCapSP.getState() == IPS_IDLE) { - IUResetSwitch(&ParkCapSP); - ParkCapS[0].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[0].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover closed."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } break; case 2: IUSaveText(&StatusT[0], "Open"); - if (ParkCapSP.s == IPS_BUSY || ParkCapSP.s == IPS_IDLE) + if (ParkCapSP.getState() == IPS_BUSY || ParkCapSP.getState() == IPS_IDLE) { - IUResetSwitch(&ParkCapSP); - ParkCapS[1].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[1].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover open."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } break; @@ -453,21 +450,21 @@ bool FlipFlat::getStatus() { case 0: IUSaveText(&StatusT[1], "Off"); - if (LightS[0].s == ISS_ON) + if (LightSP[0].getState() == ISS_ON) { - LightS[0].s = ISS_OFF; - LightS[1].s = ISS_ON; - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_OFF); + LightSP[1].setState(ISS_ON); + LightSP.apply(); } break; case 1: IUSaveText(&StatusT[1], "On"); - if (LightS[1].s == ISS_ON) + if (LightSP[1].getState() == ISS_ON) { - LightS[0].s = ISS_ON; - LightS[1].s = ISS_OFF; - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_ON); + LightSP[1].setState(ISS_OFF); + LightSP.apply(); } break; } @@ -526,9 +523,9 @@ void FlipFlat::TimerHit() getStatus(); // parking or unparking timed out, try again - if (ParkCapSP.s == IPS_BUSY && !strcmp(StatusT[0].text, "Timed out")) + if (ParkCapSP.getState() == IPS_BUSY && !strcmp(StatusT[0].text, "Timed out")) { - if (ParkCapS[0].s == ISS_ON) + if (ParkCapSP[0].getState() == ISS_ON) ParkCap(); else UnParkCap(); @@ -562,9 +559,9 @@ bool FlipFlat::getBrightness() if (brightnessValue != prevBrightness) { - prevBrightness = brightnessValue; - LightIntensityN[0].value = brightnessValue; - IDSetNumber(&LightIntensityNP, nullptr); + prevBrightness = brightnessValue; + LightIntensityNP[0].setValue(brightnessValue); + LightIntensityNP.apply(); } return true; @@ -574,8 +571,8 @@ bool FlipFlat::SetLightBoxBrightness(uint16_t value) { if (isSimulation()) { - LightIntensityN[0].value = value; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(value); + LightIntensityNP.apply(); return true; } @@ -601,9 +598,9 @@ bool FlipFlat::SetLightBoxBrightness(uint16_t value) if (brightnessValue != prevBrightness) { - prevBrightness = brightnessValue; - LightIntensityN[0].value = brightnessValue; - IDSetNumber(&LightIntensityNP, nullptr); + prevBrightness = brightnessValue; + LightIntensityNP[0].setValue(brightnessValue); + LightIntensityNP.apply(); } return true; @@ -661,7 +658,7 @@ void FlipFlat::unparkTimeoutHelper(void *context) void FlipFlat::parkTimeout() { - if (ParkCapSP.s == IPS_BUSY) + if (ParkCapSP.getState() == IPS_BUSY) { LOG_WARN("Parking cap timed out. Retrying..."); ParkCap(); @@ -670,7 +667,7 @@ void FlipFlat::parkTimeout() void FlipFlat::unparkTimeout() { - if (ParkCapSP.s == IPS_BUSY) + if (ParkCapSP.getState() == IPS_BUSY) { LOG_WARN("UnParking cap timed out. Retrying..."); UnParkCap(); diff --git a/drivers/auxiliary/giotto.cpp b/drivers/auxiliary/giotto.cpp index 309662f1a9..2820efc876 100644 --- a/drivers/auxiliary/giotto.cpp +++ b/drivers/auxiliary/giotto.cpp @@ -26,7 +26,7 @@ static std::unique_ptr sesto(new GIOTTO()); -GIOTTO::GIOTTO() : LightBoxInterface(this, true) +GIOTTO::GIOTTO() : LightBoxInterface(this) { setVersion(1, 0); } @@ -45,7 +45,7 @@ bool GIOTTO::initProperties() INDI::DefaultDevice::initProperties(); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE); @@ -68,20 +68,7 @@ bool GIOTTO::initProperties() bool GIOTTO::updateProperties() { INDI::DefaultDevice::updateProperties(); - - if (isConnected()) - { - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); - } - else - { - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); - } - - updateLightBoxProperties(); - + LI::updateProperties(); return true; } @@ -93,7 +80,7 @@ void GIOTTO::ISGetProperties(const char *dev) INDI::DefaultDevice::ISGetProperties(dev); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } //////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -115,16 +102,16 @@ bool GIOTTO::Handshake() uint16_t max = 0; if (m_GIOTTO->getMaxBrightness(max)) { - LightIntensityNP.np[0].max = max; + LightIntensityNP[0].setMax(max); LOGF_INFO("%s is online.", getDeviceName()); uint16_t value = 0; if (m_GIOTTO->getBrightness(value)) - LightIntensityNP.np[0].value = value; + LightIntensityNP[0].setValue(value); auto lightEnabled = m_GIOTTO->isLightEnabled(); - LightS[0].s = lightEnabled ? ISS_ON : ISS_OFF; - LightS[1].s = lightEnabled ? ISS_OFF : ISS_ON; + LightSP[0].setState(lightEnabled ? ISS_ON : ISS_OFF); + LightSP[1].setState(lightEnabled ? ISS_OFF : ISS_ON); return true; } @@ -147,7 +134,7 @@ const char *GIOTTO::getDefaultName() //////////////////////////////////////////////////////////////////////////////////////////////////////// bool GIOTTO::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -158,7 +145,7 @@ bool GIOTTO::ISNewNumber(const char *dev, const char *name, double values[], cha //////////////////////////////////////////////////////////////////////////////////////////////////////// bool GIOTTO::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) { - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n); @@ -169,7 +156,7 @@ bool GIOTTO::ISNewText(const char *dev, const char *name, char *texts[], char *n //////////////////////////////////////////////////////////////////////////////////////////////////////// bool GIOTTO::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n); @@ -180,7 +167,7 @@ bool GIOTTO::ISNewSwitch(const char *dev, const char *name, ISState *states, cha //////////////////////////////////////////////////////////////////////////////////////////////////////// bool GIOTTO::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -208,5 +195,5 @@ bool GIOTTO::saveConfigItems(FILE *fp) { INDI::DefaultDevice::saveConfigItems(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } diff --git a/drivers/auxiliary/light_panel_simulator.cpp b/drivers/auxiliary/light_panel_simulator.cpp index 1b2bba6fbb..1fab44c04e 100644 --- a/drivers/auxiliary/light_panel_simulator.cpp +++ b/drivers/auxiliary/light_panel_simulator.cpp @@ -9,7 +9,7 @@ static std::unique_ptr simulator(new LightPanelSimulator()); -LightPanelSimulator::LightPanelSimulator() : LightBoxInterface(this, true) +LightPanelSimulator::LightPanelSimulator() : LightBoxInterface(this) { } @@ -18,14 +18,14 @@ void LightPanelSimulator::ISGetProperties(const char *dev) INDI::DefaultDevice::ISGetProperties(dev); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } bool LightPanelSimulator::initProperties() { INDI::DefaultDevice::initProperties(); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); addAuxControls(); return true; } @@ -33,25 +33,20 @@ bool LightPanelSimulator::initProperties() bool LightPanelSimulator::updateProperties() { INDI::DefaultDevice::updateProperties(); - - if (isConnected()) - { - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); - } - else - { - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); - } - - updateLightBoxProperties(); + LI::updateProperties(); return true; } +bool LightPanelSimulator::ISSnoopDevice(XMLEle *root) +{ + LI::snoop(root); + + return INDI::DefaultDevice::ISSnoopDevice(root); +} + bool LightPanelSimulator::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -59,26 +54,26 @@ bool LightPanelSimulator::ISNewNumber(const char *dev, const char *name, double bool LightPanelSimulator::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) { - if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) - { - if (processLightBoxText(dev, name, texts, names, n)) - return true; - } + if (LI::processText(dev, name, texts, names, n)) + return true; return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n); } bool LightPanelSimulator::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { - if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) - { - if (processLightBoxSwitch(dev, name, states, names, n)) - return true; - } + if (LI::processSwitch(dev, name, states, names, n)) + return true; return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n); } +bool LightPanelSimulator::saveConfigItems(FILE *fp) +{ + INDI::DefaultDevice::saveConfigItems(fp); + return LI::saveConfigItems(fp); +} + bool LightPanelSimulator::SetLightBoxBrightness(uint16_t value) { INDI_UNUSED(value); diff --git a/drivers/auxiliary/light_panel_simulator.h b/drivers/auxiliary/light_panel_simulator.h index 1452b1ab42..5121504191 100644 --- a/drivers/auxiliary/light_panel_simulator.h +++ b/drivers/auxiliary/light_panel_simulator.h @@ -21,11 +21,13 @@ class LightPanelSimulator : public INDI::DefaultDevice, public INDI::LightBoxInt bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; bool ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) override; bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; + bool ISSnoopDevice(XMLEle *root) override; protected: bool initProperties() override; bool updateProperties() override; + bool saveConfigItems(FILE *fp) override; bool Connect() override { diff --git a/drivers/auxiliary/pegasus_flatmaster.cpp b/drivers/auxiliary/pegasus_flatmaster.cpp index 52baec71e8..65ad69c527 100644 --- a/drivers/auxiliary/pegasus_flatmaster.cpp +++ b/drivers/auxiliary/pegasus_flatmaster.cpp @@ -42,7 +42,7 @@ static std::unique_ptr flatmaster(new PegasusFlatMaster()); -PegasusFlatMaster::PegasusFlatMaster() : LightBoxInterface(this, true) +PegasusFlatMaster::PegasusFlatMaster() : LightBoxInterface(this) { setVersion(1, 2); } @@ -55,13 +55,13 @@ bool PegasusFlatMaster::initProperties() IUFillText(&FirmwareT[0], "Version", "Version", nullptr); IUFillTextVector(&FirmwareTP, FirmwareT, 1, getDeviceName(), "Firmware", "Firmware", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE); - LightIntensityN[0].min = 0; - LightIntensityN[0].max = 100; - LightIntensityN[0].step = 1; + LightIntensityNP[0].setMin(0); + LightIntensityNP[0].setMax(100); + LightIntensityNP[0].setStep(1); addAuxControls(); @@ -82,7 +82,7 @@ void PegasusFlatMaster::ISGetProperties(const char *dev) INDI::DefaultDevice::ISGetProperties(dev); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } bool PegasusFlatMaster::updateProperties() @@ -91,18 +91,14 @@ bool PegasusFlatMaster::updateProperties() if (isConnected()) { - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); defineProperty(&FirmwareTP); } else { - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); deleteProperty(FirmwareTP.name); } - updateLightBoxProperties(); + LI::updateProperties(); return true; } @@ -174,7 +170,7 @@ bool PegasusFlatMaster::EnableLightBox(bool enable) bool PegasusFlatMaster::SetLightBoxBrightness(uint16_t value) { - if(LightS[FLAT_LIGHT_ON].s != ISS_ON) + if(LightSP[FLAT_LIGHT_ON].getState() != ISS_ON) { LOG_ERROR("You must set On the Flat Light first."); return false; @@ -204,7 +200,7 @@ bool PegasusFlatMaster::SetLightBoxBrightness(uint16_t value) bool PegasusFlatMaster::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -214,7 +210,7 @@ bool PegasusFlatMaster::ISNewText(const char *dev, const char *name, char *texts { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; } @@ -225,7 +221,7 @@ bool PegasusFlatMaster::ISNewSwitch(const char *dev, const char *name, ISState * { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; } @@ -234,7 +230,7 @@ bool PegasusFlatMaster::ISNewSwitch(const char *dev, const char *name, ISState * bool PegasusFlatMaster::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -243,7 +239,7 @@ bool PegasusFlatMaster::saveConfigItems(FILE *fp) { INDI::DefaultDevice::saveConfigItems(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } bool PegasusFlatMaster::sendCommand(const char *command, char *res) diff --git a/drivers/auxiliary/snapcap.cpp b/drivers/auxiliary/snapcap.cpp index 2e9ff9dd2d..20376bd908 100644 --- a/drivers/auxiliary/snapcap.cpp +++ b/drivers/auxiliary/snapcap.cpp @@ -43,12 +43,13 @@ std::unique_ptr snapcap(new SnapCap()); #define SNAP_RES 8 // Includes terminating null #define SNAP_TIMEOUT 3 -SnapCap::SnapCap() : LightBoxInterface(this, true) +SnapCap::SnapCap() : LightBoxInterface(this), DustCapInterface(this) { setVersion(1, 3); } -SnapCap::~SnapCap(){ +SnapCap::~SnapCap() +{ delete serialConnection; delete tcpConnection; @@ -76,12 +77,12 @@ bool SnapCap::initProperties() ForceSP[1].fill("ON", "On", ISS_OFF); ForceSP.fill(getDeviceName(), "FORCE", "Force movement", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); - initDustCapProperties(getDeviceName(), MAIN_CONTROL_TAB); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + DI::initProperties(MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); - LightIntensityN[0].min = 0; - LightIntensityN[0].max = 255; - LightIntensityN[0].step = 10; + LightIntensityNP[0].setMin(0); + LightIntensityNP[0].setMax(255); + LightIntensityNP[0].setStep(10); hasLight = true; @@ -118,36 +119,33 @@ void SnapCap::ISGetProperties(const char *dev) INDI::DefaultDevice::ISGetProperties(dev); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } bool SnapCap::updateProperties() { INDI::DefaultDevice::updateProperties(); + DI::updateProperties(); + if (isConnected()) { - defineProperty(&ParkCapSP); if (hasLight) { - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); - updateLightBoxProperties(); + LI::updateProperties(); } defineProperty(StatusTP); defineProperty(FirmwareTP); defineProperty(AbortSP); defineProperty(ForceSP); + getStartupData(); } else { - deleteProperty(ParkCapSP.name); if (hasLight) { - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); - updateLightBoxProperties(); + LI::updateProperties(); } deleteProperty(StatusTP); deleteProperty(FirmwareTP); @@ -160,7 +158,7 @@ bool SnapCap::updateProperties() const char *SnapCap::getDefaultName() { - return (const char *)"SnapCap"; + return "SnapCap"; } bool SnapCap::Handshake() @@ -200,7 +198,7 @@ bool SnapCap::ISNewNumber(const char *dev, const char *name, double values[], ch if (!dev || strcmp(dev, getDeviceName())) return false; - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; return INDI::DefaultDevice::ISNewNumber(dev, name, values, names, n); @@ -211,7 +209,7 @@ bool SnapCap::ISNewText(const char *dev, const char *name, char *texts[], char * if (!dev || strcmp(dev, getDeviceName())) return false; - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n); @@ -231,15 +229,15 @@ bool SnapCap::ISNewSwitch(const char *dev, const char *name, ISState *states, ch } if (ForceSP.isNameMatch(name)) { - ForceSP.update(states, names, n); - ForceSP.apply(); + ForceSP.update(states, names, n); + ForceSP.apply(); return true; } - if (processDustCapSwitch(dev, name, states, names, n)) + if (DI::processSwitch(dev, name, states, names, n)) return true; - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; return INDI::DefaultDevice::ISNewSwitch(dev, name, states, names, n); @@ -247,7 +245,7 @@ bool SnapCap::ISNewSwitch(const char *dev, const char *name, ISState *states, ch bool SnapCap::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -256,7 +254,7 @@ bool SnapCap::saveConfigItems(FILE *fp) { INDI::DefaultDevice::saveConfigItems(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } bool SnapCap::ping() @@ -427,14 +425,14 @@ bool SnapCap::getStatus() if (isSimulation()) { - if (ParkCapSP.s == IPS_BUSY && --simulationWorkCounter <= 0) + if (ParkCapSP.getState() == IPS_BUSY && --simulationWorkCounter <= 0) { - ParkCapSP.s = IPS_IDLE; - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.setState(IPS_IDLE); + ParkCapSP.apply(); simulationWorkCounter = 0; } - if (ParkCapSP.s == IPS_BUSY) + if (ParkCapSP.getState() == IPS_BUSY) { response[2] = '1'; response[4] = '0'; @@ -443,13 +441,13 @@ bool SnapCap::getStatus() { response[2] = '0'; // Parked/Closed - if (ParkCapS[CAP_PARK].s == ISS_ON) + if (ParkCapSP[CAP_PARK].getState() == ISS_ON) response[4] = '2'; else response[4] = '1'; } - response[3] = (LightS[FLAT_LIGHT_ON].s == ISS_ON) ? '1' : '0'; + response[3] = (LightSP[FLAT_LIGHT_ON].getState() == ISS_ON) ? '1' : '0'; } else { @@ -481,26 +479,26 @@ bool SnapCap::getStatus() break; case 1: - if ((targetCoverStatus == 1 && ParkCapSP.s == IPS_BUSY) || ParkCapSP.s == IPS_IDLE) + if ((targetCoverStatus == 1 && ParkCapSP.getState() == IPS_BUSY) || ParkCapSP.getState() == IPS_IDLE) { StatusTP[0].setText("Open"); - IUResetSwitch(&ParkCapSP); - ParkCapS[CAP_UNPARK].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[CAP_UNPARK].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover open."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } break; case 2: - if ((targetCoverStatus == 2 && ParkCapSP.s == IPS_BUSY) || ParkCapSP.s == IPS_IDLE) + if ((targetCoverStatus == 2 && ParkCapSP.getState() == IPS_BUSY) || ParkCapSP.getState() == IPS_IDLE) { StatusTP[0].setText("Closed"); - IUResetSwitch(&ParkCapSP); - ParkCapS[CAP_PARK].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[CAP_PARK].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover closed."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } break; @@ -532,21 +530,21 @@ bool SnapCap::getStatus() { case 0: StatusTP[1].setText("Off"); - if (LightS[0].s == ISS_ON) + if (LightSP[0].getState() == ISS_ON) { - LightS[0].s = ISS_OFF; - LightS[1].s = ISS_ON; - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_OFF); + LightSP[1].setState(ISS_ON); + LightSP.apply(); } break; case 1: StatusTP[1].setText("On"); - if (LightS[1].s == ISS_ON) + if (LightSP[1].getState() == ISS_ON) { - LightS[0].s = ISS_ON; - LightS[1].s = ISS_OFF; - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_ON); + LightSP[1].setState(ISS_OFF); + LightSP.apply(); } break; } @@ -632,8 +630,8 @@ bool SnapCap::getBrightness() if (brightnessValue != prevBrightness) { prevBrightness = brightnessValue; - LightIntensityN[0].value = brightnessValue; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(brightnessValue); + LightIntensityNP.apply(); } return true; @@ -643,8 +641,8 @@ bool SnapCap::SetLightBoxBrightness(uint16_t value) { if (isSimulation()) { - LightIntensityN[0].value = value; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(value); + LightIntensityNP.apply(); return true; } @@ -668,8 +666,8 @@ bool SnapCap::SetLightBoxBrightness(uint16_t value) if (brightnessValue != prevBrightness) { prevBrightness = brightnessValue; - LightIntensityN[0].value = brightnessValue; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(brightnessValue); + LightIntensityNP.apply(); } return true; diff --git a/drivers/auxiliary/wanderer_cover.cpp b/drivers/auxiliary/wanderer_cover.cpp index a7eff05ccc..b4975e10f5 100644 --- a/drivers/auxiliary/wanderer_cover.cpp +++ b/drivers/auxiliary/wanderer_cover.cpp @@ -56,7 +56,7 @@ static std::unique_ptr wanderercover(new WandererCover()); # define SET_CURRENT_POSITION_TO_CLOSED_POSITION "256\n" -WandererCover::WandererCover() : LightBoxInterface(this, true) +WandererCover::WandererCover() : LightBoxInterface(this), DustCapInterface(this) { setVersion(1, 0); } @@ -64,8 +64,8 @@ WandererCover::WandererCover() : LightBoxInterface(this, true) bool WandererCover::initProperties() { INDI::DefaultDevice::initProperties(); - initDustCapProperties(getDeviceName(), MAIN_CONTROL_TAB); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); + DI::initProperties(MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE | DUSTCAP_INTERFACE); addAuxControls(); @@ -102,12 +102,9 @@ bool WandererCover::initProperties() "Action", TAB_NAME_CONFIGURATION, IP_RW, ISR_ATMOST1, 0, IPS_IDLE); - - LightIntensityN[0].min = 1; - LightIntensityN[0].max = 255; - LightIntensityN[0].step = 10; - - + LightIntensityNP[0].setMin(1); + LightIntensityNP[0].setMax(255); + LightIntensityNP[0].setStep(10); serialConnection = new Connection::Serial(this); serialConnection->setDefaultBaudRate(Connection::Serial::B_19200); @@ -246,18 +243,17 @@ void WandererCover::ISGetProperties(const char *dev) INDI::DefaultDevice::ISGetProperties(dev); // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } bool WandererCover::updateProperties() { INDI::DefaultDevice::updateProperties(); + DI::updateProperties(); + if (isConnected()) { - defineProperty(&ParkCapSP); - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); defineProperty(&StatusTP); defineProperty(&FirmwareTP); @@ -265,24 +261,19 @@ bool WandererCover::updateProperties() defineProperty(&ControlPositionNegativeDegreesConfigurationVP); defineProperty(&DefinePositionConfigurationVP); - updateLightBoxProperties(); - getStartupData(); } else { - deleteProperty(ParkCapSP.name); - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); deleteProperty(StatusTP.name); deleteProperty(FirmwareTP.name); deleteProperty(ControlPositionPositiveDegreesConfigurationVP.name); deleteProperty(ControlPositionNegativeDegreesConfigurationVP.name); deleteProperty(DefinePositionConfigurationVP.name); - - updateLightBoxProperties(); } + + LI::updateProperties(); return true; } @@ -295,7 +286,7 @@ bool WandererCover::ISNewNumber(const char *dev, const char *name, double values { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; } @@ -306,7 +297,7 @@ bool WandererCover::ISNewText(const char *dev, const char *name, char *texts[], { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; } @@ -317,10 +308,10 @@ bool WandererCover::ISNewSwitch(const char *dev, const char *name, ISState *stat { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (processDustCapSwitch(dev, name, states, names, n)) + if (DI::processSwitch(dev, name, states, names, n)) return true; - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; if (processConfigurationButtonSwitch(dev, name, states, names, n)) @@ -332,7 +323,7 @@ bool WandererCover::ISNewSwitch(const char *dev, const char *name, ISState *stat bool WandererCover::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -341,7 +332,7 @@ bool WandererCover::saveConfigItems(FILE *fp) { INDI::DefaultDevice::saveConfigItems(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } bool WandererCover::getStartupData() @@ -358,10 +349,10 @@ bool WandererCover::getStartupData() // IUSaveText(&StatusT[1], "Off"); // LightS[0].s = ISS_OFF; // LightS[1].s = ISS_ON; - // IDSetSwitch(&LightSP, nullptr); + // LightSP.apply(); // LightIntensityN[0].value = 0; // LOG_INFO("Light assumed as off."); - // IDSetNumber(&LightIntensityNP, nullptr); + // LightIntensityNP.apply(); return true; } @@ -399,11 +390,11 @@ IPState WandererCover::ParkCap() void WandererCover::setParkCapStatusAsClosed() { IUSaveText(&StatusT[0], "Closed"); - IUResetSwitch(&ParkCapSP); - ParkCapS[0].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[0].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover closed."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } IPState WandererCover::UnParkCap() @@ -438,16 +429,16 @@ IPState WandererCover::UnParkCap() void WandererCover::setParkCapStatusAsOpen() { IUSaveText(&StatusT[0], "Open"); - IUResetSwitch(&ParkCapSP); - ParkCapS[1].s = ISS_ON; - ParkCapSP.s = IPS_OK; + ParkCapSP.reset(); + ParkCapSP[1].setState(ISS_ON); + ParkCapSP.setState(IPS_OK); LOG_INFO("Cover open."); - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } bool WandererCover::EnableLightBox(bool enable) { - if (ParkCapS[1].s == ISS_ON) + if (ParkCapSP[1].getState() == ISS_ON) { LOG_ERROR("Cannot control light while cap is unparked."); return false; @@ -484,11 +475,11 @@ bool WandererCover::switchOffLightBox() void WandererCover::setLightBoxStatusAsSwitchedOff() { IUSaveText(&StatusT[1], "Off"); - LightS[0].s = ISS_OFF; - LightS[1].s = ISS_ON; - LightIntensityN[0].value = 0; - IDSetNumber(&LightIntensityNP, nullptr); - IDSetSwitch(&LightSP, nullptr); + LightSP[0].setState(ISS_OFF); + LightSP[1].setState(ISS_ON); + LightIntensityNP[0].setValue(0); + LightIntensityNP.apply(); + LightSP.apply(); LOG_INFO("Light panel switched off"); } @@ -556,8 +547,8 @@ bool WandererCover::setCurrentPositionToClosedPosition() void WandererCover::setLightBoxBrightnesStatusToValue(uint16_t value) { - LightIntensityN[0].value = value; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(value); + LightIntensityNP.apply(); LOGF_INFO("Brightness set to %d.", value); } diff --git a/drivers/auxiliary/wanderer_cover_v4_ec.cpp b/drivers/auxiliary/wanderer_cover_v4_ec.cpp index 5dcf113660..75a4431cc7 100644 --- a/drivers/auxiliary/wanderer_cover_v4_ec.cpp +++ b/drivers/auxiliary/wanderer_cover_v4_ec.cpp @@ -34,7 +34,7 @@ static std::unique_ptr wanderercoverv4ec(new WandererCoverV4EC()); -WandererCoverV4EC::WandererCoverV4EC() : DustCapInterface(), INDI::LightBoxInterface(this, true) +WandererCoverV4EC::WandererCoverV4EC() : DustCapInterface(this), LightBoxInterface(this) { setVersion(1, 2); } @@ -54,8 +54,8 @@ bool WandererCoverV4EC::initProperties() { INDI::DefaultDevice::initProperties(); - initLightBoxProperties(getDeviceName(), MAIN_CONTROL_TAB); - initDustCapProperties(getDeviceName(), MAIN_CONTROL_TAB); + LI::initProperties(MAIN_CONTROL_TAB, CAN_DIM); + DI::initProperties(MAIN_CONTROL_TAB); setDriverInterface(AUX_INTERFACE | LIGHTBOX_INTERFACE | DUSTCAP_INTERFACE); addAuxControls(); @@ -67,8 +67,8 @@ bool WandererCoverV4EC::initProperties() DataNP[voltage_read].fill( "Voltage", "Voltage (V)", "%4.2f", 0, 999, 100, 0); DataNP.fill(getDeviceName(), "STATUS", "Real Time Status", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); - LightIntensityNP.np[0].max = 255; - LightIntensityNP.np[0].value = 100; + LightIntensityNP[0].setMax(255); + LightIntensityNP[0].setValue(100); // Heater SetHeaterNP[Heat].fill( "Heater", "PWM", "%.2f", 0, 150, 50, 0); @@ -114,9 +114,7 @@ bool WandererCoverV4EC::updateProperties() LOG_INFO("New firmware available!"); } - defineProperty(&LightSP); - defineProperty(&LightIntensityNP); - defineProperty(&ParkCapSP); + defineProperty(DataNP); defineProperty(SetHeaterNP); defineProperty(CloseSetNP); @@ -124,17 +122,14 @@ bool WandererCoverV4EC::updateProperties() } else { - - deleteProperty(LightSP.name); - deleteProperty(LightIntensityNP.name); - deleteProperty(ParkCapSP.name); deleteProperty(DataNP); deleteProperty(SetHeaterNP); deleteProperty(OpenSetNP); deleteProperty(CloseSetNP); } - updateLightBoxProperties(); + DI::updateProperties(); + LI::updateProperties(); return true; } @@ -144,9 +139,7 @@ bool WandererCoverV4EC::updateProperties() void WandererCoverV4EC::ISGetProperties(const char *dev) { INDI::DefaultDevice::ISGetProperties(dev); - - // Get Light box properties - isGetLightBoxProperties(dev); + LI::ISGetProperties(dev); } //////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -154,8 +147,7 @@ void WandererCoverV4EC::ISGetProperties(const char *dev) //////////////////////////////////////////////////////////////////////////////////////////////////////// bool WandererCoverV4EC::ISSnoopDevice(XMLEle *root) { - snoopLightBox(root); - + LI::snoop(root); return INDI::DefaultDevice::ISSnoopDevice(root); } @@ -254,19 +246,20 @@ void WandererCoverV4EC::updateData(double closesetread, double opensetread, doub DataNP.setState(IPS_OK); DataNP.apply(); - auto prevParked = ParkCapS[CAP_PARK].s == ISS_ON; - auto prevState = ParkCapSP.s; + auto prevParked = ParkCapSP[CAP_PARK].getState() == ISS_ON; + auto prevState = ParkCapSP.getState(); - ParkCapS[CAP_PARK].s = (positionread - 10 <= closesetread) ? ISS_ON : ISS_OFF; - ParkCapS[CAP_UNPARK].s = (positionread + 10 >= opensetread) ? ISS_ON : ISS_OFF; - ParkCapSP.s = (ParkCapS[CAP_PARK].s == ISS_ON || ParkCapS[CAP_UNPARK].s == ISS_ON) ? IPS_OK : IPS_IDLE; + ParkCapSP[CAP_PARK].setState((positionread - 10 <= closesetread) ? ISS_ON : ISS_OFF); + ParkCapSP[CAP_UNPARK].setState((positionread + 10 >= opensetread) ? ISS_ON : ISS_OFF); + ParkCapSP.setState((ParkCapSP[CAP_PARK].getState() == ISS_ON + || ParkCapSP[CAP_UNPARK].getState() == ISS_ON) ? IPS_OK : IPS_IDLE); - auto currentParked = ParkCapS[CAP_PARK].s == ISS_ON; - auto currentState = ParkCapSP.s; + auto currentParked = ParkCapSP[CAP_PARK].getState() == ISS_ON; + auto currentState = ParkCapSP.getState(); // Only update on state changes if ((prevParked != currentParked) || (prevState != currentState)) - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); } //////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -274,7 +267,7 @@ void WandererCoverV4EC::updateData(double closesetread, double opensetread, doub //////////////////////////////////////////////////////////////////////////////////////////////////////// bool WandererCoverV4EC::ISNewText(const char *dev, const char *name, char *texts[], char *names[], int n) { - if (processLightBoxText(dev, name, texts, names, n)) + if (LI::processText(dev, name, texts, names, n)) return true; return INDI::DefaultDevice::ISNewText(dev, name, texts, names, n); @@ -285,10 +278,10 @@ bool WandererCoverV4EC::ISNewText(const char *dev, const char *name, char *texts //////////////////////////////////////////////////////////////////////////////////////////////////////// bool WandererCoverV4EC::ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { - if (processLightBoxSwitch(dev, name, states, names, n)) + if (LI::processSwitch(dev, name, states, names, n)) return true; - if (processDustCapSwitch(dev, name, states, names, n)) + if (DI::processSwitch(dev, name, states, names, n)) return true; return DefaultDevice::ISNewSwitch(dev, name, states, names, n); @@ -299,7 +292,7 @@ bool WandererCoverV4EC::ISNewSwitch(const char *dev, const char *name, ISState * //////////////////////////////////////////////////////////////////////////////////////////////////////// bool WandererCoverV4EC::ISNewNumber(const char * dev, const char * name, double values[], char * names[], int n) { - if (processLightBoxNumber(dev, name, values, names, n)) + if (LI::processNumber(dev, name, values, names, n)) return true; if (dev && !strcmp(dev, getDeviceName())) @@ -419,16 +412,16 @@ bool WandererCoverV4EC::SetLightBoxBrightness(uint16_t value) if(value > 0) { // Only change if already enabled. - if (LightS[INDI_ENABLED].s == ISS_ON) + if (LightSP[INDI_ENABLED].getState() == ISS_ON) rc = sendCommand(std::to_string(value)); } else { EnableLightBox(false); - LightS[INDI_ENABLED].s = ISS_OFF; - LightS[INDI_DISABLED].s = ISS_ON; - LightSP.s = IPS_IDLE; - IDSetSwitch(&LightSP, nullptr); + LightSP[INDI_ENABLED].setState(ISS_OFF); + LightSP[INDI_DISABLED].setState(ISS_ON); + LightSP.setState(IPS_IDLE); + LightSP.apply(); } return rc; @@ -443,7 +436,7 @@ bool WandererCoverV4EC::EnableLightBox(bool enable) if(!enable) rc = sendCommand("9999"); else - rc = sendCommand(std::to_string(static_cast(LightIntensityN[0].value))); + rc = sendCommand(std::to_string(static_cast(LightIntensityNP[0].getValue()))); return rc; } @@ -537,6 +530,5 @@ bool WandererCoverV4EC::saveConfigItems(FILE * fp) CloseSetNP.save(fp); OpenSetNP.save(fp); - return saveLightBoxConfigItems(fp); + return LI::saveConfigItems(fp); } - diff --git a/drivers/focuser/alluna_tcs2.cpp b/drivers/focuser/alluna_tcs2.cpp index 2266998195..e15ee5575e 100644 --- a/drivers/focuser/alluna_tcs2.cpp +++ b/drivers/focuser/alluna_tcs2.cpp @@ -32,7 +32,7 @@ // create an instance of this driver static std::unique_ptr allunaTCS2(new AllunaTCS2 ()); -AllunaTCS2::AllunaTCS2() : DustCapInterface() +AllunaTCS2::AllunaTCS2() : DustCapInterface(this) { LOG_DEBUG("Init AllunaTCS2"); // Let's specify the driver version @@ -53,7 +53,7 @@ AllunaTCS2::AllunaTCS2() : DustCapInterface() bool AllunaTCS2::initProperties() { INDI::Focuser::initProperties(); - INDI::DustCapInterface::initDustCapProperties(getDeviceName(), DUSTCOVER_TAB); + DI::initProperties(DUSTCOVER_TAB); // Focuser temperature / ambient temperature, ekos uses first number of "FOCUS_TEMPERATURE" property @@ -61,7 +61,7 @@ bool AllunaTCS2::initProperties() TemperatureNP[1].fill("TEMPERATURE_PRIMARY", "Primary Temp [C]", "%6.2f", -100, 100, 0, 0); TemperatureNP[2].fill("TEMPERATURE_SECONDARY", "Secondary Temp [C]", "%6.2f", -100, 100, 0, 0); TemperatureNP[3].fill("HUMIDITY", "Humidity [%]", "%6.2f", 0, 100, 0, 0); - TemperatureNP.fill(getDeviceName(),"FOCUS_TEMPERATURE", "Climate",CLIMATE_TAB, IP_RO, 0, IPS_IDLE); + TemperatureNP.fill(getDeviceName(), "FOCUS_TEMPERATURE", "Climate", CLIMATE_TAB, IP_RO, 0, IPS_IDLE); // Climate control ClimateControlSP[AUTO].fill("CLIMATE_AUTO", "On", ISS_OFF); @@ -74,7 +74,8 @@ bool AllunaTCS2::initProperties() SecondaryDewHeaterSP[ON].fill("SECONDARY_HEATER_ON", "On", ISS_OFF); SecondaryDewHeaterSP[OFF].fill("SECONDARY_HEATER_OFF", "Off", ISS_ON); - SecondaryDewHeaterSP.fill(getDeviceName(), "SECONDARY_HEATER", "Heat secondary", CLIMATE_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); + SecondaryDewHeaterSP.fill(getDeviceName(), "SECONDARY_HEATER", "Heat secondary", CLIMATE_TAB, IP_RW, ISR_1OFMANY, 60, + IPS_IDLE); FanPowerNP[0].fill("FANPOWER", "Fan power [130..255]", "%3.0f", 130, 255, 1, 255); FanPowerNP.fill(getDeviceName(), "FANPOWER", "Fan Power", CLIMATE_TAB, IP_RW, 60, IPS_IDLE); @@ -115,7 +116,6 @@ const char *AllunaTCS2::getDefaultName() bool AllunaTCS2::updateProperties() { - LOG_INFO("updateProperties called"); INDI::Focuser::updateProperties(); if (isConnected()) @@ -152,7 +152,7 @@ bool AllunaTCS2::updateProperties() defineProperty(FanPowerNP); // Cover - defineProperty(&ParkCapSP); + DI::updateProperties(); LOG_INFO("AllunaTCS2 is ready."); } @@ -168,7 +168,7 @@ bool AllunaTCS2::updateProperties() deleteProperty(SecondaryDewHeaterSP); deleteProperty(FanPowerNP); - deleteProperty(ParkCapSP.name); + DI::updateProperties(); } return true; @@ -190,15 +190,18 @@ bool AllunaTCS2::Handshake() bool AllunaTCS2::sendCommand(const char * cmd, char * res, int cmd_len, int res_len) { - if (tcs.try_lock() ) { - bool result; - result = sendCommandNoLock(cmd, res, cmd_len, res_len); - tcs.unlock(); - return result; - } else { - LOG_INFO("sendCommand: lock failed, abort"); - return false; - } + if (tcs.try_lock() ) + { + bool result; + result = sendCommandNoLock(cmd, res, cmd_len, res_len); + tcs.unlock(); + return result; + } + else + { + LOG_INFO("sendCommand: lock failed, abort"); + return false; + } } @@ -233,10 +236,13 @@ bool AllunaTCS2::sendCommandNoLock(const char * cmd, char * res, int cmd_len, in if (res == nullptr) return true; - if (res_len > 0) { + if (res_len > 0) + { LOG_DEBUG("sendCommand: Read Answer Bytes"); rc = tty_read(PortFD, res, res_len, DRIVER_TIMEOUT, &nbytes_read); - } else { + } + else + { LOG_DEBUG("sendCommand: Read Answer String"); rc = tty_nread_section(PortFD, res, DRIVER_LEN, DRIVER_STOP_CHAR, DRIVER_TIMEOUT, &nbytes_read); } @@ -269,7 +275,8 @@ bool AllunaTCS2::sendCommandOnly(const char * cmd, int cmd_len) { int nbytes_written = 0, rc = -1; - if (! tcs.try_lock() ) { + if (! tcs.try_lock() ) + { LOGF_INFO("sendCommandOnly: %s: lock failed, abort", cmd); return false; } @@ -352,20 +359,14 @@ void AllunaTCS2::hexDump(char * buf, const char * data, int size) buf[3 * size - 1] = '\0'; } -// client asks for list of all properties -void AllunaTCS2::ISGetProperties(const char *dev) -{ - INDI::Focuser::ISGetProperties(dev); - LOG_INFO("ISGetProperties called"); - // FIXME: do something like upclass does with controller class -} - // client wants to change switch value (i.e. click on switch in GUI) bool AllunaTCS2::ISNewSwitch(const char * dev, const char * name, ISState * states, char * names[], int n) { + if (DI::processSwitch(dev, name, states, names, n)) + return true; + if (dev != nullptr && !strcmp(dev, getDeviceName()) ) - { - LOGF_INFO("ISNewSwitch called for %s", name); + { if (!strcmp(name, "CONNECTION") && !strcmp(names[0], "DISCONNECT") && states[0] == ISS_ON) { // turn off green Connected-LED @@ -398,40 +399,43 @@ bool AllunaTCS2::ISNewSwitch(const char * dev, const char * name, ISState * stat defineProperty(&FocusAbsPosNP); // read focuser position (depends on stepping mode) getPosition(); - LOGF_INFO("Processed %s",name); + LOGF_INFO("Processed %s", name); return true; } // Cover Switch? - if (!strcmp(name, ParkCapSP.name)) - { - // Find out which state is requested by the client - const char *actionName = IUFindOnSwitchName(states, names, n); - // Do nothing, if state is already what it should be - int currentCoverIndex = IUFindOnSwitchIndex(&ParkCapSP); - if (!strcmp(actionName, ParkCapS[currentCoverIndex].name)) - { - DEBUGF(INDI::Logger::DBG_SESSION, "Cover is already %s", ParkCapS[currentCoverIndex].label); - ParkCapSP.s = IPS_IDLE; - IDSetSwitch(&ParkCapSP, NULL); - return true; - } - - // Otherwise, let us update the switch state - IUUpdateSwitch(&ParkCapSP, states, names, n); - currentCoverIndex = IUFindOnSwitchIndex(&ParkCapSP); - if ( setDustCover() ) { - isCoverMoving = true; - DEBUGF(INDI::Logger::DBG_SESSION, "Cover is now %s", ParkCapS[currentCoverIndex].label); - ParkCapSP.s = IPS_OK; - IDSetSwitch(&ParkCapSP, NULL); - return true; - } else { - DEBUG(INDI::Logger::DBG_SESSION, "Cannot get lock, try again"); - ParkCapSP.s = IPS_ALERT; - IDSetSwitch(&ParkCapSP, NULL); - } - } + // if (!strcmp(name, ParkCapSP.name)) + // { + // // Find out which state is requested by the client + // const char *actionName = IUFindOnSwitchName(states, names, n); + // // Do nothing, if state is already what it should be + // int currentCoverIndex = IUFindOnSwitchIndex(&ParkCapSP); + // if (!strcmp(actionName, ParkCapS[currentCoverIndex].name)) + // { + // DEBUGF(INDI::Logger::DBG_SESSION, "Cover is already %s", ParkCapS[currentCoverIndex].label); + // ParkCapSP.s = IPS_IDLE; + // IDSetSwitch(&ParkCapSP, NULL); + // return true; + // } + + // // Otherwise, let us update the switch state + // IUUpdateSwitch(&ParkCapSP, states, names, n); + // currentCoverIndex = IUFindOnSwitchIndex(&ParkCapSP); + // if ( setDustCover() ) + // { + // isCoverMoving = true; + // DEBUGF(INDI::Logger::DBG_SESSION, "Cover is now %s", ParkCapS[currentCoverIndex].label); + // ParkCapSP.s = IPS_OK; + // IDSetSwitch(&ParkCapSP, NULL); + // return true; + // } + // else + // { + // DEBUG(INDI::Logger::DBG_SESSION, "Cannot get lock, try again"); + // ParkCapSP.s = IPS_ALERT; + // IDSetSwitch(&ParkCapSP, NULL); + // } + // } // Climate Control Switch? if (ClimateControlSP.isNameMatch(name)) @@ -442,21 +446,24 @@ bool AllunaTCS2::ISNewSwitch(const char * dev, const char * name, ISState * stat int currentClimateControlIndex = ClimateControlSP.findOnSwitchIndex(); if (ClimateControlSP[currentClimateControlIndex].isNameMatch(actionName)) { - DEBUGF(INDI::Logger::DBG_SESSION, "Climate Control is already %s", ClimateControlSP[currentClimateControlIndex].label); - ClimateControlSP.setState(IPS_IDLE); - ClimateControlSP.apply(); - return true; + DEBUGF(INDI::Logger::DBG_SESSION, "Climate Control is already %s", ClimateControlSP[currentClimateControlIndex].label); + ClimateControlSP.setState(IPS_IDLE); + ClimateControlSP.apply(); + return true; } // Otherwise, let us update the switch state ClimateControlSP.update(states, names, n); currentClimateControlIndex = ClimateControlSP.findOnSwitchIndex(); - if ( setClimateControl((currentClimateControlIndex==AUTO) ? MANUAL: AUTO) ) { + if ( setClimateControl((currentClimateControlIndex == AUTO) ? MANUAL : AUTO) ) + { DEBUGF(INDI::Logger::DBG_SESSION, "ClimateControl is now %s", ClimateControlSP[currentClimateControlIndex].label); ClimateControlSP.setState(IPS_OK); ClimateControlSP.apply(); return true; - } else { + } + else + { DEBUG(INDI::Logger::DBG_SESSION, "Cannot get lock, try again"); ClimateControlSP.setState(IPS_ALERT); ClimateControlSP.apply(); @@ -472,21 +479,24 @@ bool AllunaTCS2::ISNewSwitch(const char * dev, const char * name, ISState * stat int currentPrimaryDewHeaterIndex = PrimaryDewHeaterSP.findOnSwitchIndex(); if (PrimaryDewHeaterSP[currentPrimaryDewHeaterIndex].isNameMatch(actionName)) { - DEBUGF(INDI::Logger::DBG_SESSION, "PrimaryDewHeater is already %s", PrimaryDewHeaterSP[currentPrimaryDewHeaterIndex].label); - PrimaryDewHeaterSP.setState(IPS_IDLE); - PrimaryDewHeaterSP.apply(); - return true; + DEBUGF(INDI::Logger::DBG_SESSION, "PrimaryDewHeater is already %s", PrimaryDewHeaterSP[currentPrimaryDewHeaterIndex].label); + PrimaryDewHeaterSP.setState(IPS_IDLE); + PrimaryDewHeaterSP.apply(); + return true; } // Otherwise, let us update the switch state PrimaryDewHeaterSP.update(states, names, n); currentPrimaryDewHeaterIndex = PrimaryDewHeaterSP.findOnSwitchIndex(); - if ( setPrimaryDewHeater((currentPrimaryDewHeaterIndex==OFF) ? ON:OFF) ) { + if ( setPrimaryDewHeater((currentPrimaryDewHeaterIndex == OFF) ? ON : OFF) ) + { DEBUGF(INDI::Logger::DBG_SESSION, "PrimaryDewHeater is now %s", PrimaryDewHeaterSP[currentPrimaryDewHeaterIndex].label); PrimaryDewHeaterSP.setState(IPS_OK); PrimaryDewHeaterSP.apply(); return true; - } else { + } + else + { DEBUG(INDI::Logger::DBG_SESSION, "Cannot get lock, try again"); PrimaryDewHeaterSP.setState(IPS_ALERT); PrimaryDewHeaterSP.apply(); @@ -502,21 +512,26 @@ bool AllunaTCS2::ISNewSwitch(const char * dev, const char * name, ISState * stat int currentSecondaryDewHeaterIndex = SecondaryDewHeaterSP.findOnSwitchIndex(); if (SecondaryDewHeaterSP[currentSecondaryDewHeaterIndex].isNameMatch(actionName)) { - DEBUGF(INDI::Logger::DBG_SESSION, "SecondaryDewHeater is already %s", SecondaryDewHeaterSP[currentSecondaryDewHeaterIndex].label); - SecondaryDewHeaterSP.setState(IPS_IDLE); - SecondaryDewHeaterSP.apply(); - return true; + DEBUGF(INDI::Logger::DBG_SESSION, "SecondaryDewHeater is already %s", + SecondaryDewHeaterSP[currentSecondaryDewHeaterIndex].label); + SecondaryDewHeaterSP.setState(IPS_IDLE); + SecondaryDewHeaterSP.apply(); + return true; } // Otherwise, let us update the switch state SecondaryDewHeaterSP.update(states, names, n); currentSecondaryDewHeaterIndex = SecondaryDewHeaterSP.findOnSwitchIndex(); - if ( setSecondaryDewHeater((currentSecondaryDewHeaterIndex==OFF) ? ON: OFF) ) { - DEBUGF(INDI::Logger::DBG_SESSION, "SecondaryDewHeater is now %s", SecondaryDewHeaterSP[currentSecondaryDewHeaterIndex].label); + if ( setSecondaryDewHeater((currentSecondaryDewHeaterIndex == OFF) ? ON : OFF) ) + { + DEBUGF(INDI::Logger::DBG_SESSION, "SecondaryDewHeater is now %s", + SecondaryDewHeaterSP[currentSecondaryDewHeaterIndex].label); SecondaryDewHeaterSP.setState(IPS_OK); SecondaryDewHeaterSP.apply(); return true; - } else { + } + else + { DEBUG(INDI::Logger::DBG_SESSION, "Cannot get lock, try again"); SecondaryDewHeaterSP.setState(IPS_ALERT); SecondaryDewHeaterSP.apply(); @@ -532,16 +547,15 @@ bool AllunaTCS2::ISNewSwitch(const char * dev, const char * name, ISState * stat // client wants to change number value bool AllunaTCS2::ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) { - LOGF_INFO("ISNewSwitch called for %s\n", name); if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { // Fan Power if (FanPowerNP.isNameMatch(name)) { // Try to update settings - int power=values[0]; - if (power>255) power=255; - if (power<0) power=0; + int power = values[0]; + if (power > 255) power = 255; + if (power < 0) power = 0; if (setFanPower(power)) { FanPowerNP.update(values, names, n); @@ -562,11 +576,11 @@ bool AllunaTCS2::ISNewNumber(const char *dev, const char *name, double values[], IPState AllunaTCS2::MoveAbsFocuser(uint32_t targetTicks) { - LOGF_INFO("MoveAbsFocuser %d called", targetTicks); char cmd[DRIVER_LEN]; snprintf(cmd, DRIVER_LEN, "FocuserGoTo %d\r\n", targetTicks); bool rc = sendCommandOnly(cmd); - if (rc == false) { + if (rc == false) + { LOGF_ERROR("MoveAbsFocuser %d failed", targetTicks); return IPS_ALERT; } @@ -588,12 +602,12 @@ bool AllunaTCS2::AbortFocuser() void AllunaTCS2::TimerHit() { - LOG_INFO("TimerHit"); if (!isConnected()) - return; // No need to reset timer if we are not connected anymore + return; // try to read temperature, if it works no lock was present - if (getTemperature() && getFanPower()) { + if (getTemperature() && getFanPower()) + { SetTimer(getCurrentPollingPeriod()); return; } @@ -608,7 +622,8 @@ void AllunaTCS2::TimerHit() { int32_t pos; - if ( res[1] == '#') { + if ( res[1] == '#') + { switch (res[0]) { case 'A': // aux1 on (primary mirror heating) @@ -655,7 +670,8 @@ void AllunaTCS2::TimerHit() pos = 1e6; sscanf(res, "K#%d", &pos); //LOGF_INFO("TimerHit: new pos (%d)",pos); - if (pos != 1e6) { + if (pos != 1e6) + { FocusAbsPosN[0].value = pos; } FocusAbsPosNP.s = IPS_BUSY; @@ -673,22 +689,22 @@ void AllunaTCS2::TimerHit() receiveDone(); break; case 'O': // cover started moving - LOG_INFO("TimerHit: cover started moving"); - ParkCapSP.s= IPS_BUSY; - IDSetSwitch(&ParkCapSP, NULL); + ParkCapSP.setState(IPS_BUSY); + ParkCapSP.apply(); break; case 'H': // cover stopped moving - LOG_INFO("TimetHit: cover stopped moving"); isCoverMoving = false; receiveDone(); - ParkCapSP.s= IPS_OK; - IDSetSwitch(&ParkCapSP, NULL); + ParkCapSP.setState(IPS_OK); + ParkCapSP.apply(); break; default: // unexpected output LOGF_INFO("TimerHit: unexpected response (%s)", res); - } - } else { - LOGF_INFO("TimerHit: unexpected response (%s)", res); + } + } + else + { + LOGF_INFO("TimerHit: unexpected response (%s)", res); } actionInProgress = isFocuserMoving || isCoverMoving; } @@ -735,54 +751,57 @@ bool AllunaTCS2::getTemperature() std::chrono::duration seconds = std::chrono::system_clock::now() - last_temp_update; if ( !first_run && seconds.count() < 10 ) // update every 10 seconds { - if (tcs.try_lock()) { + if (tcs.try_lock()) + { tcs.unlock(); // we need to get lock, to make TimerHit behave the same when we block reading temperature return true; // return true, if we could get the lock - } else { + } + else + { return false; // return false, if we could not get the lock } } else if ( sendCommandOnly("GetTemperatures\n") ) { - TemperatureNP.setState(IPS_BUSY); - isGetTemperature = true; - - // expect and process device output while present - char res[DRIVER_LEN] = {0}; - float value; - - // read a line, if available - while (isGetTemperature && receiveNext(res)) - { - switch (res[0]) - { - case 'R': // ambient temperature value - sscanf(res, "R#%f", &value); - TemperatureNP[0].value = value; - break; - case 'S': // primary mirror temperature value - sscanf(res, "S#%f", &value); - TemperatureNP[1].value = value; - break; - case 'T': // secondary mirror temperature value - sscanf(res, "T#%f", &value); - TemperatureNP[2].value = value; - break; - case 'd': // ambient humidity value - sscanf(res, "d#%f", &value); - TemperatureNP[3].value = value; - receiveDone(); - isGetTemperature=false; - TemperatureNP.setState(IPS_OK); - TemperatureNP.apply(); // update clients - break; - default: // unexpected output - LOGF_ERROR("GetTemperatures: unexpected response (%s)", res); - } - } - first_run = false; - last_temp_update = std::chrono::system_clock::now(); - return true; + TemperatureNP.setState(IPS_BUSY); + isGetTemperature = true; + + // expect and process device output while present + char res[DRIVER_LEN] = {0}; + float value; + + // read a line, if available + while (isGetTemperature && receiveNext(res)) + { + switch (res[0]) + { + case 'R': // ambient temperature value + sscanf(res, "R#%f", &value); + TemperatureNP[0].value = value; + break; + case 'S': // primary mirror temperature value + sscanf(res, "S#%f", &value); + TemperatureNP[1].value = value; + break; + case 'T': // secondary mirror temperature value + sscanf(res, "T#%f", &value); + TemperatureNP[2].value = value; + break; + case 'd': // ambient humidity value + sscanf(res, "d#%f", &value); + TemperatureNP[3].value = value; + receiveDone(); + isGetTemperature = false; + TemperatureNP.setState(IPS_OK); + TemperatureNP.apply(); // update clients + break; + default: // unexpected output + LOGF_ERROR("GetTemperatures: unexpected response (%s)", res); + } + } + first_run = false; + last_temp_update = std::chrono::system_clock::now(); + return true; } return false; } @@ -821,38 +840,40 @@ bool AllunaTCS2::getDustCover() if (value == -1) return false; - DEBUGF(INDI::Logger::DBG_SESSION, "Cover status read to be %s (%d)", (value==1)?"open":"closed", value); - ParkCapS[CAP_UNPARK].s = (value==1)?ISS_ON:ISS_OFF; - ParkCapS[CAP_PARK ].s = (value!=1)?ISS_ON:ISS_OFF; - ParkCapSP.s = IPS_OK; + LOGF_DEBUG("Cover status read to be %s (%d)", (value == 1) ? "open" : "closed", value); + ParkCapSP[CAP_UNPARK].setState((value == 1) ? ISS_ON : ISS_OFF); + ParkCapSP[CAP_PARK ].setState((value != 1) ? ISS_ON : ISS_OFF); + ParkCapSP.setState(IPS_OK); return true; } IPState AllunaTCS2::ParkCap() { - if (ParkCapS[CAP_PARK ].s == ISS_OFF) { + if (ParkCapSP[CAP_PARK].getState() == ISS_OFF) + { if (setDustCover()) // toggle state of dust cover return IPS_BUSY; else return IPS_ALERT; - } else { - // Cover already parked, nothing to do - return IPS_OK; } + + // Cover already parked, nothing to do + return IPS_OK; } IPState AllunaTCS2::UnParkCap() { - if (ParkCapS[CAP_UNPARK].s == ISS_OFF) { + if (ParkCapSP[CAP_UNPARK].getState() == ISS_OFF) + { if (setDustCover()) // toggle state of dust cover return IPS_BUSY; else return IPS_ALERT; - } else { - // Cover already unparked, nothing to do - return IPS_OK; } + + // Cover already unparked, nothing to do + return IPS_OK; } @@ -877,7 +898,7 @@ bool AllunaTCS2::getStepping() // Set limits as per documentation FocusAbsPosN[0].max = (steppingMode == MICRO) ? 22400 : 1400; // 22400 in microstep mode, 1400 in speedstep mode - LOGF_INFO("readStepping: set max position to %d",(int)FocusAbsPosN[0].max); + LOGF_INFO("readStepping: set max position to %d", (int)FocusAbsPosN[0].max); return true; } @@ -885,9 +906,9 @@ bool AllunaTCS2::setStepping(SteppingMode mode) { int value; char cmd[DRIVER_LEN] = {0}; - steppingMode=mode; + steppingMode = mode; value = (mode == SPEED) ? 0 : 1; - LOGF_INFO("Setting stepping mode to: %s", (mode==SPEED)?"SPEED":"micro"); + LOGF_INFO("Setting stepping mode to: %s", (mode == SPEED) ? "SPEED" : "micro"); LOGF_INFO("Setting stepping mode to: %d", value); snprintf(cmd, DRIVER_LEN, "SetFocuserMode %d\n", value); return sendCommand(cmd); @@ -913,9 +934,10 @@ bool AllunaTCS2::getClimateControl() if (value == -1) return false; - DEBUGF(INDI::Logger::DBG_SESSION, "Climate Control status read to be %s (%d)", (value==1)?"automatic":"manual", value); - ClimateControlSP[AUTO ].setState((value==1)?ISS_ON:ISS_OFF); - ClimateControlSP[MANUAL].setState((value!=1)?ISS_ON:ISS_OFF); + DEBUGF(INDI::Logger::DBG_SESSION, "Climate Control status read to be %s (%d)", (value == 1) ? "automatic" : "manual", + value); + ClimateControlSP[AUTO ].setState((value == 1) ? ISS_ON : ISS_OFF); + ClimateControlSP[MANUAL].setState((value != 1) ? ISS_ON : ISS_OFF); ClimateControlSP.setState(IPS_OK); return true; @@ -943,9 +965,9 @@ bool AllunaTCS2::getPrimaryDewHeater() if (value == -1) return false; - DEBUGF(INDI::Logger::DBG_SESSION, "PrimaryDewHeater status read to be %s (%d)", (value==1)?"ON":"OFF", value); - PrimaryDewHeaterSP[ON ].setState((value==1)?ISS_ON:ISS_OFF); - PrimaryDewHeaterSP[OFF].setState((value!=1)?ISS_ON:ISS_OFF); + DEBUGF(INDI::Logger::DBG_SESSION, "PrimaryDewHeater status read to be %s (%d)", (value == 1) ? "ON" : "OFF", value); + PrimaryDewHeaterSP[ON ].setState((value == 1) ? ISS_ON : ISS_OFF); + PrimaryDewHeaterSP[OFF].setState((value != 1) ? ISS_ON : ISS_OFF); PrimaryDewHeaterSP.setState(IPS_OK); return true; @@ -973,9 +995,9 @@ bool AllunaTCS2::getSecondaryDewHeater() if (value == -1) return false; - DEBUGF(INDI::Logger::DBG_SESSION, "SecondaryDewHeater status read to be %s (%d)", (value==1)?"ON":"OFF", value); - SecondaryDewHeaterSP[ON ].setState((value==1)?ISS_ON:ISS_OFF); - SecondaryDewHeaterSP[OFF].setState((value!=1)?ISS_ON:ISS_OFF); + DEBUGF(INDI::Logger::DBG_SESSION, "SecondaryDewHeater status read to be %s (%d)", (value == 1) ? "ON" : "OFF", value); + SecondaryDewHeaterSP[ON ].setState((value == 1) ? ISS_ON : ISS_OFF); + SecondaryDewHeaterSP[OFF].setState((value != 1) ? ISS_ON : ISS_OFF); SecondaryDewHeaterSP.setState(IPS_OK); return true; @@ -1001,10 +1023,13 @@ bool AllunaTCS2::getFanPower() std::chrono::duration seconds = std::chrono::system_clock::now() - last_temp_update; if ( !first_run && seconds.count() < 30 ) // update every 30 seconds { - if (tcs.try_lock()) { + if (tcs.try_lock()) + { tcs.unlock(); // we need to get lock, to make TimerHit behave the same when we block reading temperature return true; // return true, if we could get the lock - } else { + } + else + { return false; // return false, if we could not get the lock } } @@ -1017,11 +1042,12 @@ bool AllunaTCS2::getFanPower() if (value == -1) return false; - if (value != (int)FanPowerNP[0].value) { - LOGF_INFO("FanPower read to be %d", value); - FanPowerNP[0].value = (double)value; - FanPowerNP.setState(IPS_OK); - FanPowerNP.apply(); + if (value != (int)FanPowerNP[0].value) + { + LOGF_INFO("FanPower read to be %d", value); + FanPowerNP[0].value = (double)value; + FanPowerNP.setState(IPS_OK); + FanPowerNP.apply(); } return true; } diff --git a/drivers/focuser/alluna_tcs2.h b/drivers/focuser/alluna_tcs2.h index f795bf6cdd..178d8005d7 100644 --- a/drivers/focuser/alluna_tcs2.h +++ b/drivers/focuser/alluna_tcs2.h @@ -36,7 +36,6 @@ class AllunaTCS2 : public INDI::Focuser, public INDI::DustCapInterface bool initProperties() override; bool updateProperties() override; - void ISGetProperties(const char *dev) override; bool ISNewSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) override; bool ISNewNumber(const char *dev, const char *name, double values[], char *names[], int n) override; @@ -80,7 +79,7 @@ class AllunaTCS2 : public INDI::Focuser, public INDI::DustCapInterface INDI::PropertySwitch SteppingModeSP{2}; typedef enum { MICRO = 1, SPEED = 0 } SteppingMode; - SteppingMode steppingMode=MICRO; + SteppingMode steppingMode = MICRO; /////////////////////////////////////////////////////////////////////////////// /// Read Data From Controller diff --git a/libs/indibase/defaultdevice.h b/libs/indibase/defaultdevice.h index 889be243de..73945447e6 100644 --- a/libs/indibase/defaultdevice.h +++ b/libs/indibase/defaultdevice.h @@ -570,6 +570,7 @@ class DefaultDevice : public ParentDevice friend class FilterInterface; friend class FocuserInterface; friend class WeatherInterface; + friend class LightBoxInterface; friend class OutputInterface; friend class InputInterface; friend class PowerInterface; diff --git a/libs/indibase/indidustcapinterface.cpp b/libs/indibase/indidustcapinterface.cpp index 4ff4ee9fd5..c238a9aa98 100644 --- a/libs/indibase/indidustcapinterface.cpp +++ b/libs/indibase/indidustcapinterface.cpp @@ -1,6 +1,6 @@ /* Dust Cap Interface - Copyright (C) 2015 Jasem Mutlaq (mutlaqja@ikarustech.com) + Copyright (C) 2015-2025 Jasem Mutlaq (mutlaqja@ikarustech.com) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -19,44 +19,83 @@ */ #include "indidustcapinterface.h" +#include "defaultdevice.h" #include namespace INDI { -void DustCapInterface::initDustCapProperties(const char *deviceName, const char *groupName) +///////////////////////////////////////////////////////////////////////////////////////////// +/// +///////////////////////////////////////////////////////////////////////////////////////////// +DustCapInterface::DustCapInterface(DefaultDevice *defaultDevice) : m_DefaultDevice(defaultDevice) { - strncpy(dustCapName, deviceName, MAXINDIDEVICE); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +/// +///////////////////////////////////////////////////////////////////////////////////////////// +void DustCapInterface::initProperties(const char *group, uint32_t capabilities) +{ + m_Capabilities = capabilities; // Open/Close cover - IUFillSwitch(&ParkCapS[CAP_PARK], "PARK", "Park", ISS_OFF); - IUFillSwitch(&ParkCapS[CAP_UNPARK], "UNPARK", "Unpark", ISS_OFF); - IUFillSwitchVector(&ParkCapSP, ParkCapS, 2, deviceName, "CAP_PARK", "Dust Cover", groupName, IP_RW, ISR_1OFMANY, 0, - IPS_IDLE); + ParkCapSP[CAP_PARK].fill("PARK", "Park", ISS_OFF); + ParkCapSP[CAP_UNPARK].fill("UNPARK", "Unpark", ISS_OFF); + ParkCapSP.fill(m_DefaultDevice->getDeviceName(), "CAP_PARK", "Dust Cover", group, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); + + // Abort motion + AbortCapSP[0].fill("ABORT", "Abort", ISS_OFF); + AbortCapSP.fill(m_DefaultDevice->getDeviceName(), "CAP_ABORT", "Motion", group, IP_RW, ISR_ATMOST1, 60, IPS_IDLE); +} + +///////////////////////////////////////////////////////////////////////////////////////////// +/// +///////////////////////////////////////////////////////////////////////////////////////////// +bool DustCapInterface::updateProperties() +{ + if (m_DefaultDevice->isConnected()) + { + m_DefaultDevice->defineProperty(ParkCapSP); + if (m_Capabilities & CAN_ABORT) + m_DefaultDevice->defineProperty(AbortCapSP); + } + else + { + m_DefaultDevice->deleteProperty(ParkCapSP); + if (m_Capabilities & CAN_ABORT) + m_DefaultDevice->deleteProperty(AbortCapSP); + } + + return true; } -bool DustCapInterface::processDustCapSwitch(const char *dev, const char *name, ISState *states, char *names[], - int n) +///////////////////////////////////////////////////////////////////////////////////////////// +/// +///////////////////////////////////////////////////////////////////////////////////////////// +bool DustCapInterface::processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { INDI_UNUSED(dev); // Park/UnPark Dust Cover - if (!strcmp(ParkCapSP.name, name)) + if (ParkCapSP.isNameMatch(name)) { - int prevSwitch = IUFindOnSwitchIndex(&ParkCapSP); - IUUpdateSwitch(&ParkCapSP, states, names, n); - if (ParkCapS[CAP_PARK].s == ISS_ON) - ParkCapSP.s = ParkCap(); - else - ParkCapSP.s = UnParkCap(); - - if (ParkCapSP.s == IPS_ALERT) + auto prevSwitch = ParkCapSP.findOnSwitchIndex(); + ParkCapSP.update(states, names, n); + ParkCapSP.setState((ParkCapSP[CAP_PARK].getState() == ISS_ON) ? ParkCap() : UnParkCap()); + + if (ParkCapSP.getState() == IPS_ALERT) { - IUResetSwitch(&ParkCapSP); - ParkCapS[prevSwitch].s = ISS_ON; + ParkCapSP.reset(); + ParkCapSP[prevSwitch].setState(ISS_ON); } - - IDSetSwitch(&ParkCapSP, nullptr); + ParkCapSP.apply(); + return true; + } + else if (AbortCapSP.isNameMatch(name)) + { + AbortCapSP.setState(AbortCap()); + AbortCapSP.apply(); return true; } @@ -74,4 +113,10 @@ IPState DustCapInterface::UnParkCap() // Must be implemented by child class return IPS_ALERT; } + +IPState DustCapInterface::AbortCap() +{ + // Must be implemented by child class + return IPS_ALERT; +} } diff --git a/libs/indibase/indidustcapinterface.h b/libs/indibase/indidustcapinterface.h index a221f64006..0c7656a391 100644 --- a/libs/indibase/indidustcapinterface.h +++ b/libs/indibase/indidustcapinterface.h @@ -1,6 +1,6 @@ /* Dust Cap Interface - Copyright (C) 2015 Jasem Mutlaq (mutlaqja@ikarustech.com) + Copyright (C) 2015-2025 Jasem Mutlaq (mutlaqja@ikarustech.com) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -22,16 +22,20 @@ #include "indibase.h" #include "indidriver.h" +#include "indipropertyswitch.h" /** * \class DustCapInterface \brief Provides interface to implement remotely controlled dust cover - \e IMPORTANT: initDustCapProperties() must be called before any other function to initialize the Dust Cap properties. - - \e IMPORTANT: processDustCapSwitch() must be called in your driver ISNewSwitch function. + \e IMPORTANT: initProperties() must be called before any other function to initialize the Dust Cap properties. + \e IMPORTANT: updateProperties() must be called in your driver updateProperties function. + \e IMPORTANT: processSwitch() must be called in your driver ISNewSwitch function. \author Jasem Mutlaq */ + +// Alias +using DI = INDI::DustCapInterface; namespace INDI { @@ -44,8 +48,15 @@ class DustCapInterface CAP_UNPARK }; + enum + { + CAN_ABORT = 1 << 0, /** Can the dust cap abort motion? */ + CAN_SET_POSITION = 1 << 1, /** Can the dust go to a specific angular position? UNUSED */ + CAN_SET_LIMITS = 1 << 2, /** Can the dust set the minimum and maximum ranges for Park and Unpark? UNUSED */ + } DustCapCapability; + protected: - DustCapInterface() = default; + DustCapInterface(DefaultDevice *device); virtual ~DustCapInterface() = default; /** @@ -60,20 +71,34 @@ class DustCapInterface */ virtual IPState UnParkCap(); + /** + * @brief Abort motion. Must be implemented by child. + * @return If command completed immediately, return IPS_OK. If command is in progress, return IPS_BUSY. If there is an error, return IPS_ALERT + */ + virtual IPState AbortCap(); + /** \brief Initialize dust cap properties. It is recommended to call this function within initProperties() of your primary device - \param deviceName Name of the primary device - \param groupName Group or tab name to be used to define focuser properties. + \param group Group or tab name to be used to define properties. + \param capabilities Any additional capabilities the dust cap supports besides Parking and Unparking. */ - void initDustCapProperties(const char *deviceName, const char *groupName); + void initProperties(const char *group, uint32_t capabilities = 0); + + /** + * @brief updateProperties Defines or Delete properties based on default device connection status + * @return True if all is OK, false otherwise. + */ + bool updateProperties(); /** \brief Process dust cap switch properties */ - bool processDustCapSwitch(const char *dev, const char *name, ISState *states, char *names[], int n); + bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n); // Open/Close cover - ISwitchVectorProperty ParkCapSP; - ISwitch ParkCapS[2]; + INDI::PropertySwitch ParkCapSP {2}; + // Abort Motion + INDI::PropertySwitch AbortCapSP {1}; private: - char dustCapName[MAXINDIDEVICE]; + DefaultDevice *m_DefaultDevice { nullptr }; + uint32_t m_Capabilities {0}; }; } diff --git a/libs/indibase/indilightboxinterface.cpp b/libs/indibase/indilightboxinterface.cpp index 4093abbfcd..7836acba23 100644 --- a/libs/indibase/indilightboxinterface.cpp +++ b/libs/indibase/indilightboxinterface.cpp @@ -27,177 +27,193 @@ namespace INDI { -LightBoxInterface::LightBoxInterface(DefaultDevice *device, bool isDimmable) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +LightBoxInterface::LightBoxInterface(DefaultDevice *device) : m_DefaultDevice(device) { - this->device = device; - this->isDimmable = isDimmable; - FilterIntensityN = nullptr; - currentFilterSlot = 0; } +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// LightBoxInterface::~LightBoxInterface() { } -void LightBoxInterface::initLightBoxProperties(const char *deviceName, const char *groupName) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +void LightBoxInterface::initProperties(const char *group, uint32_t capabilities) { + m_Capabilities = capabilities; // Turn on/off light - IUFillSwitch(&LightS[FLAT_LIGHT_ON], "FLAT_LIGHT_ON", "On", ISS_OFF); - IUFillSwitch(&LightS[FLAT_LIGHT_OFF], "FLAT_LIGHT_OFF", "Off", ISS_ON); - IUFillSwitchVector(&LightSP, LightS, 2, deviceName, "FLAT_LIGHT_CONTROL", "Flat Light", groupName, IP_RW, - ISR_1OFMANY, 0, IPS_IDLE); + LightSP[FLAT_LIGHT_ON].fill("FLAT_LIGHT_ON", "On", ISS_OFF); + LightSP[FLAT_LIGHT_OFF].fill("FLAT_LIGHT_OFF", "Off", ISS_ON); + LightSP.fill(m_DefaultDevice->getDeviceName(), "FLAT_LIGHT_CONTROL", "Flat Light", group, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); // Light Intensity - IUFillNumber(&LightIntensityN[0], "FLAT_LIGHT_INTENSITY_VALUE", "Value", "%.f", 0, 255, 10, 0); - IUFillNumberVector(&LightIntensityNP, LightIntensityN, 1, deviceName, "FLAT_LIGHT_INTENSITY", "Brightness", - groupName, IP_RW, 0, IPS_IDLE); + LightIntensityNP[0].fill("FLAT_LIGHT_INTENSITY_VALUE", "Value", "%.f", 0, 255, 10, 0); + LightIntensityNP.fill(m_DefaultDevice->getDeviceName(), "FLAT_LIGHT_INTENSITY", "Brightness", group, IP_RW, 0, IPS_IDLE); // Active Devices - IUFillText(&ActiveDeviceT[0], "ACTIVE_FILTER", "Filter", "Filter Simulator"); - IUFillTextVector(&ActiveDeviceTP, ActiveDeviceT, 1, deviceName, "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, - IP_RW, 60, IPS_IDLE); + ActiveDeviceTP[0].fill("ACTIVE_FILTER", "Filter", "Filter Simulator"); + ActiveDeviceTP.fill(m_DefaultDevice->getDeviceName(), "ACTIVE_DEVICES", "Snoop devices", OPTIONS_TAB, IP_RW, 60, IPS_IDLE); + ActiveDeviceTP.load(); - // Filter duration - IUFillNumberVector(&FilterIntensityNP, nullptr, 0, deviceName, "FLAT_LIGHT_FILTER_INTENSITY", "Filter Intensity", - "Preset", IP_RW, 60, IPS_OK); + // Filter Intensities + FilterIntensityNP.fill(m_DefaultDevice->getDeviceName(), "FLAT_LIGHT_FILTER_INTENSITY", "Filter Intensity", "Preset", IP_RW, + 60, IPS_IDLE); - IDSnoopDevice(ActiveDeviceT[0].text, "FILTER_SLOT"); - IDSnoopDevice(ActiveDeviceT[0].text, "FILTER_NAME"); + IDSnoopDevice(ActiveDeviceTP[0].getText(), "FILTER_SLOT"); + IDSnoopDevice(ActiveDeviceTP[0].getText(), "FILTER_NAME"); } -void LightBoxInterface::isGetLightBoxProperties(const char *deviceName) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +void LightBoxInterface::ISGetProperties(const char *deviceName) { INDI_UNUSED(deviceName); - - device->defineProperty(&ActiveDeviceTP); - char errmsg[MAXRBUF]; - IUReadConfig(nullptr, device->getDeviceName(), "ACTIVE_DEVICES", 1, errmsg); + m_DefaultDevice->defineProperty(ActiveDeviceTP); } -bool LightBoxInterface::updateLightBoxProperties() +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +bool LightBoxInterface::updateProperties() { - if (device->isConnected() == false) + if (m_DefaultDevice->isConnected()) { - if (FilterIntensityN) - { - device->deleteProperty(FilterIntensityNP.name); - FilterIntensityNP.nnp = 0; - free (FilterIntensityN); - FilterIntensityN = nullptr; - } + m_DefaultDevice->defineProperty(LightSP); + m_DefaultDevice->defineProperty(LightIntensityNP); + } + else + { + m_DefaultDevice->deleteProperty(LightSP); + m_DefaultDevice->deleteProperty(LightIntensityNP); + + if (FilterIntensityNP.count() > 0) + m_DefaultDevice->deleteProperty(FilterIntensityNP); } return true; } -bool LightBoxInterface::processLightBoxSwitch(const char *dev, const char *name, ISState *states, char *names[], - int n) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +bool LightBoxInterface::processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n) { - if (strcmp(dev, device->getDeviceName()) == 0) - { - // Light - if (!strcmp(LightSP.name, name)) - { - int prevIndex = IUFindOnSwitchIndex(&LightSP); - IUUpdateSwitch(&LightSP, states, names, n); - bool rc = EnableLightBox(LightS[FLAT_LIGHT_ON].s == ISS_ON ? true : false); - - LightSP.s = rc ? IPS_OK : IPS_ALERT; - - if (!rc) - { - IUResetSwitch(&LightSP); - LightS[prevIndex].s = ISS_ON; - } + if (strcmp(dev, m_DefaultDevice->getDeviceName())) + return false; - IDSetSwitch(&LightSP, nullptr); + // Light + if (LightSP.isNameMatch(name)) + { + auto prevIndex = LightSP.findOnSwitchIndex(); + LightSP.update(states, names, n); + auto rc = EnableLightBox(LightSP[FLAT_LIGHT_ON].getState() == ISS_ON ? true : false); + LightSP.setState(rc ? IPS_OK : IPS_ALERT); - return true; + if (!rc) + { + LightSP.reset(); + LightSP[prevIndex].setState(ISS_ON); } + + LightSP.apply(); + return true; } return false; } -bool LightBoxInterface::processLightBoxNumber(const char *dev, const char *name, double values[], char *names[], - int n) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +bool LightBoxInterface::processNumber(const char *dev, const char *name, double values[], char *names[], int n) { - if (strcmp(dev, device->getDeviceName()) == 0) - { - // Light Intensity - if (!strcmp(LightIntensityNP.name, name)) - { - double prevValue = LightIntensityN[0].value; - IUUpdateNumber(&LightIntensityNP, values, names, n); - - bool rc = SetLightBoxBrightness(LightIntensityN[0].value); - if (rc) - LightIntensityNP.s = IPS_OK; - else - { - LightIntensityN[0].value = prevValue; - LightIntensityNP.s = IPS_ALERT; - } - - IDSetNumber(&LightIntensityNP, nullptr); + if (strcmp(dev, m_DefaultDevice->getDeviceName())) + return false; - return true; - } + // Light Intensity + if (LightIntensityNP.isNameMatch(name)) + { + auto prevValue = LightIntensityNP[0].getValue(); + LightIntensityNP.update(values, names, n); - if (!strcmp(FilterIntensityNP.name, name)) + bool rc = SetLightBoxBrightness(LightIntensityNP[0].getValue()); + if (rc) + LightIntensityNP.setState(IPS_OK); + else { - if (FilterIntensityN == nullptr) - { - for (int i = 0; i < n; i++) - addFilterDuration(names[i], values[i]); + LightIntensityNP[0].setValue(prevValue); + LightIntensityNP.setState(IPS_ALERT); + } - device->defineProperty(&FilterIntensityNP); + LightIntensityNP.apply(); + return true; + } - return true; - } + if (FilterIntensityNP.isNameMatch(name)) + { + // If this is first time, we add the filters + if (FilterIntensityNP.isEmpty()) + { + for (int i = 0; i < n; i++) + addFilterDuration(names[i], values[i]); - IUUpdateNumber(&FilterIntensityNP, values, names, n); - FilterIntensityNP.s = IPS_OK; - IDSetNumber(&FilterIntensityNP, nullptr); + m_DefaultDevice->defineProperty(FilterIntensityNP); return true; } + + FilterIntensityNP.update(values, names, n); + FilterIntensityNP.setState(IPS_OK); + FilterIntensityNP.apply(); + m_DefaultDevice->saveConfig(FilterIntensityNP); + return true; } return false; } -bool LightBoxInterface::processLightBoxText(const char *dev, const char *name, char *texts[], char *names[], - int n) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +bool LightBoxInterface::processText(const char *dev, const char *name, char *texts[], char *names[], int n) { - if (strcmp(dev, device->getDeviceName()) == 0) + if (strcmp(dev, m_DefaultDevice->getDeviceName())) + return false; + + if (ActiveDeviceTP.isNameMatch(name)) { - if (!strcmp(name, ActiveDeviceTP.name)) - { - ActiveDeviceTP.s = IPS_OK; - IUUpdateText(&ActiveDeviceTP, texts, names, n); - // Update client display - IDSetText(&ActiveDeviceTP, nullptr); + ActiveDeviceTP.setState(IPS_OK); + ActiveDeviceTP.update(texts, names, n); + // Update client display + ActiveDeviceTP.apply(); + m_DefaultDevice->saveConfig(ActiveDeviceTP); - if (strlen(ActiveDeviceT[0].text) > 0) - { - IDSnoopDevice(ActiveDeviceT[0].text, "FILTER_SLOT"); - IDSnoopDevice(ActiveDeviceT[0].text, "FILTER_NAME"); - } - // If filter removed, remove presets - else - { - device->deleteProperty(FilterIntensityNP.name); - FilterIntensityNP.nnp = 0; - free(FilterIntensityN); - FilterIntensityN = nullptr; - } - return true; + if (!ActiveDeviceTP[0].isEmpty()) + { + IDSnoopDevice(ActiveDeviceTP[0].getText(), "FILTER_SLOT"); + IDSnoopDevice(ActiveDeviceTP[0].text, "FILTER_NAME"); } + // If filter removed, remove presets + else + { + m_DefaultDevice->deleteProperty(FilterIntensityNP); + } + return true; } + return false; } +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// bool LightBoxInterface::EnableLightBox(bool enable) { INDI_UNUSED(enable); @@ -205,6 +221,9 @@ bool LightBoxInterface::EnableLightBox(bool enable) return false; } +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// bool LightBoxInterface::SetLightBoxBrightness(uint16_t value) { INDI_UNUSED(value); @@ -212,9 +231,13 @@ bool LightBoxInterface::SetLightBoxBrightness(uint16_t value) return false; } -bool LightBoxInterface::snoopLightBox(XMLEle *root) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +bool LightBoxInterface::snoop(XMLEle *root) { - if (isDimmable == false) + // If dimming not supported, we return + if (!(m_Capabilities & CAN_DIM)) return false; XMLEle *ep = nullptr; @@ -226,13 +249,14 @@ bool LightBoxInterface::snoopLightBox(XMLEle *root) if (!strcmp(propName, "FILTER_NAME")) { - if (FilterIntensityN != nullptr) + if (!FilterIntensityNP.isEmpty()) { - int snoopCounter = 0; + uint32_t snoopCounter = 0; bool isDifferent = false; for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0)) { - if (snoopCounter >= FilterIntensityNP.nnp || (strcmp(FilterIntensityN[snoopCounter].label, pcdataXMLEle(ep)))) + // If either count or labels are different, then mark it as such + if (snoopCounter >= FilterIntensityNP.count() || !FilterIntensityNP[snoopCounter].isLabelMatch(pcdataXMLEle(ep))) { isDifferent = true; break; @@ -241,17 +265,14 @@ bool LightBoxInterface::snoopLightBox(XMLEle *root) snoopCounter++; } - if (isDifferent == false && snoopCounter != FilterIntensityNP.nnp) + if (isDifferent == false && snoopCounter != FilterIntensityNP.count()) isDifferent = true; // Check if we have different FILTER_NAME // If identical, no need to recreate it. if (isDifferent) { - device->deleteProperty(FilterIntensityNP.name); - FilterIntensityNP.nnp = 0; - free(FilterIntensityN); - FilterIntensityN = nullptr; + m_DefaultDevice->deleteProperty(FilterIntensityNP); } else return false; @@ -260,15 +281,14 @@ bool LightBoxInterface::snoopLightBox(XMLEle *root) for (ep = nextXMLEle(root, 1); ep != nullptr; ep = nextXMLEle(root, 0)) addFilterDuration(pcdataXMLEle(ep), 0); - device->defineProperty(&FilterIntensityNP); - char errmsg[MAXRBUF]; - IUReadConfig(nullptr, device->getDeviceName(), "FLAT_LIGHT_FILTER_INTENSITY", 1, errmsg); + FilterIntensityNP.load(); + m_DefaultDevice->defineProperty(FilterIntensityNP); - if (device->isConnected()) + if (m_DefaultDevice->isConnected()) { - if (currentFilterSlot < FilterIntensityNP.nnp) + if (currentFilterSlot < FilterIntensityNP.count()) { - double duration = FilterIntensityN[currentFilterSlot].value; + auto duration = FilterIntensityNP[currentFilterSlot].getValue(); if (duration > 0) SetLightBoxBrightness(duration); } @@ -291,20 +311,19 @@ bool LightBoxInterface::snoopLightBox(XMLEle *root) } } - if (FilterIntensityN && device->isConnected()) + if (!FilterIntensityNP.isEmpty() && m_DefaultDevice->isConnected()) { - if (currentFilterSlot < FilterIntensityNP.nnp) + if (currentFilterSlot < FilterIntensityNP.count()) { - auto value = FilterIntensityN[currentFilterSlot].value; + auto value = FilterIntensityNP[currentFilterSlot].getValue(); if (value > 0) { if (SetLightBoxBrightness(value)) { - LightIntensityN[0].value = value; - LightIntensityNP.s = IPS_OK; - IDSetNumber(&LightIntensityNP, nullptr); + LightIntensityNP[0].setValue(value); + LightIntensityNP.setState(IPS_OK); + LightIntensityNP.apply(); } - } } } @@ -313,37 +332,32 @@ bool LightBoxInterface::snoopLightBox(XMLEle *root) return false; } +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// void LightBoxInterface::addFilterDuration(const char *filterName, uint16_t filterDuration) { - if (FilterIntensityN == nullptr) + // Ensure no duplicates + for (uint32_t i = 0; i < FilterIntensityNP.count(); i++) { - FilterIntensityN = (INumber *)malloc(sizeof(INumber)); - DEBUGDEVICE(device->getDeviceName(), Logger::DBG_DEBUG, "Filter intensity preset created."); + if (FilterIntensityNP[i].isNameMatch(filterName)) + return; } - else - { - // Ensure no duplicates - for (int i = 0; i < FilterIntensityNP.nnp; i++) - { - if (!strcmp(filterName, FilterIntensityN[i].name)) - return; - } - - FilterIntensityN = (INumber *)realloc(FilterIntensityN, (FilterIntensityNP.nnp + 1) * sizeof(INumber)); - } - - IUFillNumber(&FilterIntensityN[FilterIntensityNP.nnp], filterName, filterName, "%0.f", 0, LightIntensityN[0].max, - LightIntensityN[0].step, filterDuration); - FilterIntensityNP.nnp++; - FilterIntensityNP.np = FilterIntensityN; + INDI::WidgetNumber element; + element.fill(filterName, filterName, "%0.f", 0, LightIntensityNP[0].getMax(), LightIntensityNP[0].getStep(), + filterDuration); + FilterIntensityNP.push(std::move(element)); } -bool LightBoxInterface::saveLightBoxConfigItems(FILE *fp) +//////////////////////////////////////////////////////////////////////////////////////////////////////// +/// +//////////////////////////////////////////////////////////////////////////////////////////////////////// +bool LightBoxInterface::saveConfigItems(FILE *fp) { - IUSaveConfigText(fp, &ActiveDeviceTP); - if (FilterIntensityN != nullptr) - IUSaveConfigNumber(fp, &FilterIntensityNP); + ActiveDeviceTP.save(fp); + if (!FilterIntensityNP.isEmpty()) + FilterIntensityNP.save(fp); return true; } diff --git a/libs/indibase/indilightboxinterface.h b/libs/indibase/indilightboxinterface.h index fd41c726fe..c9b8cb6627 100644 --- a/libs/indibase/indilightboxinterface.h +++ b/libs/indibase/indilightboxinterface.h @@ -21,6 +21,9 @@ #pragma once #include "indibase.h" +#include "indipropertynumber.h" +#include "indipropertyswitch.h" +#include "indipropertytext.h" #include @@ -40,6 +43,10 @@ \e IMPORTANT: processLightBoxText() must be called in your driver ISNewText function. \author Jasem Mutlaq */ + +// Alias +using LI = INDI::LightBoxInterface; + namespace INDI { @@ -52,34 +59,39 @@ class LightBoxInterface FLAT_LIGHT_OFF }; + enum + { + CAN_DIM = 1 << 0, /** Does it support dimming? */ + } LightBoxCapability; + protected: - LightBoxInterface(DefaultDevice *device, bool isDimmable); + LightBoxInterface(DefaultDevice *device); virtual ~LightBoxInterface(); /** \brief Initialize light box properties. It is recommended to call this function within initProperties() of your primary device - \param deviceName Name of the primary device - \param groupName Group or tab name to be used to define light box properties. + \param group Group or tab name to be used to define light box properties. + \param capabilities Light box capabilities */ - void initLightBoxProperties(const char *deviceName, const char *groupNam); + void initProperties(const char *group, uint32_t capabilities); /** * @brief isGetLightBoxProperties Get light box properties * @param deviceName parent device name */ - void isGetLightBoxProperties(const char *deviceName); + void ISGetProperties(const char *deviceName); /** \brief Process light box switch properties */ - bool processLightBoxSwitch(const char *dev, const char *name, ISState *states, char *names[], int n); + bool processSwitch(const char *dev, const char *name, ISState *states, char *names[], int n); /** \brief Process light box number properties */ - bool processLightBoxNumber(const char *dev, const char *name, double values[], char *names[], int n); + bool processNumber(const char *dev, const char *name, double values[], char *names[], int n); /** \brief Process light box text properties */ - bool processLightBoxText(const char *dev, const char *name, char *texts[], char *names[], int n); + bool processText(const char *dev, const char *name, char *texts[], char *names[], int n); - bool updateLightBoxProperties(); - bool saveLightBoxConfigItems(FILE *fp); - bool snoopLightBox(XMLEle *root); + bool updateProperties(); + bool saveConfigItems(FILE *fp); + bool snoop(XMLEle *root); /** * @brief setBrightness Set light level. Must be implemented in the child class, if supported. @@ -96,25 +108,21 @@ class LightBoxInterface virtual bool EnableLightBox(bool enable); // Turn on/off light - ISwitchVectorProperty LightSP; - ISwitch LightS[2]; + INDI::PropertySwitch LightSP {2}; // Light Intensity - INumberVectorProperty LightIntensityNP; - INumber LightIntensityN[1]; + INDI::PropertyNumber LightIntensityNP {1}; // Active devices to snoop - ITextVectorProperty ActiveDeviceTP; - IText ActiveDeviceT[1] {}; + INDI::PropertyText ActiveDeviceTP {1}; - INumberVectorProperty FilterIntensityNP; - INumber *FilterIntensityN; + INDI::PropertyNumber FilterIntensityNP {0}; private: void addFilterDuration(const char *filterName, uint16_t filterDuration); - DefaultDevice *device; - uint8_t currentFilterSlot; - bool isDimmable; + DefaultDevice *m_DefaultDevice {nullptr}; + uint8_t currentFilterSlot {0}; + uint32_t m_Capabilities {0}; }; }