Skip to content

Commit

Permalink
Merge pull request letscontrolit#4792 from TD-er/cleanup/BMx280_detect
Browse files Browse the repository at this point in the history
[BME280] Show detected sensor model like is done for ADS1x15 and BMP3xx
  • Loading branch information
TD-er committed Sep 21, 2023
2 parents 6e6b1e8 + 6fb589c commit bb22164
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 19 deletions.
32 changes: 16 additions & 16 deletions src/_P028_BME280.ino
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,12 @@ boolean Plugin_028(uint8_t function, struct EventStruct *event, String& string)

case PLUGIN_WEBFORM_LOAD:
{
P028_data_struct *P028_data =
static_cast<P028_data_struct *>(getPluginTaskData(event->TaskIndex));
bool wire_status = false;
const uint8_t chip_id = I2C_read8_reg(P028_I2C_ADDRESS, BMx280_REGISTER_CHIPID, &wire_status);

if (nullptr != P028_data) {
if (P028_data->sensorID != P028_data_struct::Unknown_DEVICE) {
String detectedString = F("Detected: ");
detectedString += P028_data_struct::getDeviceName(P028_data->sensorID);
addUnit(detectedString);
}
if (wire_status) {
addRowLabel(F("Detected Sensor Type"));
addHtml(P028_data_struct::getDeviceName(static_cast<P028_data_struct::BMx_ChipId>(chip_id)));
}

addFormNumericBox(F("Altitude"), F("elev"), P028_ALTITUDE);
Expand All @@ -173,6 +170,9 @@ boolean Plugin_028(uint8_t function, struct EventStruct *event, String& string)
addUnit(F("x 0.1C"));
String offsetNote = F("Offset in units of 0.1 degree Celsius");

P028_data_struct *P028_data =
static_cast<P028_data_struct *>(getPluginTaskData(event->TaskIndex));

if (nullptr != P028_data) {
if ((P028_data_struct::BMx_DetectMode::BMP280 != static_cast<P028_data_struct::BMx_DetectMode>(P028_DETECTION_MODE)) &&
P028_data->hasHumidity()) {
Expand Down Expand Up @@ -210,12 +210,7 @@ boolean Plugin_028(uint8_t function, struct EventStruct *event, String& string)
# endif // ifndef BUILD_NO_DEBUG

// Value in case of Error
# ifndef LIMIT_BUILD_SIZE
# define P028_ERROR_STATE_COUNT 6
# else // ifndef LIMIT_BUILD_SIZE
# define P028_ERROR_STATE_COUNT 5
# endif // ifndef LIMIT_BUILD_SIZE
const __FlashStringHelper *resultsOptions[P028_ERROR_STATE_COUNT] = {
const __FlashStringHelper *resultsOptions[] = {
F("Ignore"),
F("Min -1 (-41&deg;C)"),
F("0"),
Expand All @@ -225,12 +220,17 @@ boolean Plugin_028(uint8_t function, struct EventStruct *event, String& string)
F("-1&deg;K (-274&deg;C)")
# endif // ifndef LIMIT_BUILD_SIZE
};
int resultsOptionValues[P028_ERROR_STATE_COUNT] = {
P028_ERROR_IGNORE, P028_ERROR_MIN_RANGE, P028_ERROR_ZERO, P028_ERROR_MAX_RANGE, P028_ERROR_NAN,
const int resultsOptionValues[] = {
P028_ERROR_IGNORE,
P028_ERROR_MIN_RANGE,
P028_ERROR_ZERO,
P028_ERROR_MAX_RANGE,
P028_ERROR_NAN,
# ifndef LIMIT_BUILD_SIZE
P028_ERROR_MIN_K
# endif // ifndef LIMIT_BUILD_SIZE
};
constexpr int P028_ERROR_STATE_COUNT = NR_ELEMENTS(resultsOptions);
addFormSelector(F("Temperature Error Value"),
F("err"),
P028_ERROR_STATE_COUNT,
Expand Down
8 changes: 6 additions & 2 deletions src/src/PluginStructs/P028_data_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ uint8_t P028_data_struct::get_control_settings() const {
return sensorID == Unknown_DEVICE ? 0u : 0x93; // Oversampling: 8x P, 8x T, normal mode
}

const __FlashStringHelper * P028_data_struct::getDeviceName(BMx_ChipId sensorID) {
switch (sensorID) {
const __FlashStringHelper * P028_data_struct::getDeviceName() const {
return getDeviceName(sensorID);
}

const __FlashStringHelper * P028_data_struct::getDeviceName(BMx_ChipId id) {
switch (id) {
case BMP280_DEVICE_SAMPLE1:
case BMP280_DEVICE_SAMPLE2: return F("sample BMP280");
case BMP280_DEVICE: return F("BMP280");
Expand Down
4 changes: 3 additions & 1 deletion src/src/PluginStructs/P028_data_struct.h
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ struct P028_data_struct : public PluginTaskData_base {

public:

static const __FlashStringHelper* getDeviceName(BMx_ChipId sensorID);
const __FlashStringHelper * getDeviceName() const;

static const __FlashStringHelper* getDeviceName(BMx_ChipId id);

bool hasHumidity() const;

Expand Down

0 comments on commit bb22164

Please sign in to comment.