Skip to content

Commit

Permalink
Fix weather refactor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Mar 13, 2024
1 parent 1567bfa commit 60b21bb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 54 deletions.
9 changes: 5 additions & 4 deletions indi-astrolink4/indi_astrolink4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,8 @@ bool IndiAstrolink4::initProperties()
// Auto pwm
IUFillSwitch(&AutoPWMDefaultOnS[0], "PWMA_A_DEF_ON", "A", ISS_OFF);
IUFillSwitch(&AutoPWMDefaultOnS[1], "PWMA_B_DEF_ON", "B", ISS_OFF);
IUFillSwitchVector(&AutoPWMDefaultOnSP, AutoPWMDefaultOnS, 2, getDeviceName(), "AUTO_PWM_DEF_ON", "Auto PWM default ON", SETTINGS_TAB,
IUFillSwitchVector(&AutoPWMDefaultOnSP, AutoPWMDefaultOnS, 2, getDeviceName(), "AUTO_PWM_DEF_ON", "Auto PWM default ON",
SETTINGS_TAB,
IP_RW, ISR_NOFMANY, 60, IPS_IDLE);

ISState pwmAutoA = ISS_OFF;
Expand Down Expand Up @@ -853,12 +854,12 @@ bool IndiAstrolink4::sensorRead()
setParameterValue("WEATHER_TEMPERATURE", std::stod(result[Q_SENS1_TEMP]));
setParameterValue("WEATHER_HUMIDITY", std::stod(result[Q_SENS1_HUM]));
setParameterValue("WEATHER_DEWPOINT", std::stod(result[Q_SENS1_DEW]));
ParametersNP.s = IPS_OK;
IDSetNumber(&ParametersNP, nullptr);
ParametersNP.setState(IPS_OK);
ParametersNP.apply();
}
else
{
ParametersNP.s = IPS_IDLE;
ParametersNP.setState(IPS_IDLE);
}

if(std::stod(result[Q_SENS2_TYPE]) > 0)
Expand Down
51 changes: 7 additions & 44 deletions indi-duino/weatherradio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,29 +355,6 @@ bool WeatherRadio::updateProperties()

result = INDI::Weather::updateProperties();

// clean up weather interface parameters to avoid doubling when reconnecting
for (int i = 0; i < WeatherInterface::ParametersNP.nnp; i++)
{
free(WeatherInterface::ParametersN[i].aux0);
free(WeatherInterface::ParametersN[i].aux1);
free(WeatherInterface::ParametersRangeNP[i].np);
}

free(WeatherInterface::ParametersN);
WeatherInterface::ParametersN = nullptr;
WeatherInterface::ParametersNP.nnp = 0;
if (WeatherInterface::ParametersRangeNP != nullptr)
{
WeatherInterface::ParametersRangeNP->nnp = 0;
free(WeatherInterface::ParametersRangeNP);
WeatherInterface::ParametersRangeNP = nullptr;
}
WeatherInterface::nRanges = 0;

free(WeatherInterface::critialParametersL);
WeatherInterface::critialParametersL = nullptr;
WeatherInterface::critialParametersLP.nlp = 0;

// clear firmware configuration so that #handleFirmwareVersion() recongnizes an initialisation
FirmwareConfigTP.tp = nullptr;
free(FirmwareConfigT);
Expand Down Expand Up @@ -1137,9 +1114,10 @@ void WeatherRadio::updateWeatherParameter(WeatherRadio::sensor_name sensor, doub
double elevation = LocationN[LOCATION_ELEVATION].value;

double temp = 15.0; // default value
INumber *temperatureParameter = getWeatherParameter(WEATHER_TEMPERATURE);
if (temperatureParameter != nullptr)
temp = temperatureParameter->value;

auto temperatureParameter = ParametersNP.findWidgetByName(WEATHER_TEMPERATURE);
if (temperatureParameter)
temp = temperatureParameter->getValue();

double pressure_normalized = weatherCalculator->sealevelPressure(value, elevation, temp);
setParameterValue(WEATHER_PRESSURE, pressure_normalized);
Expand All @@ -1149,10 +1127,10 @@ void WeatherRadio::updateWeatherParameter(WeatherRadio::sensor_name sensor, doub
double humidity = weatherCalculator->calibrate(weatherCalculator->humidityCalibration, value);

setParameterValue(WEATHER_HUMIDITY, humidity);
INumber *temperatureParameter = getWeatherParameter(WEATHER_TEMPERATURE);
if (temperatureParameter != nullptr)
auto temperatureParameter = ParametersNP.findWidgetByName(WEATHER_TEMPERATURE);
if (temperatureParameter)
{
double dp = weatherCalculator->dewPoint(humidity, temperatureParameter->value);
double dp = weatherCalculator->dewPoint(humidity, temperatureParameter->getValue());
setParameterValue(WEATHER_DEWPOINT, dp);
}
}
Expand Down Expand Up @@ -1275,11 +1253,8 @@ bool WeatherRadio::saveConfigItems(FILE *fp)
IUSaveConfigSwitch(fp, &rainDropsSensorSP);
IUSaveConfigSwitch(fp, &rainVolumeSensorSP);
IUSaveConfigSwitch(fp, &wetnessSensorSP);
if (ParametersRangeNP != nullptr)
IUSaveConfigNumber(fp, ParametersRangeNP);
IUSaveConfigNumber(fp, &ttyTimeoutNP);


return INDI::Weather::saveConfigItems(fp);
}

Expand Down Expand Up @@ -1309,18 +1284,6 @@ INumber *WeatherRadio::findRawSensorProperty(WeatherRadio::sensor_name sensor)
return sensorProp;
}

INumber *WeatherRadio::getWeatherParameter(std::string name)
{
for (int i = 0; i < ParametersNP.nnp; i++)
{
if (!strcmp(ParametersN[i].name, name.c_str()))
return &ParametersN[i];
}
// not found
return nullptr;
}


/**************************************************************************************
**
***************************************************************************************/
Expand Down
7 changes: 1 addition & 6 deletions indi-duino/weatherradio.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,7 @@ class WeatherRadio : public INDI::Weather
/**
* @brief find the matching sensor INDI property
*/
INumber *findRawSensorProperty(const sensor_name sensor);

/**
* @brief Find a given weather parameter.
*/
INumber *getWeatherParameter(std::string name);
INumber *findRawSensorProperty(const sensor_name sensor);

/**
* @brief TTY interface timeout
Expand Down

0 comments on commit 60b21bb

Please sign in to comment.