33class TMP102 :
public Thermometer {
35 explicit TMP102(uint8_t address = 0x48,
36 TwoWire *wire = &Wire,
40 bool alertPolarity =
false,
42 bool alertMode =
false) : alertMode_(alertMode) {
43 if (!tmp102_.begin(address, *wire)) {
44 SUPLA_LOG_ERROR(
"Unable to find TMP102 at address: 0x%x", address);
46 SUPLA_LOG_DEBUG(
"TMP102 is connected at address: 0x%x", address);
48 tmp102_.setHighTempC(hTemp);
49 tmp102_.setLowTempC(lTemp);
50 tmp102_.setExtendedMode(extMode);
51 tmp102_.setAlertPolarity(alertPolarity);
52 tmp102_.setFault(fault);
53 tmp102_.setAlertMode(alertMode);
59 channel.setNewValue(getTemp());
62 double getTemp()
override {
64 double temp = tmp102_.readTempC();
65 if (temp >= -55.0 && temp <= 128.0) {
66 return round(temp * 100) / 100.0;
68 SUPLA_LOG_WARNING(
"[TMP102] invalid temperature reading: %f", temp);
69 return TEMPERATURE_NOT_AVAILABLE;
72 return TEMPERATURE_NOT_AVAILABLE;
76 bool getAlertState() {
77 bool raw = tmp102_.alert();
78 return alertMode_ ? raw : !raw;
83 bool alertMode_ -
false;
84 bool isConnected_ =
false;