From 6cb22894eca53d4c75784bfa4339b7aecc990ff4 Mon Sep 17 00:00:00 2001 From: naheedsa <97088153+naheedsa@users.noreply.github.com> Date: Sun, 3 Mar 2024 18:36:37 +0300 Subject: [PATCH] Migrate mBox (#2017) --- drivers/weather/mbox.cpp | 96 ++++++++++++++++++++-------------------- drivers/weather/mbox.h | 9 ++-- 2 files changed, 51 insertions(+), 54 deletions(-) diff --git a/drivers/weather/mbox.cpp b/drivers/weather/mbox.cpp index b832d5f653..fa762ac0d8 100644 --- a/drivers/weather/mbox.cpp +++ b/drivers/weather/mbox.cpp @@ -61,20 +61,20 @@ bool MBox::initProperties() setCriticalParameter("WEATHER_TEMPERATURE"); // Reset Calibration - IUFillSwitch(&ResetS[0], "RESET", "Reset", ISS_OFF); - IUFillSwitchVector(&ResetSP, ResetS, 1, getDeviceName(), "CALIBRATION_RESET", "Reset", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, + ResetSP[0].fill("RESET", "Reset", ISS_OFF); + ResetSP.fill(getDeviceName(), "CALIBRATION_RESET", "Reset", MAIN_CONTROL_TAB, IP_RW, ISR_1OFMANY, 0, IPS_IDLE); // Calibration Properties - IUFillNumber(&CalibrationN[CAL_TEMPERATURE], "CAL_TEMPERATURE", "Temperature", "%.f", -50, 50, 1, 0); - IUFillNumber(&CalibrationN[CAL_PRESSURE], "CAL_PRESSURE", "Pressure", "%.f", -100, 100, 10, 0); - IUFillNumber(&CalibrationN[CAL_HUMIDITY], "CAL_HUMIDITY", "Humidity", "%.f", -50, 50, 1, 0); - IUFillNumberVector(&CalibrationNP, CalibrationN, 3, getDeviceName(), "CALIBRATION", "Calibration", MAIN_CONTROL_TAB, IP_RW, + CalibrationNP[CAL_TEMPERATURE].fill("CAL_TEMPERATURE", "Temperature", "%.f", -50, 50, 1, 0); + CalibrationNP[CAL_PRESSURE].fill("CAL_PRESSURE", "Pressure", "%.f", -100, 100, 10, 0); + CalibrationNP[CAL_HUMIDITY].fill("CAL_HUMIDITY", "Humidity", "%.f", -50, 50, 1, 0); + CalibrationNP.fill(getDeviceName(), "CALIBRATION", "Calibration", MAIN_CONTROL_TAB, IP_RW, 0, IPS_IDLE); // Firmware Information - IUFillText(&FirmwareT[0], "VERSION", "Version", "--"); - IUFillTextVector(&FirmwareTP, FirmwareT, 1, getDeviceName(), "DEVICE_FIRMWARE", "Firmware", MAIN_CONTROL_TAB, IP_RO, 0, + FirmwareTP[0].fill("VERSION", "Version", "--"); + FirmwareTP.fill(getDeviceName(), "DEVICE_FIRMWARE", "Firmware", MAIN_CONTROL_TAB, IP_RO, 0, IPS_IDLE); serialConnection->setDefaultBaudRate(Connection::Serial::B_38400); @@ -90,15 +90,15 @@ bool MBox::updateProperties() if (isConnected()) { - defineProperty(&CalibrationNP); - defineProperty(&ResetSP); - defineProperty(&FirmwareTP); + defineProperty(CalibrationNP); + defineProperty(ResetSP); + defineProperty(FirmwareTP); } else { - deleteProperty(CalibrationNP.name); - deleteProperty(ResetSP.name); - deleteProperty(FirmwareTP.name); + deleteProperty(CalibrationNP.getName()); + deleteProperty(ResetSP.getName()); + deleteProperty(FirmwareTP.getName()); } return true; @@ -125,7 +125,7 @@ bool MBox::Handshake() else if (rc == ACK_OK_INIT) { //getCalibration(true); - CalibrationNP.s = IPS_BUSY; + CalibrationNP.setState(IPS_BUSY); return true; } @@ -136,12 +136,12 @@ IPState MBox::updateWeather() { char response[MBOX_BUF]; - if (CalibrationNP.s == IPS_BUSY) + if (CalibrationNP.getState() == IPS_BUSY) { if (getCalibration(true)) { - CalibrationNP.s = IPS_OK; - IDSetNumber(&CalibrationNP, nullptr); + CalibrationNP.setState(IPS_OK); + CalibrationNP.apply(); } } @@ -188,11 +188,11 @@ IPState MBox::updateWeather() setParameterValue("WEATHER_TEMPERATURE", std::stod(result[SENSOR_TEMPERATURE])); setParameterValue("WEATHER_HUMIDITY", std::stod(result[SENSOR_HUMIDITY])); setParameterValue("WEATHER_DEWPOINT", std::stod(result[SENSOR_DEW])); - if (strcmp(result[FIRMWARE].c_str(), FirmwareT[0].text)) + if (strcmp(result[FIRMWARE].c_str(), FirmwareTP[0].getText())) { - IUSaveText(&FirmwareT[0], result[FIRMWARE].c_str()); - FirmwareTP.s = IPS_OK; - IDSetText(&FirmwareTP, nullptr); + FirmwareTP[0].setText(result[FIRMWARE].c_str()); + FirmwareTP.setState(IPS_OK); + FirmwareTP.apply(); } return IPS_OK; @@ -250,15 +250,15 @@ bool MBox::ISNewNumber(const char *dev, const char *name, double values[], char { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (!strcmp(name, CalibrationNP.name)) + if (CalibrationNP.isNameMatch(name)) { - double prevPressure = CalibrationN[CAL_PRESSURE].value; - double prevTemperature = CalibrationN[CAL_TEMPERATURE].value; - double prevHumidaty = CalibrationN[CAL_HUMIDITY].value; - IUUpdateNumber(&CalibrationNP, values, names, n); - double targetPressure = CalibrationN[CAL_PRESSURE].value; - double targetTemperature = CalibrationN[CAL_TEMPERATURE].value; - double targetHumidity = CalibrationN[CAL_HUMIDITY].value; + double prevPressure = CalibrationNP[CAL_PRESSURE].getValue(); + double prevTemperature = CalibrationNP[CAL_TEMPERATURE].getValue(); + double prevHumidaty = CalibrationNP[CAL_HUMIDITY].getValue(); + CalibrationNP.update(values, names, n); + double targetPressure = CalibrationNP[CAL_PRESSURE].getValue(); + double targetTemperature = CalibrationNP[CAL_TEMPERATURE].getValue(); + double targetHumidity = CalibrationNP[CAL_HUMIDITY].getValue(); bool rc = true; if (targetPressure != prevPressure) @@ -276,8 +276,8 @@ bool MBox::ISNewNumber(const char *dev, const char *name, double values[], char rc = setCalibration(CAL_HUMIDITY); } - CalibrationNP.s = rc ? IPS_OK : IPS_ALERT; - IDSetNumber(&CalibrationNP, nullptr); + CalibrationNP.setState(rc ? IPS_OK : IPS_ALERT); + CalibrationNP.apply(); return true; } } @@ -289,24 +289,24 @@ bool MBox::ISNewSwitch(const char *dev, const char *name, ISState *states, char { if (dev != nullptr && strcmp(dev, getDeviceName()) == 0) { - if (!strcmp(name, ResetSP.name)) + if (ResetSP.isNameMatch(name)) { if (resetCalibration()) { - ResetSP.s = IPS_OK; - IDSetSwitch(&ResetSP, nullptr); + ResetSP.setState(IPS_OK); + ResetSP.apply(); LOG_INFO("Calibration values are reset."); - CalibrationN[CAL_PRESSURE].value = 0; - CalibrationN[CAL_TEMPERATURE].value = 0; - CalibrationN[CAL_HUMIDITY].value = 0; - CalibrationNP.s = IPS_IDLE; - IDSetNumber(&CalibrationNP, nullptr); + CalibrationNP[CAL_PRESSURE].setValue(0); + CalibrationNP[CAL_TEMPERATURE].setValue(0); + CalibrationNP[CAL_HUMIDITY].setValue(0); + CalibrationNP.setState(IPS_IDLE); + CalibrationNP.apply(); } else { - ResetSP.s = IPS_ALERT; - IDSetSwitch(&ResetSP, nullptr); + ResetSP.setState(IPS_ALERT); + ResetSP.apply(); } @@ -385,9 +385,9 @@ bool MBox::getCalibration(bool sendCommand) // PCAL std::vector result = split(response, ","); - CalibrationN[CAL_PRESSURE].value = std::stod(result[SENSOR_PRESSURE]) / 10.0; - CalibrationN[CAL_TEMPERATURE].value = std::stod(result[SENSOR_PRESSURE + 2]) / 10.0; - CalibrationN[CAL_HUMIDITY].value = std::stod(result[SENSOR_PRESSURE + 4]) / 10.0; + CalibrationNP[CAL_PRESSURE].setValue(std::stod(result[SENSOR_PRESSURE]) / 10.0); + CalibrationNP[CAL_TEMPERATURE].setValue(std::stod(result[SENSOR_PRESSURE + 2]) / 10.0); + CalibrationNP[CAL_HUMIDITY].setValue(std::stod(result[SENSOR_PRESSURE + 4]) / 10.0); return true; } @@ -400,7 +400,7 @@ bool MBox::setCalibration(CalibrationType type) if (type == CAL_PRESSURE) { // Pressure. - snprintf(command, 16, ":calp,%d*", static_cast(CalibrationN[CAL_PRESSURE].value * 10.0)); + snprintf(command, 16, ":calp,%d*", static_cast(CalibrationNP[CAL_PRESSURE].getValue() * 10.0)); LOGF_DEBUG("CMD <%s>", command); @@ -420,7 +420,7 @@ bool MBox::setCalibration(CalibrationType type) else if (type == CAL_TEMPERATURE) { // Temperature - snprintf(command, 16, ":calt,%d*", static_cast(CalibrationN[CAL_TEMPERATURE].value * 10.0)); + snprintf(command, 16, ":calt,%d*", static_cast(CalibrationNP[CAL_TEMPERATURE].getValue() * 10.0)); LOGF_DEBUG("CMD <%s>", command); @@ -439,7 +439,7 @@ bool MBox::setCalibration(CalibrationType type) else { // Humidity - snprintf(command, 16, ":calh,%d*", static_cast(CalibrationN[CAL_HUMIDITY].value * 10.0)); + snprintf(command, 16, ":calh,%d*", static_cast(CalibrationNP[CAL_HUMIDITY].getValue() * 10.0)); LOGF_DEBUG("CMD <%s>", command); diff --git a/drivers/weather/mbox.h b/drivers/weather/mbox.h index aef89c5b94..8f54fe4f5e 100644 --- a/drivers/weather/mbox.h +++ b/drivers/weather/mbox.h @@ -64,14 +64,11 @@ class MBox : public INDI::Weather std::vector split(const std::string &input, const std::string ®ex); - INumber CalibrationN[3]; - INumberVectorProperty CalibrationNP; + INDI::PropertyNumber CalibrationNP {3}; - ISwitch ResetS[1]; - ISwitchVectorProperty ResetSP; + INDI::PropertySwitch ResetSP {1}; - IText FirmwareT[1] {}; - ITextVectorProperty FirmwareTP; + INDI::PropertyText FirmwareTP {1};