diff --git a/examples/advanced_multivariable/src/main.cpp b/examples/advanced_multivariable/src/main.cpp index d3b37046..ceaa8241 100644 --- a/examples/advanced_multivariable/src/main.cpp +++ b/examples/advanced_multivariable/src/main.cpp @@ -1,7 +1,7 @@ /** * @file main.cpp * @author Antonio Vanegas @hpsaturn - * @date June 2018 - 2022 + * @date June 2018 - 2023 * @brief CanAirIO Sensorslib tests * @license GPL3 * @@ -67,7 +67,7 @@ void powerEnableSensors() { void setup() { Serial.begin(115200); - delay(200); + delay(500); // Only for debugging // powerEnableSensors(); // Only for special setup hardware with enable delay(100); Serial.println("\n== Sensor test setup ==\n"); @@ -75,10 +75,11 @@ void setup() { sensors.setSampleTime(10); // config sensors sample time interval sensors.setOnDataCallBack(&onSensorDataOk); // all data read callback - sensors.setDebugMode(true); // [optional] debug mode - sensors.detectI2COnly(true); // force to only i2c sensors + sensors.setDebugMode(false); // [optional] debug mode + sensors.detectI2COnly(false); // not force to only i2c sensors sensors.setTemperatureUnit(TEMPUNIT::KELVIN); // comment for Celsius or set Fahrenheit - sensors.init(); // Auto detection to UART and i2c sensors + // sensors.init(SENSORS::Auto, 13, 12); // Auto detection (Custom UART sensor pins example) + sensors.init(); // Auto detection (UART and i2c sensors) delay(1000); } diff --git a/src/Sensors.cpp b/src/Sensors.cpp index d1e4293b..97fbef30 100644 --- a/src/Sensors.cpp +++ b/src/Sensors.cpp @@ -680,11 +680,14 @@ void Sensors::printUnitsRegistered(bool debug) { */ void Sensors::printSensorsRegistered(bool debug) { if (!debug) return; - Serial.printf("-->[SLIB] sensors count \t: %i (", sensors_registered_count); int i = 0; + Serial.printf("-->[SLIB] sensors count \t: %i (", sensors_registered_count); + if (sensors_registered_count > 0 && sensors_registered[0] == SENSORS::Auto) { + Serial.printf("%s,", sensors_device_names[sensors_registered[0]]); + i = 1; + } while (sensors_registered[i++] != 0) { - Serial.print(sensors_device_names[sensors_registered[i-1]]); - Serial.print(","); + Serial.printf("%s,", sensors_device_names[sensors_registered[i-1]]); } Serial.println(")"); } @@ -1210,7 +1213,7 @@ void Sensors::sps30Errorloop(char *mess, uint8_t r) { **/ bool Sensors::sensorSerialInit(u_int pms_type, int pms_rx, int pms_tx) { // set UART for autodetection sensors (Honeywell, Plantower) - if (pms_type == Auto) { + if (pms_type == SENSORS::Auto) { DEBUG("-->[SLIB] UART detecting type\t: Auto"); if (!serialInit(pms_type, 9600, pms_rx, pms_tx)) return false; } @@ -1819,7 +1822,9 @@ void Sensors::sensorAnnounce(SENSORS sensor) { * dynamic calls of the sensors and its units on the GUI or implementation. */ void Sensors::sensorRegister(SENSORS sensor) { - if (isSensorRegistered(sensor)) return; + if (isSensorRegistered(sensor) && sensor != SENSORS::Auto) { + return; + } Serial.printf("-->[SLIB] sensor registered\t: %s \t:D\r\n", getSensorName(sensor).c_str()); sensors_registered[sensors_registered_count++] = sensor; }