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

Release 1.9.0 #50

Merged
merged 1 commit into from
Feb 27, 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
7 changes: 4 additions & 3 deletions Source/Juego/DisplayConnector.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using System;
using static Meadow.Hardware.DisplayConnector;
using Meadow.Hardware;
using System;
using static Meadow.Devices.DisplayConnector;

namespace Meadow.Hardware;
namespace Meadow.Devices;

/// <summary>
/// Represents the display connector on Juego
Expand Down
149 changes: 74 additions & 75 deletions Source/Juego/IJuegoHardware.cs
Original file line number Diff line number Diff line change
@@ -1,93 +1,92 @@
using Meadow.Foundation.Audio;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Leds;
using Meadow.Foundation.Sensors.Accelerometers;
using Meadow.Foundation.Sensors.Buttons;
using Meadow.Hardware;
using Meadow.Peripherals.Displays;

namespace WildernessLabs.Hardware.Juego
namespace Meadow.Devices;

/// <summary>
/// Represents the hardware interface for the Juego device
/// </summary>
public interface IJuegoHardware
{
/// <summary>
/// Represents the hardware interface for the Juego device
/// Gets the graphics display interface
/// </summary>
public interface IJuegoHardware
{
/// <summary>
/// Gets the graphics display interface
/// </summary>
public IGraphicsDisplay? Display { get; }
public IPixelDisplay? Display { get; }

/// <summary>
/// Gets the right/up button
/// </summary>
public PushButton? Right_UpButton { get; }
/// <summary>
/// Gets the right/down button
/// </summary>
public PushButton? Right_DownButton { get; }
/// <summary>
/// Gets the right/left button
/// </summary>
public PushButton? Right_LeftButton { get; }
/// <summary>
/// Gets the right/right button
/// </summary>
public PushButton? Right_RightButton { get; }
/// <summary>
/// Gets the right/up button
/// </summary>
public PushButton? Right_UpButton { get; }
/// <summary>
/// Gets the right/down button
/// </summary>
public PushButton? Right_DownButton { get; }
/// <summary>
/// Gets the right/left button
/// </summary>
public PushButton? Right_LeftButton { get; }
/// <summary>
/// Gets the right/right button
/// </summary>
public PushButton? Right_RightButton { get; }

/// <summary>
/// Gets the left/up button
/// </summary>
public PushButton? Left_UpButton { get; }
/// <summary>
/// Gets the left/down button
/// </summary>
public PushButton? Left_DownButton { get; }
/// <summary>
/// Gets the left/left button
/// </summary>
public PushButton? Left_LeftButton { get; }
/// <summary>
/// Gets the left/right button
/// </summary>
public PushButton? Left_RightButton { get; }
/// <summary>
/// Gets the left/up button
/// </summary>
public PushButton? Left_UpButton { get; }
/// <summary>
/// Gets the left/down button
/// </summary>
public PushButton? Left_DownButton { get; }
/// <summary>
/// Gets the left/left button
/// </summary>
public PushButton? Left_LeftButton { get; }
/// <summary>
/// Gets the left/right button
/// </summary>
public PushButton? Left_RightButton { get; }

/// <summary>
/// Gets the start button
/// </summary>
public PushButton? StartButton { get; }
/// <summary>
/// Gets the select button
/// </summary>
public PushButton? SelectButton { get; }
/// <summary>
/// Gets the start button
/// </summary>
public PushButton? StartButton { get; }
/// <summary>
/// Gets the select button
/// </summary>
public PushButton? SelectButton { get; }

// Speakers
/// <summary>
/// Gets the left speaker
/// </summary>
public PiezoSpeaker? LeftSpeaker { get; }
/// <summary>
/// Gets the right speaker
/// </summary>
public PiezoSpeaker? RightSpeaker { get; }
// Speakers
/// <summary>
/// Gets the left speaker
/// </summary>
public PiezoSpeaker? LeftSpeaker { get; }
/// <summary>
/// Gets the right speaker
/// </summary>
public PiezoSpeaker? RightSpeaker { get; }

/// <summary>
/// Gets the PWM LED
/// </summary>
public PwmLed? BlinkyLed { get; }
/// <summary>
/// Gets the PWM LED
/// </summary>
public PwmLed? BlinkyLed { get; }

/// <summary>
/// Gets the motion sensor
/// </summary>
public Bmi270? MotionSensor { get; }
/// <summary>
/// Gets the motion sensor
/// </summary>
public Bmi270? MotionSensor { get; }

/// <summary>
/// Gets the display header connector
/// </summary>
public DisplayConnector DisplayHeader { get; }
/// <summary>
/// Gets the display header connector
/// </summary>
public DisplayConnector DisplayHeader { get; }

/// <summary>
/// Gets the Stemma QT I2C Qwiic connector
/// </summary>
public I2cConnector? Qwiic { get; }
}
/// <summary>
/// Gets the Stemma QT I2C Qwiic connector
/// </summary>
public I2cConnector? Qwiic { get; }
}
174 changes: 86 additions & 88 deletions Source/Juego/Juego.cs
Original file line number Diff line number Diff line change
@@ -1,119 +1,117 @@
using Meadow;
using Meadow.Foundation.Audio;
using Meadow.Foundation.Audio;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Hardware;
using Meadow.Logging;
using System;

namespace WildernessLabs.Hardware.Juego
namespace Meadow.Devices;

