Skip to content

Commit

Permalink
Merge pull request #41 from WildernessLabs/validation
Browse files Browse the repository at this point in the history
Improved startup validation
  • Loading branch information
ctacke authored Dec 23, 2023
2 parents 917f940 + 87482fc commit a9c690d
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 60 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/develop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: Develop Build
on:
workflow_dispatch:
pull_request:
push:
branches: [ develop ]

jobs:
Expand Down Expand Up @@ -65,7 +64,6 @@ jobs:
uses: actions/checkout@v3
with:
path: Juego
ref: develop

- name: Setup .NET SDK
uses: actions/setup-dotnet@v1
Expand Down
64 changes: 44 additions & 20 deletions Source/Juego/Juego.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Meadow;
using Meadow.Foundation.Audio;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Hardware;
using Meadow.Logging;
using System;

Expand All @@ -18,7 +19,7 @@ private Juego() { }
/// </summary>
public static IJuegoHardware? Create()
{
IJuegoHardware? hardware;
IJuegoHardware? hardware = null;
Logger? logger = Resolver.Log;

logger?.Debug("Initializing Juego...");
Expand All @@ -40,23 +41,51 @@ private Juego() { }
}
else if (device is IF7CoreComputeMeadowDevice { } ccm)
{
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
var leftSpeaker = new PiezoSpeaker(ccm.Pins.PB8);
var rightSpeaker = new PiezoSpeaker(ccm.Pins.PB9);

var i2cBus = ccm.CreateI2cBus(busSpeed: Meadow.Hardware.I2cBusSpeed.FastPlus);
logger?.Info("I2C Bus instantiated");

var mcpVersion = new Mcp23008(i2cBus, address: 0x23);
leftSpeaker = new PiezoSpeaker(ccm.Pins.PB8);
rightSpeaker = new PiezoSpeaker(ccm.Pins.PB9);
}
catch
{
logger?.Info("Failed to instantiate speakers");
}

logger?.Trace("McpVersion up");
var version = mcpVersion.ReadFromPorts();
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($"Hardware version is {version}");
try
{
logger?.Info("Intantiating version MCP23008");
mcpVersion = new Mcp23008(i2cBus, address: 0x23);
}
catch
{
logger?.Info("Failed to instantiate version MCP23008");
}

if (version >= JuegoHardwareV3.MinimumHardareVersion)
try
{
if (mcpVersion != null &&
version >= JuegoHardwareV3.MinimumHardareVersion)
{
logger?.Info("Instantiating Juego v3 hardware");
hardware = new JuegoHardwareV3(ccm, i2cBus)
Expand All @@ -71,22 +100,17 @@ private Juego() { }
logger?.Info("Instantiating Juego v2 hardware");
hardware = new JuegoHardwareV2(ccm, i2cBus)
{
Mcp_VersionInfo = mcpVersion,
Mcp_VersionInfo = mcpVersion!,
LeftSpeaker = leftSpeaker,
RightSpeaker = rightSpeaker,
};
}
}
catch (Exception e)
catch
{
logger?.Debug($"Failed to create McpVersion: {e.Message}");
hardware = null;
logger?.Info("Failed to instantiate Juego hardware");
}
}
else
{
throw new NotSupportedException();
}

return hardware;
}
Expand Down
31 changes: 0 additions & 31 deletions Source/Juego/JuegoHardwareV3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,37 +110,6 @@ public JuegoHardwareV3(IF7CoreComputeMeadowDevice device, II2cBus i2cBus)

Resolver.Log.Info("Initialize hardware...");

// DEV NOTE: **ALWAYS** Set up PWMs first - Nuttx PWM driver will step on pin configs otherwise
/* try // code left intentionally, restore once the PWM bug is fixed
{
LeftSpeaker = new PiezoSpeaker(device.Pins.PB8); //D03
}
catch (Exception e)
{
Resolver.Log.Error($"Err Left Speaker: {e.Message}");
}
try
{
RightSpeaker = new PiezoSpeaker(device.Pins.PB9); //D04
}
catch (Exception e)
{
Resolver.Log.Error($"Err Right Speaker: {e.Message}");
} */

/*
try
{
I2cBus = Device.CreateI2cBus(busSpeed: I2cBusSpeed.FastPlus);
Resolver.Log.Info("I2C initialized");
}
catch (Exception e)
{
Resolver.Log.Error($"Err initializing I2C Bus: {e.Message}");
}
*/

try
{
Mcp_Reset = Device.CreateDigitalOutputPort(Device.Pins.PA10, true);
Expand Down
3 changes: 2 additions & 1 deletion Source/Juego_Demo/DisplayController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Meadow.Foundation;
using Meadow;
using Meadow.Foundation;
using Meadow.Foundation.Graphics;
using Meadow.Units;

Expand Down
5 changes: 5 additions & 0 deletions Source/Juego_Demo/MeadowApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public override Task Initialize()

juego = Juego.Create();

if (juego == null)
{
return Task.FromException(new Exception("Juego hardware not found"));
}

if (juego.Display is { } display)
{
displayController = new DisplayController(display);
Expand Down
10 changes: 4 additions & 6 deletions Source/Juego_Prototype/Games/Lander/LanderGame.Renderer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using System;
using Meadow.Foundation;
using Meadow.Foundation.Audio;
using Meadow;
using Meadow.Foundation.Graphics;

namespace Juego.Games
Expand All @@ -9,7 +7,7 @@ public partial class LanderGame
{
readonly byte cellSize = 8;

DrawPixelDel DrawPixel;
readonly DrawPixelDel DrawPixel;

public void Init(MicroGraphics gl)
{
Expand All @@ -34,7 +32,7 @@ public void Update(IIOConfig ioConfig)

void DrawBackground(MicroGraphics graphics)
{

}

void DrawLives(MicroGraphics graphics)
Expand All @@ -46,7 +44,7 @@ void DrawLives(MicroGraphics graphics)

void DrawPixel1x(int x, int y, bool colored, MicroGraphics graphics, Color color)
{
graphics.DrawPixel(x, y, colored?color:Color.Black);
graphics.DrawPixel(x, y, colored ? color : Color.Black);
}

void DrawPixel2x(int x, int y, bool colored, MicroGraphics graphics)
Expand Down

0 comments on commit a9c690d

Please sign in to comment.