Skip to content

Commit

Permalink
Fix issue with reporting updated measurements due to creep in from cu…
Browse files Browse the repository at this point in the history
…mulative threshold
  • Loading branch information
knro committed Nov 8, 2023
1 parent d7c3b1b commit d045d17
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
18 changes: 10 additions & 8 deletions drivers/focuser/esatto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -321,22 +321,24 @@ void Esatto::TimerHit()

if (m_TemperatureCounter++ == TEMPERATURE_FREQUENCY)
{
auto externalTemperature = TemperatureNP[TEMPERATURE_EXTERNAL].value;
auto motorTemperature = TemperatureNP[TEMPERATURE_MOTOR].value;
rc = updateTemperature();

// Only update temperature if there is a change of 0.1 or more
if (rc && (std::abs(externalTemperature - TemperatureNP[TEMPERATURE_EXTERNAL].value) >= 0.1 ||
std::abs(motorTemperature - TemperatureNP[TEMPERATURE_MOTOR].value) >= 0.1 ))
if (rc && (std::abs(m_LastTemperature[TEMPERATURE_EXTERNAL] - TemperatureNP[TEMPERATURE_EXTERNAL].value) >= MEASUREMENT_THRESHOLD ||
std::abs(m_LastTemperature[TEMPERATURE_MOTOR] - TemperatureNP[TEMPERATURE_MOTOR].value) >= MEASUREMENT_THRESHOLD ))
{
m_LastTemperature[TEMPERATURE_EXTERNAL] = TemperatureNP[TEMPERATURE_EXTERNAL].value;
m_LastTemperature[TEMPERATURE_MOTOR] = TemperatureNP[TEMPERATURE_MOTOR].value;
TemperatureNP.apply();
}

auto current12V = VoltageNP[VOLTAGE_12V].getValue();
auto currentUSB = VoltageNP[VOLTAGE_USB].getValue();
if (updateVoltageIn())
{
if (std::abs(current12V - VoltageNP[VOLTAGE_12V].getValue()) >= 0.1 ||
std::abs(currentUSB - VoltageNP[VOLTAGE_USB].getValue()) >= 0.1)
if (std::abs(m_LastVoltage[VOLTAGE_12V] - VoltageNP[VOLTAGE_12V].getValue()) >= MEASUREMENT_THRESHOLD ||
std::abs(m_LastVoltage[VOLTAGE_USB] - VoltageNP[VOLTAGE_USB].getValue()) >= MEASUREMENT_THRESHOLD)
{
m_LastVoltage[VOLTAGE_12V] = VoltageNP[VOLTAGE_12V].getValue();
m_LastVoltage[VOLTAGE_USB] = VoltageNP[VOLTAGE_USB].getValue();
VoltageNP.apply();
if (VoltageNP[VOLTAGE_12V].getValue() < 11.0)
LOG_WARN("Please check 12v DC power supply is connected.");
Expand Down
3 changes: 3 additions & 0 deletions drivers/focuser/esatto.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class Esatto : public INDI::Focuser
void hexDump(char * buf, const char * data, int size);

uint16_t m_TemperatureCounter { 0 };
double m_LastTemperature[2] = {-1, -1};
double m_LastVoltage[2] = {-1, -1};

INDI::PropertyNumber TemperatureNP {2};
enum
Expand Down Expand Up @@ -91,4 +93,5 @@ class Esatto : public INDI::Focuser

std::unique_ptr<PrimalucaLabs::Esatto> m_Esatto;
static constexpr uint8_t TEMPERATURE_FREQUENCY {10};
static constexpr double MEASUREMENT_THRESHOLD {0.1};
};

0 comments on commit d045d17

Please sign in to comment.