Skip to content

Commit

Permalink
Merge pull request #858 from WildernessLabs/gas_resistance
Browse files Browse the repository at this point in the history
Use IGasResistanceSensor interface
  • Loading branch information
adrianstevens authored Dec 11, 2023
2 parents 7932c33 + a34e297 commit b2245b0
Showing 1 changed file with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Meadow.Hardware;
using Meadow.Peripherals.Sensors;
using Meadow.Peripherals.Sensors.Atmospheric;
using Meadow.Peripherals.Sensors.Environmental;
using Meadow.Units;
using Meadow.Utilities;
using System;
Expand All @@ -22,16 +23,12 @@ public abstract partial class Bme68x :
RelativeHumidity? Humidity,
Pressure? Pressure,
Resistance? GasResistance)>,
ITemperatureSensor, IHumiditySensor, IBarometricPressureSensor, ISpiPeripheral, II2cPeripheral, IDisposable
ITemperatureSensor, IHumiditySensor, IBarometricPressureSensor, IGasResistanceSensor, ISpiPeripheral, II2cPeripheral, IDisposable
{
private event EventHandler<IChangeResult<Units.Temperature>> _temperatureHandlers;
private event EventHandler<IChangeResult<RelativeHumidity>> _humidityHandlers;
private event EventHandler<IChangeResult<Pressure>> _pressureHandlers;

/// <summary>
/// Raised when the gas resistance value changes
/// </summary>
public event EventHandler<IChangeResult<Resistance>> GasResistanceUpdated = default!;
private event EventHandler<IChangeResult<Units.Temperature>> _temperatureHandlers = default!;
private event EventHandler<IChangeResult<RelativeHumidity>> _humidityHandlers = default!;
private event EventHandler<IChangeResult<Pressure>> _pressureHandlers = default!;
private event EventHandler<IChangeResult<Resistance>> _gasResistanceHandlers = default!;

/// <summary>
/// The temperature oversampling mode
Expand Down Expand Up @@ -292,6 +289,12 @@ event EventHandler<IChangeResult<Pressure>> ISamplingSensor<Pressure>.Updated
remove => _pressureHandlers -= value;
}

event EventHandler<IChangeResult<Resistance>> ISamplingSensor<Resistance>.Updated
{
add => _gasResistanceHandlers += value;
remove => _gasResistanceHandlers -= value;
}

/// <summary>
/// Initialize the sensor
/// </summary>
Expand Down Expand Up @@ -430,7 +433,7 @@ protected override void RaiseEventsAndNotify(IChangeResult<(Units.Temperature? T
}
if (changeResult.New.GasResistance is { } gasResistance)
{
GasResistanceUpdated?.Invoke(this, new ChangeResult<Resistance>(gasResistance, changeResult.Old?.GasResistance));
_gasResistanceHandlers?.Invoke(this, new ChangeResult<Resistance>(gasResistance, changeResult.Old?.GasResistance));
}
base.RaiseEventsAndNotify(changeResult);
}
Expand Down Expand Up @@ -669,5 +672,8 @@ async Task<RelativeHumidity> ISensor<RelativeHumidity>.Read()

async Task<Pressure> ISensor<Pressure>.Read()
=> (await Read()).Pressure!.Value;

async Task<Resistance> ISensor<Resistance>.Read()
=> (await Read()).GasResistance!.Value;
}
}

0 comments on commit b2245b0

Please sign in to comment.