From b182820046f2d47bd75aba26dae8f3017502e563 Mon Sep 17 00:00:00 2001 From: Ian Jessen Date: Mon, 26 Feb 2024 10:56:21 -0500 Subject: [PATCH] Support setting autodew aggression (#1992) --- drivers/auxiliary/pegasus_ppba.cpp | 49 ++++++++++++++++++++++++++++++ drivers/auxiliary/pegasus_ppba.h | 9 ++++++ 2 files changed, 58 insertions(+) diff --git a/drivers/auxiliary/pegasus_ppba.cpp b/drivers/auxiliary/pegasus_ppba.cpp index f1a792be76..caecbc1f2e 100644 --- a/drivers/auxiliary/pegasus_ppba.cpp +++ b/drivers/auxiliary/pegasus_ppba.cpp @@ -135,6 +135,10 @@ bool PegasusPPBA::initProperties() IUFillSwitchVector(&AutoDewSP, AutoDewS, 2, getDeviceName(), "AUTO_DEW", "Auto Dew", DEW_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); + IUFillNumber(&AutoDewSettingsN[AUTO_DEW_AGGRESSION], "AUTO_DEW_AGGRESSION", "Auto Dew Aggresiveness (%)", "%.2f", 0, 100, 10, 0); + IUFillNumberVector(&AutoDewSettingsNP, AutoDewSettingsN, 1, getDeviceName(), "AUTO_DEW_SETTINGS", "Auto Dew Settings", DEW_TAB, IP_RW, 60, IPS_IDLE); + + // Dew PWM IUFillNumber(&DewPWMN[DEW_PWM_A], "DEW_A", "Dew A (%)", "%.2f", 0, 100, 10, 0); IUFillNumber(&DewPWMN[DEW_PWM_B], "DEW_B", "Dew B (%)", "%.2f", 0, 100, 10, 0); @@ -213,8 +217,11 @@ bool PegasusPPBA::updateProperties() // Dew defineProperty(&AutoDewSP); + defineProperty(&AutoDewSettingsNP); defineProperty(&DewPWMNP); + getAutoDewAggression(); + // Focuser if (m_HasExternalMotor) { @@ -244,6 +251,7 @@ bool PegasusPPBA::updateProperties() // Dew deleteProperty(AutoDewSP.name); + deleteProperty(AutoDewSettingsNP.name); deleteProperty(DewPWMNP.name); if (m_HasExternalMotor) @@ -506,6 +514,16 @@ bool PegasusPPBA::ISNewNumber(const char * dev, const char * name, double values return true; } + // Auto Dew Settings + if (!strcmp(name, AutoDewSettingsNP.name)) + { + AutoDewSettingsNP.s = setAutoDewAggression(static_cast(values[AUTO_DEW_AGGRESSION] / 100.0 * 255.0)) ? IPS_OK : IPS_ALERT; + if (AutoDewSettingsNP.s == IPS_OK) + IUUpdateNumber(&AutoDewSettingsNP, values, names, n); + IDSetNumber(&AutoDewSettingsNP, nullptr); + return true; + } + // Focuser Settings if (!strcmp(name, FocuserSettingsNP.name)) { @@ -593,6 +611,18 @@ bool PegasusPPBA::setAutoDewEnabled(bool enabled) return false; } +bool PegasusPPBA::setAutoDewAggression(uint8_t value) +{ + char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0}; + snprintf(cmd, PEGASUS_LEN, "PD:%03d", value); + if (sendCommand(cmd, res)) + { + return (!strcmp(res, cmd)); + } + + return false; +} + bool PegasusPPBA::setPowerOnBoot() { char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0}; @@ -632,6 +662,7 @@ bool PegasusPPBA::saveConfigItems(FILE * fp) } WI::saveConfigItems(fp); IUSaveConfigSwitch(fp, &AutoDewSP); + IUSaveConfigNumber(fp, &AutoDewSettingsNP); return true; } @@ -791,6 +822,24 @@ bool PegasusPPBA::getConsumptionData() return false; } +bool PegasusPPBA::getAutoDewAggression() +{ + char res[PEGASUS_LEN] = {0}; + if (sendCommand("DA", res)) + { + + uint32_t value = 0; + sscanf(res, "%*[^:]:%d", &value); + AutoDewSettingsN[AUTO_DEW_AGGRESSION].value = value; + IDSetNumber(&AutoDewSettingsNP, nullptr); + + return true; + } + + return false; + +} + bool PegasusPPBA::getMetricsData() { char res[PEGASUS_LEN] = {0}; diff --git a/drivers/auxiliary/pegasus_ppba.h b/drivers/auxiliary/pegasus_ppba.h index affd460894..b10f0bf629 100644 --- a/drivers/auxiliary/pegasus_ppba.h +++ b/drivers/auxiliary/pegasus_ppba.h @@ -128,6 +128,8 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p // Dew bool setAutoDewEnabled(bool enabled); + bool setAutoDewAggression(uint8_t value); + bool getAutoDewAggression(); bool setDewPWM(uint8_t id, uint8_t value); // Focuser @@ -212,6 +214,13 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p ISwitch AutoDewS[2]; ISwitchVectorProperty AutoDewSP; + INumber AutoDewSettingsN[1]; + INumberVectorProperty AutoDewSettingsNP; + enum + { + AUTO_DEW_AGGRESSION + }; + // Dew PWM INumber DewPWMN[2]; INumberVectorProperty DewPWMNP;