Skip to content

Commit

Permalink
Merge pull request #8 from chinswain/main
Browse files Browse the repository at this point in the history
Add reed switch and counter
  • Loading branch information
matthias-bs authored Apr 7, 2024
2 parents 606d553 + 366d742 commit 6ca27f2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ void loop() {
Serial.printf("%.3fV\n", miThermometer.data[i].batt_voltage/1000.0);
Serial.printf("%d%%\n", miThermometer.data[i].batt_level);
Serial.printf("%ddBm\n", miThermometer.data[i].rssi);
Serial.printf("Measurement Count: %d\n", miThermometer.data[i].count);
// Print boolean flags
Serial.printf("Reed Switch State: %s\n", miThermometer.data[i].reedSwitchState ? "Open" : "Closed");
Serial.printf("GPIO TRG Output: %s\n", miThermometer.data[i].gpioTrgOutput ? "High" : "Low");
Serial.printf("Control Parameters: %s\n", miThermometer.data[i].controlParameters ? "Set" : "Not Set");
Serial.printf("Temperature Trigger Event: %s\n", miThermometer.data[i].tempTriggerEvent ? "Triggered" : "Not Triggered");
Serial.printf("Humidity Trigger Event: %s\n", miThermometer.data[i].humiTriggerEvent ? "Triggered" : "Not Triggered");
Serial.println();
}
}
Expand Down
14 changes: 13 additions & 1 deletion src/ATC_MiThermometer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,19 @@ unsigned ATC_MiThermometer::getData(uint32_t duration) {
data[n].batt_voltage = (volt_msb << 8) | volt_lsb;

// Battery state [%]
data[n].batt_level = foundDevices.getDevice(i).getServiceData().c_str()[12];
data[n].batt_level = foundDevices.getDevice(i).getServiceData().c_str()[12];

// Count
data[n].count = foundDevices.getDevice(i).getServiceData().c_str()[13];

//Flags
uint8_t flagsByte = foundDevices.getDevice(i).getServiceData().c_str()[14];
data[n].reedSwitchState = flagsByte & 0x01; // Extract bit 0 (Reed Switch)
data[n].gpioTrgOutput = (flagsByte >> 1) & 0x01; // Extract bit 1 (GPIO_TRG pin output)
data[n].controlParameters = (flagsByte >> 2) & 0x01; // Extract bit 2 (Control parameters)
data[n].tempTriggerEvent = (flagsByte >> 3) & 0x01; // Extract bit 3 (Temperature trigger event)
data[n].humiTriggerEvent = (flagsByte >> 4) & 0x01; // Extract bit 4 (Humidity trigger event)

}
else if (len == 13) {
log_d("ATC1441 format");
Expand Down
7 changes: 7 additions & 0 deletions src/ATC_MiThermometer.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ struct MiThData_S {
uint16_t batt_voltage; //!< battery voltage [mv]
uint8_t batt_level; //!< battery level [%]
int16_t rssi; //!< RSSI [dBm]
uint8_t count; //!< measurement count
bool reedSwitchState;
bool gpioTrgOutput;
bool controlParameters;
bool tempTriggerEvent;
bool humiTriggerEvent;

};

typedef struct MiThData_S MiThData_t; //!< Shortcut for struct MiThData_S
Expand Down

0 comments on commit 6ca27f2

Please sign in to comment.