Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 188 generic uart reg #190

Merged
merged 2 commits into from
Nov 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions examples/advanced_multivariable/src/main.cpp
Original file line number Diff line number Diff line change
@@ -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
*
Expand Down Expand Up @@ -67,18 +67,19 @@ 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");
Serial.println("-->[SETUP] Detecting sensors..");

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);
}

Expand Down
15 changes: 10 additions & 5 deletions src/Sensors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(")");
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down