Fix PMS5003 telemetry & ensure reinitialization.
This commit is contained in:
parent
e99e67bd58
commit
ea39ea4046
1 changed files with 19 additions and 13 deletions
|
@ -34,9 +34,14 @@ namespace NucuCar.Sensors.Modules.PMS5003
|
||||||
|
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
if (_pms5003 != null) return;
|
if (_pms5003 != null)
|
||||||
|
{
|
||||||
|
CurrentState = SensorStateEnum.Initialized;
|
||||||
|
return;
|
||||||
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Pms5003.Logger = (Logger<Pms5003>) Logger;
|
||||||
_pms5003 = new Pms5003(23, 24);
|
_pms5003 = new Pms5003(23, 24);
|
||||||
_pms5003.Reset();
|
_pms5003.Reset();
|
||||||
CurrentState = SensorStateEnum.Initialized;
|
CurrentState = SensorStateEnum.Initialized;
|
||||||
|
@ -101,21 +106,22 @@ namespace NucuCar.Sensors.Modules.PMS5003
|
||||||
Dictionary<string, object> returnValue = null;
|
Dictionary<string, object> returnValue = null;
|
||||||
if (_pms5003Data != null && TelemetryEnabled)
|
if (_pms5003Data != null && TelemetryEnabled)
|
||||||
{
|
{
|
||||||
|
// The telemetry handled by FirebaseRestTranslator wants the values to be int or double.
|
||||||
returnValue = new Dictionary<string, object>
|
returnValue = new Dictionary<string, object>
|
||||||
{
|
{
|
||||||
["sensor_state"] = GetState(),
|
["sensor_state"] = GetState(),
|
||||||
["Pm1Atmospheric"] = _pms5003Data.Pm1Atmospheric,
|
["Pm1Atmospheric"] = (int) _pms5003Data.Pm1Atmospheric,
|
||||||
["Pm1Standard"] = _pms5003Data.Pm1Standard,
|
["Pm1Standard"] = (int) _pms5003Data.Pm1Standard,
|
||||||
["Pm10Atmospheric"] = _pms5003Data.Pm10Atmospheric,
|
["Pm10Atmospheric"] = (int) _pms5003Data.Pm10Atmospheric,
|
||||||
["Pm10Standard"] = _pms5003Data.Pm10Standard,
|
["Pm10Standard"] = (int) _pms5003Data.Pm10Standard,
|
||||||
["Pm2Dot5Atmospheric"] = _pms5003Data.Pm2Dot5Atmospheric,
|
["Pm2Dot5Atmospheric"] = (int) _pms5003Data.Pm2Dot5Atmospheric,
|
||||||
["Pm2Dot5Standard"] = _pms5003Data.Pm2Dot5Standard,
|
["Pm2Dot5Standard"] = (int) _pms5003Data.Pm2Dot5Standard,
|
||||||
["ParticlesDiameterBeyond0Dot3"] = _pms5003Data.ParticlesDiameterBeyond0Dot3,
|
["ParticlesDiameterBeyond0Dot3"] = (int) _pms5003Data.ParticlesDiameterBeyond0Dot3,
|
||||||
["ParticlesDiameterBeyond0Dot5"] = _pms5003Data.ParticlesDiameterBeyond0Dot5,
|
["ParticlesDiameterBeyond0Dot5"] = (int) _pms5003Data.ParticlesDiameterBeyond0Dot5,
|
||||||
["ParticlesDiameterBeyond1Dot0"] = _pms5003Data.ParticlesDiameterBeyond1Dot0,
|
["ParticlesDiameterBeyond1Dot0"] = (int) _pms5003Data.ParticlesDiameterBeyond1Dot0,
|
||||||
["ParticlesDiameterBeyond2Dot5"] = _pms5003Data.ParticlesDiameterBeyond2Dot5,
|
["ParticlesDiameterBeyond2Dot5"] = (int) _pms5003Data.ParticlesDiameterBeyond2Dot5,
|
||||||
["ParticlesDiameterBeyond5Dot0"] = _pms5003Data.ParticlesDiameterBeyond5Dot0,
|
["ParticlesDiameterBeyond5Dot0"] = (int) _pms5003Data.ParticlesDiameterBeyond5Dot0,
|
||||||
["ParticlesDiameterBeyond10Dot0"] = _pms5003Data.ParticlesDiameterBeyond10Dot0,
|
["ParticlesDiameterBeyond10Dot0"] = (int) _pms5003Data.ParticlesDiameterBeyond10Dot0,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue