diff --git a/drivers/auxiliary/pegasus_ppba.cpp b/drivers/auxiliary/pegasus_ppba.cpp index 489634793c..4ae1245790 100644 --- a/drivers/auxiliary/pegasus_ppba.cpp +++ b/drivers/auxiliary/pegasus_ppba.cpp @@ -64,9 +64,9 @@ bool PegasusPPBA::initProperties() /// Main Control Panel //////////////////////////////////////////////////////////////////////////// // Quad 12v Power - IUFillSwitch(&QuadOutS[INDI_ENABLED], "QUADOUT_ON", "Enable", ISS_OFF); - IUFillSwitch(&QuadOutS[INDI_DISABLED], "QUADOUT_OFF", "Disable", ISS_OFF); - IUFillSwitchVector(&QuadOutSP, QuadOutS, 2, getDeviceName(), "QUADOUT_POWER", "Quad Output", MAIN_CONTROL_TAB, + QuadOutSP[INDI_ENABLED].fill("QUADOUT_ON", "Enable", ISS_OFF); + QuadOutSP[INDI_DISABLED].fill("QUADOUT_OFF", "Disable", ISS_OFF); + QuadOutSP.fill(getDeviceName(), "QUADOUT_POWER", "Quad Output", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE); // Adjustable Power @@ -76,40 +76,40 @@ bool PegasusPPBA::initProperties() // ISR_1OFMANY, 60, IPS_IDLE); // Adjustable Voltage - IUFillSwitch(&AdjOutVoltS[ADJOUT_OFF], "ADJOUT_OFF", "Off", ISS_ON); - IUFillSwitch(&AdjOutVoltS[ADJOUT_3V], "ADJOUT_3V", "3V", ISS_OFF); - IUFillSwitch(&AdjOutVoltS[ADJOUT_5V], "ADJOUT_5V", "5V", ISS_OFF); - IUFillSwitch(&AdjOutVoltS[ADJOUT_8V], "ADJOUT_8V", "8V", ISS_OFF); - IUFillSwitch(&AdjOutVoltS[ADJOUT_9V], "ADJOUT_9V", "9V", ISS_OFF); - IUFillSwitch(&AdjOutVoltS[ADJOUT_12V], "ADJOUT_12V", "12V", ISS_OFF); - IUFillSwitchVector(&AdjOutVoltSP, AdjOutVoltS, 6, getDeviceName(), "ADJOUT_VOLTAGE", "Adj voltage", MAIN_CONTROL_TAB, IP_RW, + AdjOutVoltSP[ADJOUT_OFF].fill("ADJOUT_OFF", "Off", ISS_ON); + AdjOutVoltSP[ADJOUT_3V].fill("ADJOUT_3V", "3V", ISS_OFF); + AdjOutVoltSP[ADJOUT_5V].fill("ADJOUT_5V", "5V", ISS_OFF); + AdjOutVoltSP[ADJOUT_8V].fill("ADJOUT_8V", "8V", ISS_OFF); + AdjOutVoltSP[ADJOUT_9V].fill("ADJOUT_9V", "9V", ISS_OFF); + AdjOutVoltSP[ADJOUT_12V].fill("ADJOUT_12V", "12V", ISS_OFF); + AdjOutVoltSP.fill(getDeviceName(), "ADJOUT_VOLTAGE", "Adj voltage", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); // Reboot - IUFillSwitch(&RebootS[0], "REBOOT", "Reboot Device", ISS_OFF); - IUFillSwitchVector(&RebootSP, RebootS, 1, getDeviceName(), "REBOOT_DEVICE", "Device", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, + RebootSP[0].fill("REBOOT", "Reboot Device", ISS_OFF); + RebootSP.fill(getDeviceName(), "REBOOT_DEVICE", "Device", MAIN_CONTROL_TAB, IP_RW, ISR_ATMOST1, 60, IPS_IDLE); // Power Sensors - IUFillNumber(&PowerSensorsN[SENSOR_VOLTAGE], "SENSOR_VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_CURRENT], "SENSOR_CURRENT", "Current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_AVG_AMPS], "SENSOR_AVG_AMPS", "Average Current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_AMP_HOURS], "SENSOR_AMP_HOURS", "Amp hours (Ah)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_WATT_HOURS], "SENSOR_WATT_HOURS", "Watt hours (Wh)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_TOTAL_CURRENT], "SENSOR_TOTAL_CURRENT", "Total current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_12V_CURRENT], "SENSOR_12V_CURRENT", "12V current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_DEWA_CURRENT], "SENSOR_DEWA_CURRENT", "DewA current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumber(&PowerSensorsN[SENSOR_DEWB_CURRENT], "SENSOR_DEWB_CURRENT", "DewB current (A)", "%4.2f", 0, 999, 100, 0); - IUFillNumberVector(&PowerSensorsNP, PowerSensorsN, 9, getDeviceName(), "POWER_SENSORS", "Sensors", MAIN_CONTROL_TAB, IP_RO, + PowerSensorsNP[SENSOR_VOLTAGE].fill("SENSOR_VOLTAGE", "Voltage (V)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_CURRENT].fill("SENSOR_CURRENT", "Current (A)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_AVG_AMPS].fill("SENSOR_AVG_AMPS", "Average Current (A)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_AMP_HOURS].fill("SENSOR_AMP_HOURS", "Amp hours (Ah)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_WATT_HOURS].fill("SENSOR_WATT_HOURS", "Watt hours (Wh)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_TOTAL_CURRENT].fill("SENSOR_TOTAL_CURRENT", "Total current (A)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_12V_CURRENT].fill("SENSOR_12V_CURRENT", "12V current (A)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_DEWA_CURRENT].fill("SENSOR_DEWA_CURRENT", "DewA current (A)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP[SENSOR_DEWB_CURRENT].fill("SENSOR_DEWB_CURRENT", "DewB current (A)", "%4.2f", 0, 999, 100, 0); + PowerSensorsNP.fill(getDeviceName(), "POWER_SENSORS", "Sensors", MAIN_CONTROL_TAB, IP_RO, 60, IPS_IDLE); - IUFillLight(&PowerWarnL[0], "POWER_WARN_ON", "Current Overload", IPS_IDLE); - IUFillLightVector(&PowerWarnLP, PowerWarnL, 1, getDeviceName(), "POWER_WARM", "Power Warn", MAIN_CONTROL_TAB, IPS_IDLE); + PowerWarnLP[0].fill("POWER_WARN_ON", "Current Overload", IPS_IDLE); + PowerWarnLP.fill(getDeviceName(), "POWER_WARM", "Power Warn", MAIN_CONTROL_TAB, IPS_IDLE); // LED Indicator - IUFillSwitch(&LedIndicatorS[INDI_ENABLED], "LED_ON", "Enable", ISS_ON); - IUFillSwitch(&LedIndicatorS[INDI_DISABLED], "LED_OFF", "Disable", ISS_OFF); - IUFillSwitchVector(&LedIndicatorSP, LedIndicatorS, 2, getDeviceName(), "LED_INDICATOR", "LED Indicator", MAIN_CONTROL_TAB, + LedIndicatorSP[INDI_ENABLED].fill("LED_ON", "Enable", ISS_ON); + LedIndicatorSP[INDI_DISABLED].fill("LED_OFF", "Disable", ISS_OFF); + LedIndicatorSP.fill(getDeviceName(), "LED_INDICATOR", "LED Indicator", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); @@ -118,11 +118,11 @@ bool PegasusPPBA::initProperties() //////////////////////////////////////////////////////////////////////////// // Power on Boot - IUFillSwitch(&PowerOnBootS[0], "POWER_PORT_1", "Quad Out", ISS_ON); - IUFillSwitch(&PowerOnBootS[1], "POWER_PORT_2", "Adj Out", ISS_ON); - IUFillSwitch(&PowerOnBootS[2], "POWER_PORT_3", "Dew A", ISS_ON); - IUFillSwitch(&PowerOnBootS[3], "POWER_PORT_4", "Dew B", ISS_ON); - IUFillSwitchVector(&PowerOnBootSP, PowerOnBootS, 4, getDeviceName(), "POWER_ON_BOOT", "Power On Boot", MAIN_CONTROL_TAB, + PowerOnBootSP[POWER_PORT_1].fill("POWER_PORT_1", "Quad Out", ISS_ON); + PowerOnBootSP[POWER_PORT_2].fill("POWER_PORT_2", "Adj Out", ISS_ON); + PowerOnBootSP[POWER_PORT_3].fill("POWER_PORT_3", "Dew A", ISS_ON); + PowerOnBootSP[POWER_PORT_4].fill("POWER_PORT_4", "Dew B", ISS_ON); + PowerOnBootSP.fill(getDeviceName(), "POWER_ON_BOOT", "Power On Boot", MAIN_CONTROL_TAB, IP_RW, ISR_NOFMANY, 60, IPS_IDLE); //////////////////////////////////////////////////////////////////////////// @@ -130,26 +130,26 @@ bool PegasusPPBA::initProperties() //////////////////////////////////////////////////////////////////////////// // Automatic Dew - IUFillSwitch(&AutoDewS[INDI_ENABLED], "INDI_ENABLED", "Enabled", ISS_OFF); - IUFillSwitch(&AutoDewS[INDI_DISABLED], "INDI_DISABLED", "Disabled", ISS_OFF); - IUFillSwitchVector(&AutoDewSP, AutoDewS, 2, getDeviceName(), "AUTO_DEW", "Auto Dew", DEW_TAB, IP_RW, ISR_1OFMANY, 60, + AutoDewSP[INDI_ENABLED].fill("INDI_ENABLED", "Enabled", ISS_OFF); + AutoDewSP[INDI_DISABLED].fill("INDI_DISABLED", "Disabled", ISS_OFF); + AutoDewSP.fill(getDeviceName(), "AUTO_DEW", "Auto Dew", DEW_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); - IUFillNumber(&AutoDewSettingsN[AUTO_DEW_AGGRESSION], "AGGRESSION", "Aggresiveness (%)", "%.2f", 0, 100, 10, 0); - IUFillNumberVector(&AutoDewSettingsNP, AutoDewSettingsN, 1, getDeviceName(), "AUTO_DEW_SETTINGS", "Auto Dew Settings", DEW_TAB, IP_RW, 60, IPS_IDLE); + AutoDewSettingsNP[AUTO_DEW_AGGRESSION].fill("AGGRESSION", "Aggresiveness (%)", "%.2f", 0, 100, 10, 0); + AutoDewSettingsNP.fill(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); - IUFillNumberVector(&DewPWMNP, DewPWMN, 2, getDeviceName(), "DEW_PWM", "Dew PWM", DEW_TAB, IP_RW, 60, IPS_IDLE); + DewPWMNP[DEW_PWM_A].fill("DEW_A", "Dew A (%)", "%.2f", 0, 100, 10, 0); + DewPWMNP[DEW_PWM_B].fill("DEW_B", "Dew B (%)", "%.2f", 0, 100, 10, 0); + DewPWMNP.fill(getDeviceName(), "DEW_PWM", "Dew PWM", DEW_TAB, IP_RW, 60, IPS_IDLE); //////////////////////////////////////////////////////////////////////////// /// Firmware Group //////////////////////////////////////////////////////////////////////////// - IUFillText(&FirmwareT[FIRMWARE_VERSION], "VERSION", "Version", "NA"); - IUFillText(&FirmwareT[FIRMWARE_UPTIME], "UPTIME", "Uptime (h)", "NA"); - IUFillTextVector(&FirmwareTP, FirmwareT, 2, getDeviceName(), "FIRMWARE_INFO", "Firmware", FIRMWARE_TAB, IP_RO, 60, + FirmwareTP[FIRMWARE_VERSION].fill("VERSION", "Version", "NA"); + FirmwareTP[FIRMWARE_UPTIME].fill("UPTIME", "Uptime (h)", "NA"); + FirmwareTP.fill(getDeviceName(), "FIRMWARE_INFO", "Firmware", FIRMWARE_TAB, IP_RO, 60, IPS_IDLE); //////////////////////////////////////////////////////////////////////////// @@ -165,16 +165,16 @@ bool PegasusPPBA::initProperties() //////////////////////////////////////////////////////////////////////////// // Max Speed - IUFillNumber(&FocuserSettingsN[SETTING_MAX_SPEED], "SETTING_MAX_SPEED", "Max Speed (%)", "%.f", 0, 900, 100, 400); - IUFillNumberVector(&FocuserSettingsNP, FocuserSettingsN, 1, getDeviceName(), "FOCUSER_SETTINGS", "Settings", FOCUS_TAB, + FocuserSettingsNP[SETTING_MAX_SPEED].fill("SETTING_MAX_SPEED", "Max Speed (%)", "%.f", 0, 900, 100, 400); + FocuserSettingsNP.fill(getDeviceName(), "FOCUSER_SETTINGS", "Settings", FOCUS_TAB, IP_RW, 60, IPS_IDLE); // Stepping - IUFillSwitch(&FocuserDriveS[STEP_FULL], "STEP_FULL", "Full", ISS_OFF); - IUFillSwitch(&FocuserDriveS[STEP_HALF], "STEP_HALF", "Half", ISS_ON); - IUFillSwitch(&FocuserDriveS[STEP_FORTH], "STEP_FORTH", "1/4", ISS_OFF); - IUFillSwitch(&FocuserDriveS[STEP_EIGHTH], "STEP_EIGHTH", "1/8", ISS_OFF); - IUFillSwitchVector(&FocuserDriveSP, FocuserDriveS, 4, getDeviceName(), "FOCUSER_DRIVE", "Microstepping", FOCUS_TAB, + FocuserDriveSP[STEP_FULL].fill("STEP_FULL", "Full", ISS_OFF); + FocuserDriveSP[STEP_HALF].fill("STEP_HALF", "Half", ISS_ON); + FocuserDriveSP[STEP_FORTH].fill("STEP_FORTH", "1/4", ISS_OFF); + FocuserDriveSP[STEP_EIGHTH].fill("STEP_EIGHTH", "1/8", ISS_OFF); + FocuserDriveSP.fill(getDeviceName(), "FOCUSER_DRIVE", "Microstepping", FOCUS_TAB, IP_RW, ISR_1OFMANY, 60, IPS_IDLE); //////////////////////////////////////////////////////////////////////////// @@ -206,19 +206,19 @@ bool PegasusPPBA::updateProperties() } // Main Control - defineProperty(&QuadOutSP); + defineProperty(QuadOutSP); //defineProperty(&AdjOutSP); - defineProperty(&AdjOutVoltSP); - defineProperty(&PowerSensorsNP); - defineProperty(&PowerOnBootSP); - defineProperty(&RebootSP); - defineProperty(&PowerWarnLP); - defineProperty(&LedIndicatorSP); + defineProperty(AdjOutVoltSP); + defineProperty(PowerSensorsNP); + defineProperty(PowerOnBootSP); + defineProperty(RebootSP); + defineProperty(PowerWarnLP); + defineProperty(LedIndicatorSP); // Dew - defineProperty(&AutoDewSP); - defineProperty(&AutoDewSettingsNP); - defineProperty(&DewPWMNP); + defineProperty(AutoDewSP); + defineProperty(AutoDewSettingsNP); + defineProperty(DewPWMNP); getAutoDewAggression(); @@ -226,14 +226,14 @@ bool PegasusPPBA::updateProperties() if (m_HasExternalMotor) { FI::updateProperties(); - defineProperty(&FocuserSettingsNP); - defineProperty(&FocuserDriveSP); + defineProperty(FocuserSettingsNP); + defineProperty(FocuserDriveSP); } WI::updateProperties(); // Firmware - defineProperty(&FirmwareTP); + defineProperty(FirmwareTP); sendFirmware(); setupComplete = true; @@ -241,30 +241,30 @@ bool PegasusPPBA::updateProperties() else { // Main Control - deleteProperty(QuadOutSP.name); + deleteProperty(QuadOutSP); //deleteProperty(AdjOutSP.name); - deleteProperty(AdjOutVoltSP.name); - deleteProperty(PowerSensorsNP.name); - deleteProperty(PowerOnBootSP.name); - deleteProperty(RebootSP.name); - deleteProperty(PowerWarnLP.name); - deleteProperty(LedIndicatorSP.name); + deleteProperty(AdjOutVoltSP); + deleteProperty(PowerSensorsNP); + deleteProperty(PowerOnBootSP); + deleteProperty(RebootSP); + deleteProperty(PowerWarnLP); + deleteProperty(LedIndicatorSP); // Dew - deleteProperty(AutoDewSP.name); - deleteProperty(AutoDewSettingsNP.name); - deleteProperty(DewPWMNP.name); + deleteProperty(AutoDewSP); + deleteProperty(AutoDewSettingsNP); + deleteProperty(DewPWMNP); if (m_HasExternalMotor) { FI::updateProperties(); - deleteProperty(FocuserSettingsNP.name); - deleteProperty(FocuserDriveSP.name); + deleteProperty(FocuserSettingsNP); + deleteProperty(FocuserDriveSP); } WI::updateProperties(); - deleteProperty(FirmwareTP.name); + deleteProperty(FirmwareTP); setupComplete = false; } @@ -330,20 +330,20 @@ bool PegasusPPBA::ISNewSwitch(const char * dev, const char * name, ISState * sta if (dev && !strcmp(dev, getDeviceName())) { // Quad 12V Power - if (!strcmp(name, QuadOutSP.name)) + if (QuadOutSP.isNameMatch(name)) { - IUUpdateSwitch(&QuadOutSP, states, names, n); + QuadOutSP.update(states, names, n); - QuadOutSP.s = IPS_ALERT; + QuadOutSP.setState(IPS_ALERT); char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0}; - snprintf(cmd, PEGASUS_LEN, "P1:%d", QuadOutS[INDI_ENABLED].s == ISS_ON); + snprintf(cmd, PEGASUS_LEN, "P1:%d", QuadOutSP[INDI_ENABLED].getState() == ISS_ON); if (sendCommand(cmd, res)) { - QuadOutSP.s = !strcmp(cmd, res) ? IPS_OK : IPS_ALERT; + QuadOutSP.setState(!strcmp(cmd, res) ? IPS_OK : IPS_ALERT); } - IUResetSwitch(&QuadOutSP); - IDSetSwitch(&QuadOutSP, nullptr); + QuadOutSP.reset(); + QuadOutSP.apply(); return true; } @@ -366,11 +366,11 @@ bool PegasusPPBA::ISNewSwitch(const char * dev, const char * name, ISState * sta // } // Adjustable Voltage - if (!strcmp(name, AdjOutVoltSP.name)) + if (AdjOutVoltSP.isNameMatch(name)) { - int previous_index = IUFindOnSwitchIndex(&AdjOutVoltSP); - IUUpdateSwitch(&AdjOutVoltSP, states, names, n); - int target_index = IUFindOnSwitchIndex(&AdjOutVoltSP); + int previous_index = AdjOutVoltSP.findOnSwitchIndex(); + AdjOutVoltSP.update(states, names, n); + int target_index = AdjOutVoltSP.findOnSwitchIndex(); int adjv = 0; switch(target_index) { @@ -394,93 +394,93 @@ bool PegasusPPBA::ISNewSwitch(const char * dev, const char * name, ISState * sta break; } - AdjOutVoltSP.s = IPS_ALERT; + AdjOutVoltSP.setState(IPS_ALERT); char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0}; snprintf(cmd, PEGASUS_LEN, "P2:%d", adjv); if (sendCommand(cmd, res)) - AdjOutVoltSP.s = IPS_OK; + AdjOutVoltSP.setState(IPS_OK); else { - IUResetSwitch(&AdjOutVoltSP); - AdjOutVoltS[previous_index].s = ISS_ON; - AdjOutVoltSP.s = IPS_ALERT; + AdjOutVoltSP.reset(); + AdjOutVoltSP[previous_index].setState(ISS_ON); + AdjOutVoltSP.setState(IPS_ALERT); } - IDSetSwitch(&AdjOutVoltSP, nullptr); + AdjOutVoltSP.apply(); return true; } // Reboot - if (!strcmp(name, RebootSP.name)) + if (RebootSP.isNameMatch(name)) { - RebootSP.s = reboot() ? IPS_OK : IPS_ALERT; - IDSetSwitch(&RebootSP, nullptr); + RebootSP.setState(reboot() ? IPS_OK : IPS_ALERT); + RebootSP.apply(); LOG_INFO("Rebooting device..."); return true; } // LED Indicator - if (!strcmp(name, LedIndicatorSP.name)) + if (LedIndicatorSP.isNameMatch(name)) { - IUUpdateSwitch(&LedIndicatorSP, states, names, n); + LedIndicatorSP.update(states, names, n); char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0}; - snprintf(cmd, PEGASUS_LEN, "PL:%d", LedIndicatorS[INDI_ENABLED].s == ISS_ON); + snprintf(cmd, PEGASUS_LEN, "PL:%d", LedIndicatorSP[INDI_ENABLED].getState() == ISS_ON); if (sendCommand(cmd, res)) { - LedIndicatorSP.s = !strcmp(cmd, res) ? IPS_OK : IPS_ALERT; + LedIndicatorSP.setState(!strcmp(cmd, res) ? IPS_OK : IPS_ALERT); } - IDSetSwitch(&LedIndicatorSP, nullptr); - saveConfig(true, LedIndicatorSP.name); + LedIndicatorSP.apply(); + saveConfig(true, LedIndicatorSP.getName()); return true; } // Power on boot - if (!strcmp(name, PowerOnBootSP.name)) + if (PowerOnBootSP.isNameMatch(name)) { - IUUpdateSwitch(&PowerOnBootSP, states, names, n); - PowerOnBootSP.s = setPowerOnBoot() ? IPS_OK : IPS_ALERT; - IDSetSwitch(&PowerOnBootSP, nullptr); - saveConfig(true, PowerOnBootSP.name); + PowerOnBootSP.update(states, names, n); + PowerOnBootSP.setState(setPowerOnBoot() ? IPS_OK : IPS_ALERT); + PowerOnBootSP.apply(); + saveConfig(true, PowerOnBootSP.getName()); return true; } // Auto Dew - if (!strcmp(name, AutoDewSP.name)) + if (AutoDewSP.isNameMatch(name)) { - int prevIndex = IUFindOnSwitchIndex(&AutoDewSP); - IUUpdateSwitch(&AutoDewSP, states, names, n); - if (setAutoDewEnabled(AutoDewS[INDI_ENABLED].s == ISS_ON)) + int prevIndex = AutoDewSP.findOnSwitchIndex(); + AutoDewSP.update(states, names, n); + if (setAutoDewEnabled(AutoDewSP[INDI_ENABLED].getState() == ISS_ON)) { - AutoDewSP.s = IPS_OK; + AutoDewSP.setState(IPS_OK); } else { - IUResetSwitch(&AutoDewSP); - AutoDewS[prevIndex].s = ISS_ON; - AutoDewSP.s = IPS_ALERT; + AutoDewSP.reset(); + AutoDewSP[prevIndex].setState(ISS_ON); + AutoDewSP.setState(IPS_ALERT); } - IDSetSwitch(&AutoDewSP, nullptr); + AutoDewSP.apply(); return true; } // Microstepping - if (!strcmp(name, FocuserDriveSP.name)) + if (FocuserDriveSP.isNameMatch(name)) { - int prevIndex = IUFindOnSwitchIndex(&FocuserDriveSP); - IUUpdateSwitch(&FocuserDriveSP, states, names, n); - if (setFocuserMicrosteps(IUFindOnSwitchIndex(&FocuserDriveSP) + 1)) + int prevIndex = FocuserDriveSP.findOnSwitchIndex(); + FocuserDriveSP.update(states, names, n); + if (setFocuserMicrosteps(FocuserDriveSP.findOnSwitchIndex() + 1)) { - FocuserDriveSP.s = IPS_OK; + FocuserDriveSP.setState(IPS_OK); } else { - IUResetSwitch(&FocuserDriveSP); - FocuserDriveS[prevIndex].s = ISS_ON; - FocuserDriveSP.s = IPS_ALERT; + FocuserDriveSP.reset(); + FocuserDriveSP[prevIndex].setState(ISS_ON); + FocuserDriveSP.setState(IPS_ALERT); } - IDSetSwitch(&FocuserDriveSP, nullptr); + FocuserDriveSP.apply(); return true; } @@ -496,48 +496,48 @@ bool PegasusPPBA::ISNewNumber(const char * dev, const char * name, double values if (dev && !strcmp(dev, getDeviceName())) { // Dew PWM - if (!strcmp(name, DewPWMNP.name)) + if (DewPWMNP.isNameMatch(name)) { bool rc1 = false, rc2 = false; for (int i = 0; i < n; i++) { - if (!strcmp(names[i], DewPWMN[DEW_PWM_A].name)) + if (!strcmp(names[i], DewPWMNP[DEW_PWM_A].getName())) rc1 = setDewPWM(3, static_cast(values[i] / 100.0 * 255.0)); - else if (!strcmp(names[i], DewPWMN[DEW_PWM_B].name)) + else if (!strcmp(names[i], DewPWMNP[DEW_PWM_B].getName())) rc2 = setDewPWM(4, static_cast(values[i] / 100.0 * 255.0)); } - DewPWMNP.s = (rc1 && rc2) ? IPS_OK : IPS_ALERT; - if (DewPWMNP.s == IPS_OK) - IUUpdateNumber(&DewPWMNP, values, names, n); - IDSetNumber(&DewPWMNP, nullptr); + DewPWMNP.setState((rc1 && rc2) ? IPS_OK : IPS_ALERT); + if (DewPWMNP.getState() == IPS_OK) + DewPWMNP.update(values, names, n); + DewPWMNP.apply(); 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); + if (AutoDewSettingsNP.isNameMatch(name)) + { + AutoDewSettingsNP.setState(setAutoDewAggression(static_cast(values[AUTO_DEW_AGGRESSION] / 100.0 * 255.0)) ? IPS_OK : IPS_ALERT); + if (AutoDewSettingsNP.getState() == IPS_OK) + AutoDewSettingsNP.update(values, names, n); + AutoDewSettingsNP.apply(); return true; } // Focuser Settings - if (!strcmp(name, FocuserSettingsNP.name)) + if (FocuserSettingsNP.isNameMatch(name)) { if (setFocuserMaxSpeed(values[0])) { - FocuserSettingsN[0].value = values[0]; - FocuserSettingsNP.s = IPS_OK; + FocuserSettingsNP[SETTING_MAX_SPEED].setValue(values[0]); + FocuserSettingsNP.setState(IPS_OK); } else { - FocuserSettingsNP.s = IPS_ALERT; + FocuserSettingsNP.setState(IPS_ALERT); } - IDSetNumber(&FocuserSettingsNP, nullptr); + FocuserSettingsNP.apply(); return true; } @@ -626,10 +626,10 @@ bool PegasusPPBA::setAutoDewAggression(uint8_t value) bool PegasusPPBA::setPowerOnBoot() { char cmd[PEGASUS_LEN] = {0}, res[PEGASUS_LEN] = {0}; - snprintf(cmd, PEGASUS_LEN, "PE:%d%d%d%d", PowerOnBootS[0].s == ISS_ON ? 1 : 0, - PowerOnBootS[1].s == ISS_ON ? 1 : 0, - PowerOnBootS[2].s == ISS_ON ? 1 : 0, - PowerOnBootS[3].s == ISS_ON ? 1 : 0); + snprintf(cmd, PEGASUS_LEN, "PE:%d%d%d%d", PowerOnBootSP[POWER_PORT_1].getState() == ISS_ON ? 1 : 0, + PowerOnBootSP[POWER_PORT_2].getState() == ISS_ON ? 1 : 0, + PowerOnBootSP[POWER_PORT_3].getState() == ISS_ON ? 1 : 0, + PowerOnBootSP[POWER_PORT_4].getState() == ISS_ON ? 1 : 0); if (sendCommand(cmd, res)) { return (!strcmp(res, "PE:1")); @@ -657,12 +657,12 @@ bool PegasusPPBA::saveConfigItems(FILE * fp) if (m_HasExternalMotor) { FI::saveConfigItems(fp); - IUSaveConfigNumber(fp, &FocuserSettingsNP); - IUSaveConfigSwitch(fp, &FocuserDriveSP); + FocuserSettingsNP.save(fp); + FocuserDriveSP.save(fp); } WI::saveConfigItems(fp); - IUSaveConfigSwitch(fp, &AutoDewSP); - IUSaveConfigNumber(fp, &AutoDewSettingsNP); + AutoDewSP.save(fp); + AutoDewSettingsNP.save(fp); return true; } @@ -690,8 +690,8 @@ bool PegasusPPBA::sendFirmware() if (sendCommand("PV", res)) { LOGF_INFO("Detected firmware %s", res); - IUSaveText(&FirmwareT[FIRMWARE_VERSION], res); - IDSetText(&FirmwareTP, nullptr); + FirmwareTP[FIRMWARE_VERSION].setText(res); + FirmwareTP.apply(); return true; } @@ -714,11 +714,11 @@ bool PegasusPPBA::getSensorData() return true; // Power Sensors - PowerSensorsN[SENSOR_VOLTAGE].value = std::stod(result[PA_VOLTAGE]); - PowerSensorsN[SENSOR_CURRENT].value = std::stod(result[PA_CURRENT]) / 65.0; - PowerSensorsNP.s = IPS_OK; + PowerSensorsNP[SENSOR_VOLTAGE].setValue(std::stod(result[PA_VOLTAGE])); + PowerSensorsNP[SENSOR_CURRENT].setValue(std::stod(result[PA_CURRENT]) / 65.0); + PowerSensorsNP.setState(IPS_OK); if (lastSensorData[PA_VOLTAGE] != result[PA_VOLTAGE] || lastSensorData[PA_CURRENT] != result[PA_CURRENT]) - IDSetNumber(&PowerSensorsNP, nullptr); + PowerSensorsNP.apply(); // Environment Sensors setParameterValue("WEATHER_TEMPERATURE", std::stod(result[PA_TEMPERATURE])); @@ -735,11 +735,11 @@ bool PegasusPPBA::getSensorData() } // Power Status - QuadOutS[INDI_ENABLED].s = (std::stoi(result[PA_PORT_STATUS]) == 1) ? ISS_ON : ISS_OFF; - QuadOutS[INDI_DISABLED].s = (std::stoi(result[PA_PORT_STATUS]) == 1) ? ISS_OFF : ISS_ON; - QuadOutSP.s = (std::stoi(result[6]) == 1) ? IPS_OK : IPS_IDLE; + QuadOutSP[INDI_ENABLED].setState((std::stoi(result[PA_PORT_STATUS]) == 1) ? ISS_ON : ISS_OFF); + QuadOutSP[INDI_DISABLED].setState((std::stoi(result[PA_PORT_STATUS]) == 1) ? ISS_OFF : ISS_ON); + QuadOutSP.setState((std::stoi(result[6]) == 1) ? IPS_OK : IPS_IDLE); if (lastSensorData[PA_PORT_STATUS] != result[PA_PORT_STATUS]) - IDSetSwitch(&QuadOutSP, nullptr); + QuadOutSP.apply(); // Adjustable Power Status // AdjOutS[INDI_ENABLED].s = (std::stoi(result[PA_ADJ_STATUS]) == 1) ? ISS_ON : ISS_OFF; @@ -749,38 +749,38 @@ bool PegasusPPBA::getSensorData() // IDSetSwitch(&AdjOutSP, nullptr); // Adjustable Power Status - IUResetSwitch(&AdjOutVoltSP); + AdjOutVoltSP.reset(); if (std::stoi(result[PA_ADJ_STATUS]) == 0) - AdjOutVoltS[ADJOUT_OFF].s = ISS_ON; + AdjOutVoltSP[ADJOUT_OFF].setState(ISS_ON); else { - AdjOutVoltS[ADJOUT_3V].s = (std::stoi(result[PA_PWRADJ]) == 3) ? ISS_ON : ISS_OFF; - AdjOutVoltS[ADJOUT_5V].s = (std::stoi(result[PA_PWRADJ]) == 5) ? ISS_ON : ISS_OFF; - AdjOutVoltS[ADJOUT_8V].s = (std::stoi(result[PA_PWRADJ]) == 8) ? ISS_ON : ISS_OFF; - AdjOutVoltS[ADJOUT_9V].s = (std::stoi(result[PA_PWRADJ]) == 9) ? ISS_ON : ISS_OFF; - AdjOutVoltS[ADJOUT_12V].s = (std::stoi(result[PA_PWRADJ]) == 12) ? ISS_ON : ISS_OFF; + AdjOutVoltSP[ADJOUT_3V].setState((std::stoi(result[PA_PWRADJ]) == 3) ? ISS_ON : ISS_OFF); + AdjOutVoltSP[ADJOUT_5V].setState((std::stoi(result[PA_PWRADJ]) == 5) ? ISS_ON : ISS_OFF); + AdjOutVoltSP[ADJOUT_8V].setState((std::stoi(result[PA_PWRADJ]) == 8) ? ISS_ON : ISS_OFF); + AdjOutVoltSP[ADJOUT_9V].setState((std::stoi(result[PA_PWRADJ]) == 9) ? ISS_ON : ISS_OFF); + AdjOutVoltSP[ADJOUT_12V].setState((std::stoi(result[PA_PWRADJ]) == 12) ? ISS_ON : ISS_OFF); } if (lastSensorData[PA_PWRADJ] != result[PA_PWRADJ] || lastSensorData[PA_ADJ_STATUS] != result[PA_ADJ_STATUS]) - IDSetSwitch(&AdjOutVoltSP, nullptr); + AdjOutVoltSP.apply(); // Power Warn - PowerWarnL[0].s = (std::stoi(result[PA_PWR_WARN]) == 1) ? IPS_ALERT : IPS_OK; - PowerWarnLP.s = (std::stoi(result[PA_PWR_WARN]) == 1) ? IPS_ALERT : IPS_OK; + PowerWarnLP[0].setState((std::stoi(result[PA_PWR_WARN]) == 1) ? IPS_ALERT : IPS_OK); + PowerWarnLP.setState((std::stoi(result[PA_PWR_WARN]) == 1) ? IPS_ALERT : IPS_OK); if (lastSensorData[PA_PWR_WARN] != result[PA_PWR_WARN]) - IDSetLight(&PowerWarnLP, nullptr); + PowerWarnLP.apply(); // Dew PWM - DewPWMN[0].value = std::stod(result[PA_DEW_1]) / 255.0 * 100.0; - DewPWMN[1].value = std::stod(result[PA_DEW_2]) / 255.0 * 100.0; + DewPWMNP[DEW_PWM_A].setValue(std::stod(result[PA_DEW_1]) / 255.0 * 100.0); + DewPWMNP[DEW_PWM_B].setValue(std::stod(result[PA_DEW_2]) / 255.0 * 100.0); if (lastSensorData[PA_DEW_1] != result[PA_DEW_1] || lastSensorData[PA_DEW_2] != result[PA_DEW_2]) - IDSetNumber(&DewPWMNP, nullptr); + DewPWMNP.apply(); // Auto Dew - AutoDewS[INDI_DISABLED].s = (std::stoi(result[PA_AUTO_DEW]) == 1) ? ISS_OFF : ISS_ON; - AutoDewS[INDI_ENABLED].s = (std::stoi(result[PA_AUTO_DEW]) == 1) ? ISS_ON : ISS_OFF; - AutoDewSP.s = (std::stoi(result[PA_AUTO_DEW]) == 1) ? IPS_OK : IPS_IDLE; + AutoDewSP[INDI_DISABLED].setState((std::stoi(result[PA_AUTO_DEW]) == 1) ? ISS_OFF : ISS_ON); + AutoDewSP[INDI_ENABLED].setState((std::stoi(result[PA_AUTO_DEW]) == 1) ? ISS_ON : ISS_OFF); + AutoDewSP.setState((std::stoi(result[PA_AUTO_DEW]) == 1) ? IPS_OK : IPS_IDLE); if (lastSensorData[PA_AUTO_DEW] != result[PA_AUTO_DEW]) - IDSetSwitch(&AutoDewSP, nullptr); + AutoDewSP.apply(); lastSensorData = result; @@ -806,13 +806,13 @@ bool PegasusPPBA::getConsumptionData() return true; // Power Sensors - PowerSensorsN[SENSOR_AVG_AMPS].value = std::stod(result[PS_AVG_AMPS]); - PowerSensorsN[SENSOR_AMP_HOURS].value = std::stod(result[PS_AMP_HOURS]); - PowerSensorsN[SENSOR_WATT_HOURS].value = std::stod(result[PS_WATT_HOURS]); - PowerSensorsNP.s = IPS_OK; + PowerSensorsNP[SENSOR_AVG_AMPS].setValue(std::stod(result[PS_AVG_AMPS])); + PowerSensorsNP[SENSOR_AMP_HOURS].setValue(std::stod(result[PS_AMP_HOURS])); + PowerSensorsNP[SENSOR_WATT_HOURS].setValue(std::stod(result[PS_WATT_HOURS])); + PowerSensorsNP.setState(IPS_OK); if (lastConsumptionData[PS_AVG_AMPS] != result[PS_AVG_AMPS] || lastConsumptionData[PS_AMP_HOURS] != result[PS_AMP_HOURS] || lastConsumptionData[PS_WATT_HOURS] != result[PS_WATT_HOURS]) - IDSetNumber(&PowerSensorsNP, nullptr); + PowerSensorsNP.apply(); lastConsumptionData = result; @@ -830,13 +830,13 @@ bool PegasusPPBA::getAutoDewAggression() uint32_t value = 0; sscanf(res, "%*[^:]:%d", &value); - AutoDewSettingsN[AUTO_DEW_AGGRESSION].value = 100 * value / 255; + AutoDewSettingsNP[AUTO_DEW_AGGRESSION].setValue(100 * value / 255); } else - AutoDewSettingsNP.s = IPS_ALERT; + AutoDewSettingsNP.setState(IPS_ALERT); - IDSetNumber(&AutoDewSettingsNP, nullptr); - return AutoDewSettingsNP.s != IPS_ALERT; + AutoDewSettingsNP.apply(); + return AutoDewSettingsNP.getState() != IPS_ALERT; } bool PegasusPPBA::getMetricsData() @@ -855,23 +855,23 @@ bool PegasusPPBA::getMetricsData() return true; // Power Sensors - PowerSensorsN[SENSOR_TOTAL_CURRENT].value = std::stod(result[PC_TOTAL_CURRENT]); - PowerSensorsN[SENSOR_12V_CURRENT].value = std::stod(result[PC_12V_CURRENT]); - PowerSensorsN[SENSOR_DEWA_CURRENT].value = std::stod(result[PC_DEWA_CURRENT]); - PowerSensorsN[SENSOR_DEWB_CURRENT].value = std::stod(result[PC_DEWB_CURRENT]); - PowerSensorsNP.s = IPS_OK; + PowerSensorsNP[SENSOR_TOTAL_CURRENT].setValue(std::stod(result[PC_TOTAL_CURRENT])); + PowerSensorsNP[SENSOR_12V_CURRENT].setValue(std::stod(result[PC_12V_CURRENT])); + PowerSensorsNP[SENSOR_DEWA_CURRENT].setValue(std::stod(result[PC_DEWA_CURRENT])); + PowerSensorsNP[SENSOR_DEWB_CURRENT].setValue(std::stod(result[PC_DEWB_CURRENT])); + PowerSensorsNP.setState(IPS_OK); if (lastMetricsData[PC_TOTAL_CURRENT] != result[PC_TOTAL_CURRENT] || lastMetricsData[PC_12V_CURRENT] != result[PC_12V_CURRENT] || lastMetricsData[PC_DEWA_CURRENT] != result[PC_DEWA_CURRENT] || lastMetricsData[PC_DEWB_CURRENT] != result[PC_DEWB_CURRENT]) - IDSetNumber(&PowerSensorsNP, nullptr); + PowerSensorsNP.apply(); std::chrono::milliseconds uptime(std::stol(result[PC_UPTIME])); using dhours = std::chrono::duration>; std::stringstream ss; ss << std::fixed << std::setprecision(3) << dhours(uptime).count(); - IUSaveText(&FirmwareT[FIRMWARE_UPTIME], ss.str().c_str()); - IDSetText(&FirmwareTP, nullptr); + FirmwareTP[FIRMWARE_UPTIME].setText(ss.str().c_str()); + FirmwareTP.apply(); lastMetricsData = result; @@ -989,7 +989,7 @@ bool PegasusPPBA::getXMCStartupData() { uint32_t speed = 0; sscanf(res, "%*[^#]#%d", &speed); - FocuserSettingsN[0].value = speed; + FocuserSettingsNP[SETTING_MAX_SPEED].setValue(speed); } return true; diff --git a/drivers/auxiliary/pegasus_ppba.h b/drivers/auxiliary/pegasus_ppba.h index b10f0bf629..8098a2c17c 100644 --- a/drivers/auxiliary/pegasus_ppba.h +++ b/drivers/auxiliary/pegasus_ppba.h @@ -154,12 +154,10 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p /// Main Control //////////////////////////////////////////////////////////////////////////////////// /// Reboot Device - ISwitch RebootS[1]; - ISwitchVectorProperty RebootSP; + INDI::PropertySwitch RebootSP {1}; // Power Sensors - INumber PowerSensorsN[9]; - INumberVectorProperty PowerSensorsNP; + INDI::PropertyNumber PowerSensorsNP {9}; enum { SENSOR_VOLTAGE, @@ -177,14 +175,12 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p /// Power Group //////////////////////////////////////////////////////////////////////////////////// - ISwitch QuadOutS[2]; - ISwitchVectorProperty QuadOutSP; + INDI::PropertySwitch QuadOutSP {2}; // ISwitch AdjOutS[2]; // ISwitchVectorProperty AdjOutSP; - ISwitch AdjOutVoltS[6]; - ISwitchVectorProperty AdjOutVoltSP; + INDI::PropertySwitch AdjOutVoltSP {6}; enum { ADJOUT_OFF, @@ -196,34 +192,35 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p }; // Select which power is ON on bootup - ISwitch PowerOnBootS[4]; - ISwitchVectorProperty PowerOnBootSP; + INDI::PropertySwitch PowerOnBootSP {4}; + enum + { + POWER_PORT_1, + POWER_PORT_2, + POWER_PORT_3, + POWER_PORT_4 + }; // Short circuit warn - ILight PowerWarnL[1]; - ILightVectorProperty PowerWarnLP; + INDI::PropertyLight PowerWarnLP {1}; - ISwitch LedIndicatorS[2]; - ISwitchVectorProperty LedIndicatorSP; + INDI::PropertySwitch LedIndicatorSP{2}; //////////////////////////////////////////////////////////////////////////////////// /// Dew Group //////////////////////////////////////////////////////////////////////////////////// // Auto Dew - ISwitch AutoDewS[2]; - ISwitchVectorProperty AutoDewSP; + INDI::PropertySwitch AutoDewSP {2}; - INumber AutoDewSettingsN[1]; - INumberVectorProperty AutoDewSettingsNP; + INDI::PropertyNumber AutoDewSettingsNP {1}; enum { AUTO_DEW_AGGRESSION }; // Dew PWM - INumber DewPWMN[2]; - INumberVectorProperty DewPWMNP; + INDI::PropertyNumber DewPWMNP {2}; enum { DEW_PWM_A, @@ -235,16 +232,14 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p //////////////////////////////////////////////////////////////////////////////////// // Focuser speed - INumber FocuserSettingsN[1]; - INumberVectorProperty FocuserSettingsNP; + INDI::PropertyNumber FocuserSettingsNP {1}; enum { SETTING_MAX_SPEED, }; // Microstepping - ISwitchVectorProperty FocuserDriveSP; - ISwitch FocuserDriveS[4]; + INDI::PropertySwitch FocuserDriveSP {4}; enum { STEP_FULL, @@ -259,8 +254,7 @@ class PegasusPPBA : public INDI::DefaultDevice, public INDI::FocuserInterface, p /// Firmware //////////////////////////////////////////////////////////////////////////////////// - ITextVectorProperty FirmwareTP; - IText FirmwareT[2] {}; + INDI::PropertyText FirmwareTP {2}; enum { FIRMWARE_VERSION,