Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate mBox #2017

Merged
merged 1 commit into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 48 additions & 48 deletions drivers/weather/mbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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;
}
}
Expand All @@ -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();
}


Expand Down Expand Up @@ -385,9 +385,9 @@ bool MBox::getCalibration(bool sendCommand)

// PCAL
std::vector<std::string> 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;
}

Expand All @@ -400,7 +400,7 @@ bool MBox::setCalibration(CalibrationType type)
if (type == CAL_PRESSURE)
{
// Pressure.
snprintf(command, 16, ":calp,%d*", static_cast<int32_t>(CalibrationN[CAL_PRESSURE].value * 10.0));
snprintf(command, 16, ":calp,%d*", static_cast<int32_t>(CalibrationNP[CAL_PRESSURE].getValue() * 10.0));

LOGF_DEBUG("CMD <%s>", command);

Expand All @@ -420,7 +420,7 @@ bool MBox::setCalibration(CalibrationType type)
else if (type == CAL_TEMPERATURE)
{
// Temperature
snprintf(command, 16, ":calt,%d*", static_cast<int32_t>(CalibrationN[CAL_TEMPERATURE].value * 10.0));
snprintf(command, 16, ":calt,%d*", static_cast<int32_t>(CalibrationNP[CAL_TEMPERATURE].getValue() * 10.0));

LOGF_DEBUG("CMD <%s>", command);

Expand All @@ -439,7 +439,7 @@ bool MBox::setCalibration(CalibrationType type)
else
{
// Humidity
snprintf(command, 16, ":calh,%d*", static_cast<int32_t>(CalibrationN[CAL_HUMIDITY].value * 10.0));
snprintf(command, 16, ":calh,%d*", static_cast<int32_t>(CalibrationNP[CAL_HUMIDITY].getValue() * 10.0));

LOGF_DEBUG("CMD <%s>", command);

Expand Down
9 changes: 3 additions & 6 deletions drivers/weather/mbox.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,11 @@ class MBox : public INDI::Weather

std::vector<std::string> split(const std::string &input, const std::string &regex);

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};



Expand Down
Loading