Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #26 from WildernessLabs/develop
Browse files Browse the repository at this point in the history
Update 1.9.0
  • Loading branch information
jorgedevs authored Feb 28, 2024
2 parents f3b464a + f17df23 commit 3cbf1ed
Show file tree
Hide file tree
Showing 32 changed files with 530 additions and 39 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/develop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ jobs:
uses: actions/setup-dotnet@v1
with:
dotnet-version:
7.0.x
8.0.x

- name: Install MAUI Workload
run: dotnet workload install maui --ignore-failed-sources
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ Source/Linux/.vs/
bin/
obj/
Source/CrossPlatform/DevCamp_Avalonia_Sample/.vs/
.vs/
8 changes: 4 additions & 4 deletions Source/CrossPlatform/MauiMeadow/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Meadow;
using Meadow.Foundation.Displays;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.ICs.IOExpanders;
using Meadow.Peripherals.Displays;
using Meadow.UI;

namespace MauiMeadow
Expand All @@ -18,9 +18,9 @@ public App()
MainPage = new AppShell();
}

protected Task MeadowInitialize()
protected Task MeadowInitialize()
{
var expander = new Ft232h();
var expander = FtdiExpanderCollection.Devices[0];

var display = new Gc9a01
(
Expand All @@ -30,7 +30,7 @@ protected Task MeadowInitialize()
resetPin: expander.Pins.C2
);

Resolver.Services.Add<IGraphicsDisplay>(display);
Resolver.Services.Add<IPixelDisplay>(display);

return Task.CompletedTask;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Meadow;
using Meadow.Foundation.Graphics;
using Meadow.Peripherals.Displays;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Input;
Expand All @@ -10,7 +11,7 @@ public class MainPageViewModel : INotifyPropertyChanged
{
private MicroGraphics graphics;

private IGraphicsDisplay _display;
private IPixelDisplay _display;

public ICommand CountCommand { get; set; }

Expand All @@ -27,7 +28,7 @@ private async Task WaitForDisplay()
{
while (_display == null)
{
_display = Resolver.Services.Get<IGraphicsDisplay>();
_display = Resolver.Services.Get<IPixelDisplay>();
await Task.Delay(100);
}

Expand Down
20 changes: 20 additions & 0 deletions Source/Linux/Amg8833_Sample/Amg8833_Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<AssemblyName>App</AssemblyName>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meadow.Linux" Version="*" />
<PackageReference Include="Meadow.Foundation.Graphics.MicroLayout" Version="*" />
<PackageReference Include="Meadow.Foundation.Displays.AsciiConsole" Version="*" />
<PackageReference Include="Meadow.Foundation.Sensors.Camera.Amg8833" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="libmpsse.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
93 changes: 93 additions & 0 deletions Source/Linux/Amg8833_Sample/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using Meadow;
using Meadow.Foundation.Displays;
using Meadow.Foundation.Graphics.MicroLayout;
using Meadow.Foundation.Sensors.Camera;
using Meadow.Peripherals.Displays;
using Meadow.Pinouts;

public class MeadowApp : App<Linux<RaspberryPi>>
{
private IPixelDisplay _display;
private DisplayScreen _screen;
private Amg8833 _camera;
private Box[] _pixelBoxes;

public static async Task Main(string[] args)
{
await MeadowOS.Start(args);
}

public override Task Initialize()
{
Console.WriteLine("Creating Outputs");

_display = new AsciiConsoleDisplay(8 * 4, 8 * 3); // each "pixel" will be 4x3

var i2c = Device.CreateI2cBus();
_camera = new Amg8833(i2c);

CreateLayout();

return base.Initialize();
}

private void CreateLayout()
{
_pixelBoxes = new Box[64];
_screen = new DisplayScreen(_display);
var x = 0;
var y = 0;
var boxSize = 4;
for (var i = 0; i < _pixelBoxes.Length; i++)
{
_pixelBoxes[i] = new Box(x, y, 4, 3)
{
ForeColor = Color.Blue
};

_screen.Controls.Add(_pixelBoxes[i]);

if (i % 8 == 7)
{
x = 0;
y += 3;
}
else
{
x += boxSize;
}
}
}

public override async Task Run()
{
var t = 0;

while (true)
{
var pixels = _camera.ReadPixels();

_screen.BeginUpdate();

for (var i = 0; i < pixels.Length; i++)
{
var color = pixels[i].Celsius switch
{
< 20 => Color.Black,
< 22 => Color.DarkViolet,
< 24 => Color.DarkBlue,
< 26 => Color.DarkGreen,
< 28 => Color.DarkOrange,
< 30 => Color.Yellow,
_ => Color.White
};

_pixelBoxes[i].ForeColor = color;
}

_screen.EndUpdate();

await Task.Delay(100);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meadow.Linux" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="app.config.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
70 changes: 70 additions & 0 deletions Source/Linux/Cloud/CloudCommandReceiver/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
using Meadow;
using Meadow.Cloud;
using Meadow.Logging;
using Meadow.Pinouts;

public class MyCommand : IMeadowCommand
{
public bool Enabled { get; set; }
public string? DisplayText { get; set; }
}

public class MeadowApp : App<Linux<WSL2>>
{
public static async Task Main(string[] args)
{
await MeadowOS.Start(args);
}

private DateTimeOffset _startTime;

public override Task Initialize()
{
_startTime = DateTimeOffset.UtcNow;

Resolver.Log.AddProvider(new DebugLogProvider());

Resolver.CommandService?.Subscribe<MyCommand>(HandleMyCommandReceived);

return base.Initialize();
}

private void OnCloudServiceError(object? sender, string e)
{
Resolver.Log.Info($"CLOUD ERROR: {e}");
}

private void HandleMyCommandReceived(MyCommand command)
{
TickEnabled = command.Enabled;

if (command.DisplayText != null && command.DisplayText.Length > 0)
{
Resolver.Log.Info($"{Environment.NewLine}{command.DisplayText}");
Tick = 1;
}
}

private int Tick { get; set; }
private bool TickEnabled { get; set; } = true;

public override async Task Run()
{
Tick = 1;

while (true)
{
await Task.Delay(1000);

if (TickEnabled)
{
Console.Write(".");

if (Tick++ % 10 == 0)
{
Console.WriteLine("");
}
}
}
}
}
3 changes: 3 additions & 0 deletions Source/Linux/Cloud/CloudCommandReceiver/app.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Update:
Enabled: true

20 changes: 20 additions & 0 deletions Source/Linux/Cloud/CloudEventPublisher/CloudEventPublisher.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Meadow.Linux" Version="*" />
</ItemGroup>

<ItemGroup>
<None Update="app.config.yaml">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
59 changes: 59 additions & 0 deletions Source/Linux/Cloud/CloudEventPublisher/MeadowApp.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
using Meadow;
using Meadow.Cloud;
using Meadow.Logging;
using Meadow.Pinouts;

public class MeadowApp : App<Linux<WSL2>>
{
public static async Task Main(string[] args)
{
await MeadowOS.Start(args);
}

private DateTimeOffset _startTime;

public override Task Initialize()
{
_startTime = DateTimeOffset.UtcNow;

Resolver.Log.AddProvider(new DebugLogProvider());
Resolver.MeadowCloudService.ServiceError += OnCloudServiceError;

return base.Initialize();
}

private void OnCloudServiceError(object? sender, string e)
{
Console.WriteLine($"CLOUD ERROR: {e}");
}

public override async Task Run()
{
var eventNumber = 20;

while (true)
{
var @event = new CloudEvent
{
Measurements = new()
{
{ "uptime", DateTime.UtcNow - _startTime },
{ "eventNumber", eventNumber++ },
{ "text", "foo bar" }
}
};

try
{
Console.WriteLine($"Sending event to Meadow.Cloud...");
await Resolver.MeadowCloudService.SendEvent(@event);
}
catch (Exception ex)
{
Resolver.Log.Error($"ERROR: {ex.Message}");
}

await Task.Delay(10000);
}
}
}
3 changes: 3 additions & 0 deletions Source/Linux/Cloud/CloudEventPublisher/app.config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Logging:
LogLevel:
Default: Trace
Loading

0 comments on commit 3cbf1ed

Please sign in to comment.