From c9abb81f419028277b3bd428f3204320b17ca311 Mon Sep 17 00:00:00 2001 From: "Justin E. Mann" Date: Mon, 2 Dec 2024 11:05:01 -0700 Subject: [PATCH] inprove check for RAK12035VBSOIL Sensor by checking device registry for expected values.. --- .vscode/settings.json | 11 +++++++++++ src/detect/ScanI2CTwoWire.cpp | 34 +++++++++++----------------------- 2 files changed, 22 insertions(+), 23 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index bf9b82111..0c5564299 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -7,5 +7,16 @@ "cmake.configureOnOpen": false, "[cpp]": { "editor.defaultFormatter": "trunk.io" + }, + "files.associations": { + "array": "cpp", + "chrono": "cpp", + "functional": "cpp", + "istream": "cpp", + "ostream": "cpp", + "ratio": "cpp", + "tuple": "cpp", + "type_traits": "cpp", + "utility": "cpp" } } diff --git a/src/detect/ScanI2CTwoWire.cpp b/src/detect/ScanI2CTwoWire.cpp index 75bc14c57..23e19971e 100644 --- a/src/detect/ScanI2CTwoWire.cpp +++ b/src/detect/ScanI2CTwoWire.cpp @@ -291,33 +291,21 @@ void ScanI2CTwoWire::scanPort(I2CPort port, uint8_t *address, uint8_t asize) case RAK12035VB_ADDR: // (0x20) can be RAK12023VB Soil Sensor or TCA9535 I2C expander - // check if it is a RAK12035, if not can assume it is a TCA9535 I2C expander - // registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x20), 1); // get ID - // if (registerValue == 0xC0) { - // type = RAK12035VB; - // LOG_INFO("RAK12035VB Soil Sensor found"); - // } else { - //#ifdef RAK4631 - // type = NCP5623; - // logFoundDevice("NCP5623", (uint8_t)addr.address); - //#endif - // type = TCA9535; - // LOG_INFO("TCA9535 I2C expander found\n"); - // } - // break; - - // ^^^^^^^^^^^ not working... so we will just assume it is a RAK12035VB Soil Sensor so I can keep testing. - #ifdef RAK4631 + // Check if it is a RAK12035, if not can assume it is a TCA9535 I2C expander + // additional info about registry values can be found here [https://github.com/RAKWireless/RAK12035_SoilMoisture/blob/main/RAK12035_SoilMoisture.h] + registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x02), 1); // get the default address for the device (stored in registry here [0x02]).. should come back as 0x20 + LOG_INFO("Checking for RAK12035VB Soil Sensor with registry address 0x02..."); + if (registerValue == 0x20) { + LOG_INFO("Found registry value 0x%x", registerValue); type = RAK12035VB; LOG_INFO("RAK12035VB Soil Sensor found"); - #endif + } else { + LOG_INFO("Found registry value 0x%x", registerValue); + type = TCA9535; + LOG_INFO("TCA9535 I2C expander found\n"); + } break; - - - - - case MCP9808_ADDR: // We need to check for STK8BAXX first, since register 0x07 is new data flag for the z-axis and can produce some // weird result. and register 0x00 doesn't seems to be colliding with MCP9808 and LIS3DH chips.