Skip to content

Commit

Permalink
Fix bug with critical parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Jun 13, 2024
1 parent 0f2243f commit aa1cb9a
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions libs/indibase/indiweatherinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,10 +248,10 @@ IPState WeatherInterface::updateWeather()
////////////////////////////////////////////////////////////////////////////////////
void WeatherInterface::addParameter(std::string name, std::string label, double numMinOk, double numMaxOk, double percWarning)
{
LOGF_DEBUG("Parameter %s is added. Ok (%g,%g,%g) ", name.c_str(), numMinOk, numMaxOk, percWarning);
LOGF_DEBUG("Parameter %s is added. Ok (%.2f,%.2f,%.2f) ", name.c_str(), numMinOk, numMaxOk, percWarning);

INDI::WidgetNumber oneParameter;
oneParameter.fill(name.c_str(), label.c_str(), "%4.2f", numMinOk, numMaxOk, 0, 0);
oneParameter.fill(name.c_str(), label.c_str(), "%.2f", numMinOk, numMaxOk, 0, 0);
ParametersNP.push(std::move(oneParameter));

if (numMinOk != numMaxOk)
Expand Down Expand Up @@ -286,7 +286,6 @@ bool WeatherInterface::setCriticalParameter(std::string name)
return true;
}


////////////////////////////////////////////////////////////////////////////////////
//
////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -297,22 +296,24 @@ IPState WeatherInterface::checkParameterState(const std::string &name) const
return oneElement.isNameMatch(name);
});

// Not
if (oneRange == ParametersRangeNP.end())
auto oneParameter = ParametersNP.findWidgetByName(name.c_str());
if (!oneParameter)
return IPS_IDLE;

// If parameter is found but not in range, then it is a critical parameter
if (oneRange == ParametersRangeNP.end())
{
if (oneParameter->getMin() == 0 && oneParameter->getMax() == 0 && oneParameter->getValue() != 0)
return IPS_ALERT;
else
return IPS_IDLE;
}

auto minLimit = (*oneRange)[MIN_OK].getValue();
auto maxLimit = (*oneRange)[MAX_OK].getValue();
auto percentageWarning = (*oneRange)[PERCENT_WARNING].getValue();
auto rangeWarn = (maxLimit - minLimit) * (percentageWarning / 100);

if (minLimit == 0 && maxLimit == 0)
return IPS_IDLE;

auto oneParameter = ParametersNP.findWidgetByName(name.c_str());
if (!oneParameter)
return IPS_IDLE;

auto value = oneParameter->getValue();

if (value < minLimit || value > maxLimit)
Expand Down

0 comments on commit aa1cb9a

Please sign in to comment.