From 1da05e2bfb378963db9138c18af217d93d54f631 Mon Sep 17 00:00:00 2001 From: Salman Naheed Date: Thu, 22 Feb 2024 09:57:28 +0300 Subject: [PATCH 1/5] Update StepModeSP property --- drivers/focuser/moonlite.cpp | 42 ++++++++++++++++++------------------ drivers/focuser/moonlite.h | 3 +-- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/drivers/focuser/moonlite.cpp b/drivers/focuser/moonlite.cpp index 5f3fb5c9a0..3423417824 100644 --- a/drivers/focuser/moonlite.cpp +++ b/drivers/focuser/moonlite.cpp @@ -49,9 +49,9 @@ bool MoonLite::initProperties() FocusSpeedN[0].value = 1; // Step Mode - IUFillSwitch(&StepModeS[FOCUS_HALF_STEP], "FOCUS_HALF_STEP", "Half Step", ISS_OFF); - IUFillSwitch(&StepModeS[FOCUS_FULL_STEP], "FOCUS_FULL_STEP", "Full Step", ISS_ON); - IUFillSwitchVector(&StepModeSP, StepModeS, 2, getDeviceName(), "Step Mode", "", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0, + StepModeSP[FOCUS_HALF_STEP].fill("FOCUS_HALF_STEP", "Half Step", ISS_OFF); + StepModeSP[FOCUS_FULL_STEP].fill("FOCUS_FULL_STEP", "Full Step", ISS_ON); + StepModeSP.fill(getDeviceName(), "Step Mode", "", OPTIONS_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); // Focuser temperature @@ -95,7 +95,7 @@ bool MoonLite::updateProperties() if (isConnected()) { defineProperty(&TemperatureNP); - defineProperty(&StepModeSP); + defineProperty(StepModeSP); defineProperty(&TemperatureSettingNP); defineProperty(&TemperatureCompensateSP); @@ -106,7 +106,7 @@ bool MoonLite::updateProperties() else { deleteProperty(TemperatureNP.name); - deleteProperty(StepModeSP.name); + deleteProperty(StepModeSP.getName()); deleteProperty(TemperatureSettingNP.name); deleteProperty(TemperatureCompensateSP.name); } @@ -158,9 +158,9 @@ bool MoonLite::readStepMode() return false; if (strcmp(res, "FF#") == 0) - StepModeS[FOCUS_HALF_STEP].s = ISS_ON; + StepModeSP[FOCUS_HALF_STEP].setState(ISS_ON); else if (strcmp(res, "00#") == 0) - StepModeS[FOCUS_FULL_STEP].s = ISS_ON; + StepModeSP[FOCUS_FULL_STEP].setState(ISS_ON); else { LOGF_ERROR("Unknown error: focuser step value (%s)", res); @@ -337,32 +337,32 @@ bool MoonLite::ISNewSwitch(const char * dev, const char * name, ISState * states if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { // Focus Step Mode - if (strcmp(StepModeSP.name, name) == 0) + if (StepModeSP.isNameMatch(name)) { - int current_mode = IUFindOnSwitchIndex(&StepModeSP); + int current_mode = StepModeSP.findOnSwitchIndex(); - IUUpdateSwitch(&StepModeSP, states, names, n); + StepModeSP.update(states, names, n); - int target_mode = IUFindOnSwitchIndex(&StepModeSP); + int target_mode = StepModeSP.findOnSwitchIndex(); if (current_mode == target_mode) { - StepModeSP.s = IPS_OK; - IDSetSwitch(&StepModeSP, nullptr); + StepModeSP.setState(IPS_OK); + StepModeSP.apply(); } bool rc = setStepMode(target_mode == 0 ? FOCUS_HALF_STEP : FOCUS_FULL_STEP); if (!rc) { - IUResetSwitch(&StepModeSP); - StepModeS[current_mode].s = ISS_ON; - StepModeSP.s = IPS_ALERT; - IDSetSwitch(&StepModeSP, nullptr); + StepModeSP.reset(); + StepModeSP[current_mode].setState(ISS_ON); + StepModeSP.setState(IPS_ALERT); + StepModeSP.apply(); return false; } - StepModeSP.s = IPS_OK; - IDSetSwitch(&StepModeSP, nullptr); + StepModeSP.setState(IPS_OK); + StepModeSP.apply(); return true; } @@ -429,7 +429,7 @@ void MoonLite::GetFocusParams() IDSetNumber(&FocusSpeedNP, nullptr); if (readStepMode()) - IDSetSwitch(&StepModeSP, nullptr); + StepModeSP.apply(); } bool MoonLite::SetFocuserSpeed(int speed) @@ -550,7 +550,7 @@ bool MoonLite::saveConfigItems(FILE * fp) { Focuser::saveConfigItems(fp); - IUSaveConfigSwitch(fp, &StepModeSP); + StepModeSP.save(fp); return true; } diff --git a/drivers/focuser/moonlite.h b/drivers/focuser/moonlite.h index 47b4cc8e42..47be8cb72f 100644 --- a/drivers/focuser/moonlite.h +++ b/drivers/focuser/moonlite.h @@ -126,8 +126,7 @@ class MoonLite : public INDI::Focuser INumberVectorProperty TemperatureNP; // Full/Half Step modes - ISwitch StepModeS[2]; - ISwitchVectorProperty StepModeSP; + INDI::PropertySwitch StepModeSP {2}; // Temperature Settings INumber TemperatureSettingN[2]; From a3d26b61d27768623893bae219b3f6bb702c5879 Mon Sep 17 00:00:00 2001 From: Salman Naheed Date: Thu, 22 Feb 2024 10:33:01 +0300 Subject: [PATCH 2/5] Update TemperatureNP and TemperatureSettingNP --- drivers/focuser/moonlite.cpp | 44 ++++++++++++++++++------------------ drivers/focuser/moonlite.h | 15 ++++++++---- 2 files changed, 33 insertions(+), 26 deletions(-) diff --git a/drivers/focuser/moonlite.cpp b/drivers/focuser/moonlite.cpp index 3423417824..f90c682e6e 100644 --- a/drivers/focuser/moonlite.cpp +++ b/drivers/focuser/moonlite.cpp @@ -55,14 +55,14 @@ bool MoonLite::initProperties() IPS_IDLE); // Focuser temperature - IUFillNumber(&TemperatureN[0], "TEMPERATURE", "Celsius", "%6.2f", -50, 70., 0., 0.); - IUFillNumberVector(&TemperatureNP, TemperatureN, 1, getDeviceName(), "FOCUS_TEMPERATURE", "Temperature", + TemperatureNP[TEMPERATURE].fill("TEMPERATURE", "Celsius", "%6.2f", -50, 70., 0., 0.); + TemperatureNP.fill(getDeviceName(), "FOCUS_TEMPERATURE", "Temperature", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE); // Temperature Settings - IUFillNumber(&TemperatureSettingN[0], "Calibration", "", "%6.2f", -100, 100, 0.5, 0); - IUFillNumber(&TemperatureSettingN[1], "Coefficient", "", "%6.2f", -100, 100, 0.5, 0); - IUFillNumberVector(&TemperatureSettingNP, TemperatureSettingN, 2, getDeviceName(), "T. Settings", "", + TemperatureSettingNP[Calibration].fill("Calibration", "", "%6.2f", -100, 100, 0.5, 0); + TemperatureSettingNP[Coefficient].fill("Coefficient", "", "%6.2f", -100, 100, 0.5, 0); + TemperatureSettingNP.fill(getDeviceName(), "T. Settings", "", OPTIONS_TAB, IP_RW, 0, IPS_IDLE); // Compensate for temperature @@ -94,9 +94,9 @@ bool MoonLite::updateProperties() if (isConnected()) { - defineProperty(&TemperatureNP); + defineProperty(TemperatureNP); defineProperty(StepModeSP); - defineProperty(&TemperatureSettingNP); + defineProperty(TemperatureSettingNP); defineProperty(&TemperatureCompensateSP); GetFocusParams(); @@ -105,9 +105,9 @@ bool MoonLite::updateProperties() } else { - deleteProperty(TemperatureNP.name); + deleteProperty(TemperatureNP.getName()); deleteProperty(StepModeSP.getName()); - deleteProperty(TemperatureSettingNP.name); + deleteProperty(TemperatureSettingNP.getName()); deleteProperty(TemperatureCompensateSP.name); } @@ -195,7 +195,7 @@ bool MoonLite::readTemperature() int rc = sscanf(res, "%X", &temp); if (rc > 0) // Signed hex - TemperatureN[0].value = static_cast(temp) / 2.0; + TemperatureNP[TEMPERATURE].setValue(static_cast(temp) / 2.0); else { LOGF_ERROR("Unknown error: focuser temperature value (%s)", res); @@ -397,19 +397,19 @@ bool MoonLite::ISNewNumber(const char * dev, const char * name, double values[], if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { // Temperature Settings - if (strcmp(name, TemperatureSettingNP.name) == 0) + if (TemperatureSettingNP.isNameMatch(name)) { - IUUpdateNumber(&TemperatureSettingNP, values, names, n); - if (!setTemperatureCalibration(TemperatureSettingN[0].value) || - !setTemperatureCoefficient(TemperatureSettingN[1].value)) + TemperatureSettingNP.update(values, names, n); + if (!setTemperatureCalibration(TemperatureSettingNP[Calibration].getValue()) || + !setTemperatureCoefficient(TemperatureSettingNP[Coefficient].getValue())) { - TemperatureSettingNP.s = IPS_ALERT; - IDSetNumber(&TemperatureSettingNP, nullptr); + TemperatureSettingNP.setState(IPS_ALERT); + TemperatureSettingNP.apply(); return false; } - TemperatureSettingNP.s = IPS_OK; - IDSetNumber(&TemperatureSettingNP, nullptr); + TemperatureSettingNP.setState(IPS_OK); + TemperatureSettingNP.apply(); return true; } } @@ -423,7 +423,7 @@ void MoonLite::GetFocusParams() IDSetNumber(&FocusAbsPosNP, nullptr); if (readTemperature()) - IDSetNumber(&TemperatureNP, nullptr); + TemperatureNP.apply(); if (readSpeed()) IDSetNumber(&FocusSpeedNP, nullptr); @@ -518,10 +518,10 @@ void MoonLite::TimerHit() rc = readTemperature(); if (rc) { - if (fabs(lastTemperature - TemperatureN[0].value) >= 0.5) + if (fabs(lastTemperature - TemperatureNP[TEMPERATURE].value) >= 0.5) { - IDSetNumber(&TemperatureNP, nullptr); - lastTemperature = static_cast(TemperatureN[0].value); + TemperatureNP.apply(); + lastTemperature = static_cast(TemperatureNP[TEMPERATURE].value); } } diff --git a/drivers/focuser/moonlite.h b/drivers/focuser/moonlite.h index 47be8cb72f..c442ea1654 100644 --- a/drivers/focuser/moonlite.h +++ b/drivers/focuser/moonlite.h @@ -122,15 +122,22 @@ class MoonLite : public INDI::Focuser uint32_t targetPos { 0 }, lastPos { 0 }, lastTemperature { 0 }; // Read Only Temperature Reporting - INumber TemperatureN[1]; - INumberVectorProperty TemperatureNP; + INDI::PropertyNumber TemperatureNP {1}; + enum + { + TEMPERATURE + }; // Full/Half Step modes INDI::PropertySwitch StepModeSP {2}; // Temperature Settings - INumber TemperatureSettingN[2]; - INumberVectorProperty TemperatureSettingNP; + INDI::PropertyNumber TemperatureSettingNP {2}; + enum + { + Calibration, + Coefficient + }; // Temperature Compensation Enable/Disable ISwitch TemperatureCompensateS[2]; From 25ca248c1dba5c0aba6e75d4b663ba2c2d8137e0 Mon Sep 17 00:00:00 2001 From: Salman Naheed Date: Thu, 22 Feb 2024 10:40:27 +0300 Subject: [PATCH 3/5] Update TemperatureCompensateSP Property --- drivers/focuser/moonlite.cpp | 30 +++++++++++++++--------------- drivers/focuser/moonlite.h | 8 ++++++-- 2 files changed, 21 insertions(+), 17 deletions(-) diff --git a/drivers/focuser/moonlite.cpp b/drivers/focuser/moonlite.cpp index f90c682e6e..ca951a00f9 100644 --- a/drivers/focuser/moonlite.cpp +++ b/drivers/focuser/moonlite.cpp @@ -66,9 +66,9 @@ bool MoonLite::initProperties() OPTIONS_TAB, IP_RW, 0, IPS_IDLE); // Compensate for temperature - IUFillSwitch(&TemperatureCompensateS[0], "Enable", "", ISS_OFF); - IUFillSwitch(&TemperatureCompensateS[1], "Disable", "", ISS_ON); - IUFillSwitchVector(&TemperatureCompensateSP, TemperatureCompensateS, 2, getDeviceName(), "T. Compensate", + TemperatureCompensateSP[Enable].fill("Enable", "", ISS_OFF); + TemperatureCompensateSP[Disable].fill("Disable", "", ISS_ON); + TemperatureCompensateSP.fill(getDeviceName(), "T. Compensate", "", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); /* Relative and absolute movement */ @@ -97,7 +97,7 @@ bool MoonLite::updateProperties() defineProperty(TemperatureNP); defineProperty(StepModeSP); defineProperty(TemperatureSettingNP); - defineProperty(&TemperatureCompensateSP); + defineProperty(TemperatureCompensateSP); GetFocusParams(); @@ -108,7 +108,7 @@ bool MoonLite::updateProperties() deleteProperty(TemperatureNP.getName()); deleteProperty(StepModeSP.getName()); deleteProperty(TemperatureSettingNP.getName()); - deleteProperty(TemperatureCompensateSP.name); + deleteProperty(TemperatureCompensateSP.getName()); } return true; @@ -367,24 +367,24 @@ bool MoonLite::ISNewSwitch(const char * dev, const char * name, ISState * states } // Temperature Compensation Mode - if (strcmp(TemperatureCompensateSP.name, name) == 0) + if (TemperatureCompensateSP.isNameMatch(name)) { - int last_index = IUFindOnSwitchIndex(&TemperatureCompensateSP); - IUUpdateSwitch(&TemperatureCompensateSP, states, names, n); + int last_index = TemperatureCompensateSP.findOnSwitchIndex(); + TemperatureCompensateSP.update(states, names, n); - bool rc = setTemperatureCompensation((TemperatureCompensateS[0].s == ISS_ON)); + bool rc = setTemperatureCompensation((TemperatureCompensateSP[Enable].getState() == ISS_ON)); if (!rc) { - TemperatureCompensateSP.s = IPS_ALERT; - IUResetSwitch(&TemperatureCompensateSP); - TemperatureCompensateS[last_index].s = ISS_ON; - IDSetSwitch(&TemperatureCompensateSP, nullptr); + TemperatureCompensateSP.setState(IPS_ALERT); + TemperatureCompensateSP.reset(); + TemperatureCompensateSP[last_index].setState(ISS_ON); + TemperatureCompensateSP.apply(); return false; } - TemperatureCompensateSP.s = IPS_OK; - IDSetSwitch(&TemperatureCompensateSP, nullptr); + TemperatureCompensateSP.setState(IPS_OK); + TemperatureCompensateSP.apply(); return true; } } diff --git a/drivers/focuser/moonlite.h b/drivers/focuser/moonlite.h index c442ea1654..e5a91ec181 100644 --- a/drivers/focuser/moonlite.h +++ b/drivers/focuser/moonlite.h @@ -140,8 +140,12 @@ class MoonLite : public INDI::Focuser }; // Temperature Compensation Enable/Disable - ISwitch TemperatureCompensateS[2]; - ISwitchVectorProperty TemperatureCompensateSP; + INDI::PropertySwitch TemperatureCompensateSP {2}; + enum + { + Enable, + Disable + }; // MoonLite Buffer static const uint8_t ML_RES { 32 }; From f9f134007650a3dd2ab93438449e2ef258dc8b8e Mon Sep 17 00:00:00 2001 From: Salman Naheed Date: Thu, 22 Feb 2024 11:20:23 +0300 Subject: [PATCH 4/5] remove unnecessary Enums and avoid using enum for a single item --- drivers/focuser/moonlite.cpp | 14 +++++++------- drivers/focuser/moonlite.h | 9 --------- 2 files changed, 7 insertions(+), 16 deletions(-) diff --git a/drivers/focuser/moonlite.cpp b/drivers/focuser/moonlite.cpp index ca951a00f9..c6c67bd41e 100644 --- a/drivers/focuser/moonlite.cpp +++ b/drivers/focuser/moonlite.cpp @@ -55,7 +55,7 @@ bool MoonLite::initProperties() IPS_IDLE); // Focuser temperature - TemperatureNP[TEMPERATURE].fill("TEMPERATURE", "Celsius", "%6.2f", -50, 70., 0., 0.); + TemperatureNP[0].fill("TEMPERATURE", "Celsius", "%6.2f", -50, 70., 0., 0.); TemperatureNP.fill(getDeviceName(), "FOCUS_TEMPERATURE", "Temperature", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE); @@ -66,8 +66,8 @@ bool MoonLite::initProperties() OPTIONS_TAB, IP_RW, 0, IPS_IDLE); // Compensate for temperature - TemperatureCompensateSP[Enable].fill("Enable", "", ISS_OFF); - TemperatureCompensateSP[Disable].fill("Disable", "", ISS_ON); + TemperatureCompensateSP[INDI_ENABLED].fill("Enable", "", ISS_OFF); + TemperatureCompensateSP[INDI_DISABLED].fill("Disable", "", ISS_ON); TemperatureCompensateSP.fill(getDeviceName(), "T. Compensate", "", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); @@ -195,7 +195,7 @@ bool MoonLite::readTemperature() int rc = sscanf(res, "%X", &temp); if (rc > 0) // Signed hex - TemperatureNP[TEMPERATURE].setValue(static_cast(temp) / 2.0); + TemperatureNP[0].setValue(static_cast(temp) / 2.0); else { LOGF_ERROR("Unknown error: focuser temperature value (%s)", res); @@ -372,7 +372,7 @@ bool MoonLite::ISNewSwitch(const char * dev, const char * name, ISState * states int last_index = TemperatureCompensateSP.findOnSwitchIndex(); TemperatureCompensateSP.update(states, names, n); - bool rc = setTemperatureCompensation((TemperatureCompensateSP[Enable].getState() == ISS_ON)); + bool rc = setTemperatureCompensation((TemperatureCompensateSP[INDI_ENABLED].getState() == ISS_ON)); if (!rc) { @@ -518,10 +518,10 @@ void MoonLite::TimerHit() rc = readTemperature(); if (rc) { - if (fabs(lastTemperature - TemperatureNP[TEMPERATURE].value) >= 0.5) + if (fabs(lastTemperature - TemperatureNP[0].value) >= 0.5) { TemperatureNP.apply(); - lastTemperature = static_cast(TemperatureNP[TEMPERATURE].value); + lastTemperature = static_cast(TemperatureNP[0].value); } } diff --git a/drivers/focuser/moonlite.h b/drivers/focuser/moonlite.h index e5a91ec181..0b709b8b95 100644 --- a/drivers/focuser/moonlite.h +++ b/drivers/focuser/moonlite.h @@ -123,10 +123,6 @@ class MoonLite : public INDI::Focuser // Read Only Temperature Reporting INDI::PropertyNumber TemperatureNP {1}; - enum - { - TEMPERATURE - }; // Full/Half Step modes INDI::PropertySwitch StepModeSP {2}; @@ -141,11 +137,6 @@ class MoonLite : public INDI::Focuser // Temperature Compensation Enable/Disable INDI::PropertySwitch TemperatureCompensateSP {2}; - enum - { - Enable, - Disable - }; // MoonLite Buffer static const uint8_t ML_RES { 32 }; From 57f38ad5ddf0a4510ffdbc5caf318cbf5c1ec923 Mon Sep 17 00:00:00 2001 From: Salman Naheed Date: Thu, 22 Feb 2024 13:34:13 +0300 Subject: [PATCH 5/5] use getValue and std:Abs instead of fabs --- drivers/focuser/moonlite.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/focuser/moonlite.cpp b/drivers/focuser/moonlite.cpp index c6c67bd41e..f12274289b 100644 --- a/drivers/focuser/moonlite.cpp +++ b/drivers/focuser/moonlite.cpp @@ -518,10 +518,10 @@ void MoonLite::TimerHit() rc = readTemperature(); if (rc) { - if (fabs(lastTemperature - TemperatureNP[0].value) >= 0.5) + if (std::abs(lastTemperature - TemperatureNP[0].getValue()) >= 0.5) { TemperatureNP.apply(); - lastTemperature = static_cast(TemperatureNP[0].value); + lastTemperature = static_cast(TemperatureNP[0].getValue()); } }