You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TempInput.cpp 1000B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #include "TempInput.h"
  2. #include "globals.h"
  3. #include "defines.h"
  4. TempInput::TempInput(uint8_t index)
  5. : m_address{0}
  6. , m_index(index)
  7. , m_lastSensorRequestMs(0)
  8. , m_hasReadSensor(false)
  9. {
  10. }
  11. void TempInput::begin()
  12. {
  13. setValue(TEMP_T_INVALID);
  14. g_dallasTemperature.getAddress(m_address, m_index);
  15. }
  16. void TempInput::loop()
  17. {
  18. const auto& currentMs = millis();
  19. if (currentMs - m_lastSensorRequestMs >= SENSORS_CHECK_INTERVAL)
  20. {
  21. m_lastSensorRequestMs = currentMs;
  22. m_hasReadSensor = false;
  23. g_dallasTemperature.requestTemperaturesByAddress(m_address);
  24. }
  25. if (currentMs - m_lastSensorRequestMs >= SENSORS_REQUEST_DELAY &&
  26. !m_hasReadSensor)
  27. {
  28. m_hasReadSensor = true;
  29. auto raw = g_dallasTemperature.getTempC(m_address);
  30. temp_t temp = TEMP_T_INVALID;
  31. if (raw != DEVICE_DISCONNECTED_C)
  32. {
  33. temp = (temp_t) (raw * 10);
  34. }
  35. setValue(temp);
  36. }
  37. }