123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- #include "TempInput.h"
- #include "globals.h"
- #include "defines.h"
- #include "Logs.h"
-
- TempInput::TempInput(uint8_t index)
- : m_address{0}
- , m_index(index)
- , m_lastSensorRequestMs(0)
- , m_hasReadSensor(false)
- {
- }
-
- void TempInput::begin()
- {
- setValue(TEMP_T_INVALID);
- g_dallasTemperature.getAddress(m_address, m_index);
- }
-
- void TempInput::loop()
- {
- const auto& currentMs = millis();
-
- if (currentMs - m_lastSensorRequestMs >= SENSORS_CHECK_INTERVAL)
- {
- LOG(5, "TempInput: requesting value");
- m_lastSensorRequestMs = currentMs;
- m_hasReadSensor = false;
- g_dallasTemperature.requestTemperaturesByAddress(m_address);
- }
- if (currentMs - m_lastSensorRequestMs >= SENSORS_REQUEST_DELAY &&
- !m_hasReadSensor)
- {
- LOG(5, "TempInput: reading value");
- m_hasReadSensor = true;
- auto raw = g_dallasTemperature.getTempC(m_address);
- temp_t temp = TEMP_T_INVALID;
- if (raw != DEVICE_DISCONNECTED_C)
- {
- temp = (temp_t) (raw * 10);
- }
- setValue(temp);
- }
- else
- {
- setValue(m_lastValue);
- }
- }
|