From ea39ea40460edacf954d31e5e83240c39ff6c6e1 Mon Sep 17 00:00:00 2001 From: Denis Nutiu Date: Fri, 30 Apr 2021 13:07:31 +0300 Subject: [PATCH] Fix PMS5003 telemetry & ensure reinitialization. --- .../Modules/PMS5003/Pms5003Sensor.cs | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs b/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs index facd781..6837158 100644 --- a/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs +++ b/NucuCar.Sensors/Modules/PMS5003/Pms5003Sensor.cs @@ -34,9 +34,14 @@ namespace NucuCar.Sensors.Modules.PMS5003 public override void Initialize() { - if (_pms5003 != null) return; + if (_pms5003 != null) + { + CurrentState = SensorStateEnum.Initialized; + return; + } try { + Pms5003.Logger = (Logger) Logger; _pms5003 = new Pms5003(23, 24); _pms5003.Reset(); CurrentState = SensorStateEnum.Initialized; @@ -101,21 +106,22 @@ namespace NucuCar.Sensors.Modules.PMS5003 Dictionary returnValue = null; if (_pms5003Data != null && TelemetryEnabled) { + // The telemetry handled by FirebaseRestTranslator wants the values to be int or double. returnValue = new Dictionary { ["sensor_state"] = GetState(), - ["Pm1Atmospheric"] = _pms5003Data.Pm1Atmospheric, - ["Pm1Standard"] = _pms5003Data.Pm1Standard, - ["Pm10Atmospheric"] = _pms5003Data.Pm10Atmospheric, - ["Pm10Standard"] = _pms5003Data.Pm10Standard, - ["Pm2Dot5Atmospheric"] = _pms5003Data.Pm2Dot5Atmospheric, - ["Pm2Dot5Standard"] = _pms5003Data.Pm2Dot5Standard, - ["ParticlesDiameterBeyond0Dot3"] = _pms5003Data.ParticlesDiameterBeyond0Dot3, - ["ParticlesDiameterBeyond0Dot5"] = _pms5003Data.ParticlesDiameterBeyond0Dot5, - ["ParticlesDiameterBeyond1Dot0"] = _pms5003Data.ParticlesDiameterBeyond1Dot0, - ["ParticlesDiameterBeyond2Dot5"] = _pms5003Data.ParticlesDiameterBeyond2Dot5, - ["ParticlesDiameterBeyond5Dot0"] = _pms5003Data.ParticlesDiameterBeyond5Dot0, - ["ParticlesDiameterBeyond10Dot0"] = _pms5003Data.ParticlesDiameterBeyond10Dot0, + ["Pm1Atmospheric"] = (int) _pms5003Data.Pm1Atmospheric, + ["Pm1Standard"] = (int) _pms5003Data.Pm1Standard, + ["Pm10Atmospheric"] = (int) _pms5003Data.Pm10Atmospheric, + ["Pm10Standard"] = (int) _pms5003Data.Pm10Standard, + ["Pm2Dot5Atmospheric"] = (int) _pms5003Data.Pm2Dot5Atmospheric, + ["Pm2Dot5Standard"] = (int) _pms5003Data.Pm2Dot5Standard, + ["ParticlesDiameterBeyond0Dot3"] = (int) _pms5003Data.ParticlesDiameterBeyond0Dot3, + ["ParticlesDiameterBeyond0Dot5"] = (int) _pms5003Data.ParticlesDiameterBeyond0Dot5, + ["ParticlesDiameterBeyond1Dot0"] = (int) _pms5003Data.ParticlesDiameterBeyond1Dot0, + ["ParticlesDiameterBeyond2Dot5"] = (int) _pms5003Data.ParticlesDiameterBeyond2Dot5, + ["ParticlesDiameterBeyond5Dot0"] = (int) _pms5003Data.ParticlesDiameterBeyond5Dot0, + ["ParticlesDiameterBeyond10Dot0"] = (int) _pms5003Data.ParticlesDiameterBeyond10Dot0, }; }