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

Check version mcp to switch between v3 and v4 hardware #65

Merged
merged 1 commit into from
Feb 4, 2024
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
33 changes: 30 additions & 3 deletions Source/Meadow.Clima/Clima.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Meadow.Hardware;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Hardware;
using Meadow.Logging;
using System;

Expand Down Expand Up @@ -44,8 +45,34 @@ public static IClimaHardware Create()
}
else if (device is IF7CoreComputeMeadowDevice { } ccm)
{
logger?.Info("Instantiating Clima v3 specific hardware");
hardware = new ClimaHardwareV3(ccm, i2cBus);
Mcp23008? mcpVersion = null;
byte version = 0;

try
{
logger?.Info("Instantiating version MCP23008");

var resetPort = ccm.Pins.D02.CreateDigitalOutputPort();

mcpVersion = new Mcp23008(i2cBus, address: 0x27, resetPort: resetPort);

version = mcpVersion.ReadFromPorts();
}
catch
{
logger?.Info("Failed to instantiate version MCP23008");
}

if (version > 4)
{
logger?.Info("Instantiating Clima v4 specific hardware");
hardware = new ClimaHardwareV4(ccm, i2cBus, mcpVersion!);
}
else
{
logger?.Info("Instantiating Clima v3 specific hardware");
hardware = new ClimaHardwareV3(ccm, i2cBus, mcpVersion!);
}
}
else
{
Expand Down
24 changes: 9 additions & 15 deletions Source/Meadow.Clima/ClimaHardwareV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ namespace Meadow.Devices
/// </summary>
public class ClimaHardwareV3 : ClimaHardwareBase
{
private readonly IF7CoreComputeMeadowDevice _device;
/// <summary>
/// The Meadow CCM device
/// </summary>
protected readonly IF7CoreComputeMeadowDevice _device;

private Scd40? _environmentalSensor;
private ICO2ConcentrationSensor? _co2ConcentrationSensor;
Expand All @@ -35,7 +38,7 @@ public class ClimaHardwareV3 : ClimaHardwareBase
/// <summary>
/// The MCP23008 IO expander that contains the Clima hardware version
/// </summary>
Mcp23008? McpVersion { get; set; }
public Mcp23008 McpVersion { get; protected set; }

/// <inheritdoc/>
public override string RevisionString => "v3.x";
Expand All @@ -59,8 +62,11 @@ public class ClimaHardwareV3 : ClimaHardwareBase
/// </summary>
/// <param name="device">The meadow device</param>
/// <param name="i2cBus">The I2C bus</param>
public ClimaHardwareV3(IF7CoreComputeMeadowDevice device, II2cBus i2cBus)
/// <param name="mcpVersion">The Mcp23008 used to read version information</param>
public ClimaHardwareV3(IF7CoreComputeMeadowDevice device, II2cBus i2cBus, Mcp23008 mcpVersion)
{
McpVersion = mcpVersion;

_device = device;

I2cBus = i2cBus;
Expand All @@ -69,18 +75,6 @@ public ClimaHardwareV3(IF7CoreComputeMeadowDevice device, II2cBus i2cBus)
// Must initialise any PWM based I/O first
GetRgbPwmLed();

try
{
Logger?.Trace("Instantiating Mcp Version");
McpVersion = new Mcp23008(I2cBus, address: 0x27, resetPort: device.Pins.D02.CreateDigitalOutputPort());
Logger?.Info("Mcp Version up");
}
catch (Exception e)
{
Logger?.Trace($"ERR creating the MCP that has version information: {e.Message}");
}


try
{
Logger?.Trace("Instantiating Solar Voltage Input");
Expand Down
11 changes: 5 additions & 6 deletions Source/Meadow.Clima/ClimaHardwareV4.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Meadow.Hardware;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Hardware;

namespace Meadow.Devices
{
Expand All @@ -7,8 +8,6 @@ namespace Meadow.Devices
/// </summary>
public class ClimaHardwareV4 : ClimaHardwareV3
{
private readonly IF7CoreComputeMeadowDevice _device;

/// <inheritdoc/>
public override string RevisionString => "v4.x";

Expand All @@ -17,10 +16,10 @@ public class ClimaHardwareV4 : ClimaHardwareV3
/// </summary>
/// <param name="device">The meadow device</param>
/// <param name="i2cBus">The I2C bus</param>
public ClimaHardwareV4(IF7CoreComputeMeadowDevice device, II2cBus i2cBus)
: base(device, i2cBus)
/// <param name="mcpVersion">The Mcp23008 used to read version information</param>
public ClimaHardwareV4(IF7CoreComputeMeadowDevice device, II2cBus i2cBus, Mcp23008 mcpVersion)
: base(device, i2cBus, mcpVersion)
{
_device = device;
}

internal override I2cConnector? CreateQwiicConnector()
Expand Down
Loading