kike-canaries / canairio_sensorlib

Particle sensor manager for multiple sensors: Honeywell, Plantower, Panasonic, Sensirion, etc. This is sensors layer of CanAirIO project too.
https://canair.io/docs/sensorlib.html
GNU General Public License v3.0
37 stars 12 forks source link

[FEATURE] To improve the two auto detections flows in only one. #11

Closed hpsaturn closed 3 years ago

hpsaturn commented 4 years ago

Summary

The current firmware rev633 has two flows for sensor auto detecting, Honeywell flow and Sensirion flow. It is because the UART re-init or changing the speed and parameters don't works fine in the ESP32.

The current method is:


bool Sensors::pmSensorInit(int pms_type, int pms_rx, int pms_tx) {
    // set UART for autodetection sensors (Honeywell, Plantower, Panasonic)
    if (pms_type <= 1) {
        DEBUG("-->[PMSENSOR] detecting PM sensor..");
        Serial2.begin(9600, SERIAL_8N1, pms_rx, pms_tx);
    }
    // set UART for autodetection Sensirion sensor
    else if (pms_type == Sensirion) {
        DEBUG("-->[PMSENSOR] detecting Sensirion sensor..");
        Serial2.begin(115200);
    }
    // starting auto detection loop 
    _serial = &Serial2;
    int try_sensor_init = 0;
    while (!pmSensorAutoDetect(pms_type) && try_sensor_init++ < 2);

}

The idea is only have one Serial.begin(), and change the params for each detection in run time.

source

hpsaturn commented 3 years ago

I2C implementation is better for this goal, for this reason this feature is a minor and the issue should be close