/// <summary>
/// Juego hardware factory class for Juego v1, v2, and v3 hardware
/// </summary>
public class Juego
{
private Juego() { }

/// <summary>
/// Juego hardware factory class for Juego v1, v2, and v3 hardware
/// Create an instance of the Juego class for the current hardware
/// </summary>
public class Juego
public static IJuegoHardware? Create()
{
private Juego() { }
IJuegoHardware? hardware = null;
Logger? logger = Resolver.Log;

logger?.Debug("Initializing Juego...");

/// <summary>
/// Create an instance of the Juego class for the current hardware
/// </summary>
public static IJuegoHardware? Create()
var device = Resolver.Device;

// make sure not getting instantiated before the App Initialize method
if (Resolver.Device == null)
{
IJuegoHardware? hardware = null;
Logger? logger = Resolver.Log;
var msg = "Juego instance must be created no earlier than App.Initialize()";
logger?.Error(msg);
throw new Exception(msg);
}

logger?.Debug("Initializing Juego...");
if (device is IF7FeatherMeadowDevice { } feather)
{
logger?.Info("Instantiating Juego v1 hardware");
hardware = new JuegoHardwareV1(feather);
}
else if (device is IF7CoreComputeMeadowDevice { } ccm)
{
II2cBus i2cBus;
Mcp23008? mcpVersion = null;
byte version = 0;

var device = Resolver.Device;
PiezoSpeaker? leftSpeaker = null;
PiezoSpeaker? rightSpeaker = null;

// make sure not getting instantiated before the App Initialize method
if (Resolver.Device == null)
try
{
logger?.Info("Instantiating speakers");
// hack for PWM init bug .... move back into the hardware classes once it's fixed
leftSpeaker = new PiezoSpeaker(ccm.Pins.PB8);
rightSpeaker = new PiezoSpeaker(ccm.Pins.PB9);
}
catch
{
var msg = "Juego instance must be created no earlier than App.Initialize()";
logger?.Error(msg);
throw new Exception(msg);
logger?.Info("Failed to instantiate speakers");
}

if (device is IF7FeatherMeadowDevice { } feather)
try
{
logger?.Info("Instantiating Juego v1 hardware");
hardware = new JuegoHardwareV1(feather);
logger?.Info("Intantiating I2C Bus");
i2cBus = ccm.CreateI2cBus(busSpeed: I2cBusSpeed.FastPlus);
}
else if (device is IF7CoreComputeMeadowDevice { } ccm)
catch
{
II2cBus i2cBus;
Mcp23008? mcpVersion = null;
byte version = 0;

PiezoSpeaker? leftSpeaker = null;
PiezoSpeaker? rightSpeaker = null;

try
{
logger?.Info("Instantiating speakers");
// hack for PWM init bug .... move back into the hardware classes once it's fixed
leftSpeaker = new PiezoSpeaker(ccm.Pins.PB8);
rightSpeaker = new PiezoSpeaker(ccm.Pins.PB9);
}
catch
{
logger?.Info("Failed to instantiate speakers");
}

try
{
logger?.Info("Intantiating I2C Bus");
i2cBus = ccm.CreateI2cBus(busSpeed: I2cBusSpeed.FastPlus);
}
catch
{
logger?.Info("Failed to instantiate I2C Bus");
logger?.Info("Cannot instantiate Juego hardware");
return null;
}
logger?.Info("Failed to instantiate I2C Bus");
logger?.Info("Cannot instantiate Juego hardware");
return null;
}

try
{
logger?.Info("Intantiating version MCP23008");
mcpVersion = new Mcp23008(i2cBus, address: 0x23);
version = mcpVersion.ReadFromPorts();
}
catch
{
logger?.Info("Failed to instantiate version MCP23008");
}
try
{
logger?.Info("Instantiating version MCP23008");
mcpVersion = new Mcp23008(i2cBus, address: 0x23);
version = mcpVersion.ReadFromPorts();
}
catch
{
logger?.Info("Failed to instantiate version MCP23008");
}

try
try
{
if (mcpVersion != null &&
version >= JuegoHardwareV3.MinimumHardareVersion)
{
if (mcpVersion != null &&
version >= JuegoHardwareV3.MinimumHardareVersion)
logger?.Info("Instantiating Juego v3 hardware");
hardware = new JuegoHardwareV3(ccm, i2cBus)
{
logger?.Info("Instantiating Juego v3 hardware");
hardware = new JuegoHardwareV3(ccm, i2cBus)
{
Mcp_VersionInfo = mcpVersion,
LeftSpeaker = leftSpeaker,
RightSpeaker = rightSpeaker,
};
}
else
{
logger?.Info("Instantiating Juego v2 hardware");
hardware = new JuegoHardwareV2(ccm, i2cBus)
{
Mcp_VersionInfo = mcpVersion!,
LeftSpeaker = leftSpeaker,
RightSpeaker = rightSpeaker,
};
}
Mcp_VersionInfo = mcpVersion,
LeftSpeaker = leftSpeaker,
RightSpeaker = rightSpeaker,
};
}
catch
else
{
logger?.Info("Failed to instantiate Juego hardware");
logger?.Info("Instantiating Juego v2 hardware");
hardware = new JuegoHardwareV2(ccm, i2cBus)
{
Mcp_VersionInfo = mcpVersion!,
LeftSpeaker = leftSpeaker,
RightSpeaker = rightSpeaker,
};
}
}

return hardware;
catch
{
logger?.Info("Failed to instantiate Juego hardware");
}
}

return hardware;
}
}
Loading
Loading