Fixes on 0x69 address detection

* Change SEN5X detection method, using class itself
* MPU6050 register check
* BMX160 default removed
This commit is contained in:
oscgonfer
2026-06-14 13:45:15 +02:00
parent bbcc35e209
commit 7c17e489c2
3 changed files with 70 additions and 51 deletions
+43 -51
View File
@@ -137,45 +137,52 @@ bool ScanI2CTwoWire::i2cCommandResponseLength(ScanI2C::DeviceAddress addr, uint1
}
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_AIR_QUALITY_SENSOR
#include "../modules/Telemetry/Sensor/SEN5XSensor.h"
bool probeSEN5X(TwoWire *i2cBus, uint8_t address, ScanI2C::I2CPort port)
{
SEN5XSensor sen5xsensor = SEN5XSensor();
return sen5xsensor.probe(i2cBus, address, port);
}
// FIXME Move to a separate file for detection of sensors that require more complex interactions?
// For SEN5X detection
// Note, this code needs to be called before setting the I2C bus speed
// for the screen at high speed. The speed needs to be at 100kHz, otherwise
// detection will not work
String readSEN5xProductName(TwoWire *i2cBus, uint8_t address)
{
uint8_t cmd[] = {0xD0, 0x14};
uint8_t response[48] = {0};
// String readSEN5xProductName(TwoWire *i2cBus, uint8_t address)
// {
// uint8_t cmd[] = {0xD0, 0x14};
// uint8_t response[48] = {0};
i2cBus->beginTransmission(address);
i2cBus->write(cmd, 2);
if (i2cBus->endTransmission() != 0)
return "";
// i2cBus->beginTransmission(address);
// i2cBus->write(cmd, 2);
// if (i2cBus->endTransmission() != 0)
// return "";
delay(20);
if (i2cBus->requestFrom(address, (uint8_t)48) != 48)
return "";
// delay(20);
// if (i2cBus->requestFrom(address, (uint8_t)48) != 48)
// return "";
for (int i = 0; i < 48 && i2cBus->available(); ++i) {
response[i] = i2cBus->read();
}
// for (int i = 0; i < 48 && i2cBus->available(); ++i) {
// response[i] = i2cBus->read();
// }
char productName[33] = {0};
int j = 0;
for (int i = 0; i < 48 && j < 32; i += 3) {
if (response[i] >= 32 && response[i] <= 126)
productName[j++] = response[i];
else
break;
// char productName[33] = {0};
// int j = 0;
// for (int i = 0; i < 48 && j < 32; i += 3) {
// if (response[i] >= 32 && response[i] <= 126)
// productName[j++] = response[i];
// else
// break;
if (response[i + 1] >= 32 && response[i + 1] <= 126)
productName[j++] = response[i + 1];
else
break;
}
// if (response[i + 1] >= 32 && response[i + 1] <= 126)
// productName[j++] = response[i + 1];
// else
// break;
// }
return String(productName);
}
// return String(productName);
// }
#endif
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
@@ -789,33 +796,18 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize)
type = ICM42607P;
logFoundDevice("ICM-42607-P", (uint8_t)addr.address);
break;
}
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_AIR_QUALITY_SENSOR
String prod = "";
prod = readSEN5xProductName(i2cBus, addr.address);
if (prod.startsWith("SEN55")) {
type = SEN5X;
logFoundDevice("Sensirion SEN55", addr.address);
break;
} else if (prod.startsWith("SEN54")) {
type = SEN5X;
logFoundDevice("Sensirion SEN54", addr.address);
break;
} else if (prod.startsWith("SEN50")) {
type = SEN5X;
logFoundDevice("Sensirion SEN50", addr.address);
break;
}
#endif
if (addr.address == BMX160_ADDR) {
type = BMX160;
logFoundDevice("BMX160", (uint8_t)addr.address);
break;
} else {
} else if (registerValue == 0x68) { // WHO_AM_I from datasheet
type = MPU6050;
logFoundDevice("MPU6050", (uint8_t)addr.address);
break;
}
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_AIR_QUALITY_SENSOR
if (probeSEN5X(i2cBus, addr.address, port)) {
type = SEN5X;
logFoundDevice("SEN5X", addr.address);
break;
}
#endif
}
break;