Add HYT I2c bus2 support

This commit is contained in:
Theo Arends 2023-10-20 13:35:24 +02:00
parent 2cabbc68c3
commit f05470bf81
2 changed files with 19 additions and 12 deletions

View File

@ -105,7 +105,7 @@ Index | Define | Driver | Device | Address(es) | Bus2 | Descrip
65 | USE_ADE7880 | xnrg_23 | ADE7880 | 0x38 | | Energy monitor
66 | USE_PCF85363 | xsns_99 | PCF85363 | 0x51 | | Real time clock
67 | USE_DS3502 | xdrv_61 | DS3502 | 0x28 - 0x2B | | Digital potentiometer
68 | USE_HYT | xsns_97 | HYTxxx | 0x28 | | Temperature and Humidity sensor
68 | USE_HYT | xsns_97 | HYTxxx | 0x28 | Yes | Temperature and Humidity sensor
69 | USE_SGP40 | xsns_98 | SGP40 | 0x59 | | Gas (TVOC) and air quality
70 | USE_LUXV30B | xsns_99 | LUXV30B | 0x4A | | DFRobot SEN0390 V30B lux sensor
71 | USE_QMC5883L | xsns_33 | QMC5883L | 0x0D | | Magnetic Field Sensor

View File

@ -36,6 +36,7 @@
struct HYT {
float humidity = NAN;
float temperature = NAN;
uint8_t bus;
uint8_t valid = 0;
uint8_t count = 0;
char name[6] = "HYT";
@ -44,14 +45,16 @@ struct HYT {
bool HYT_Read(void) {
if (HYT.valid) { HYT.valid--; }
Wire.beginTransmission(HYT_ADDR);
Wire.requestFrom(HYT_ADDR, 4);
if (Wire.available() == 4) {
uint8_t data1 = Wire.read();
uint8_t data2 = Wire.read();
uint8_t data3 = Wire.read();
uint8_t data4 = Wire.read();
Wire.endTransmission();
TwoWire& myWire = I2cGetWire(HYT.bus);
if (&myWire == nullptr) { return false; } // No valid I2c bus
myWire.beginTransmission(HYT_ADDR);
myWire.requestFrom(HYT_ADDR, 4);
if (myWire.available() == 4) {
uint8_t data1 = myWire.read();
uint8_t data2 = myWire.read();
uint8_t data3 = myWire.read();
uint8_t data4 = myWire.read();
myWire.endTransmission();
// Convert the data to 14-bits
float humidity = ((((data1 & 0x3F) * 256) + data2) * 100.0) / 16383.0;
@ -72,9 +75,13 @@ bool HYT_Read(void) {
/********************************************************************************************/
void HYT_Detect(void) {
if (I2cSetDevice(HYT_ADDR)) {
I2cSetActiveFound(HYT_ADDR, "HYT");
HYT.count = 1;
for (HYT.bus = 0; HYT.bus < 2; HYT.bus++) {
if (!I2cSetDevice(HYT_ADDR, HYT.bus)) { continue; }
if (HYT_Read()) {
I2cSetActiveFound(HYT_ADDR, "HYT", HYT.bus);
HYT.count = 1;
break;
}
}
}