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

Add basic YoshiPi template #9

Merged
merged 14 commits into from
Aug 21, 2024
2 changes: 1 addition & 1 deletion Source/dotnet/Driver/IYoshiPiHardware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public interface IYoshiPiHardware : IMeadowAppEmbeddedHardware
/// <summary>
/// Gets the pixel display.
/// </summary>
IPixelDisplay Display { get; }
IColorInvertableDisplay Display { get; }

/// <summary>
/// Gets the calibratable touchscreen.
Expand Down
1 change: 1 addition & 0 deletions Source/dotnet/Driver/YoshiPi.Hardware.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Core\Source\implementations\linux\Meadow.Linux\Meadow.Linux.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Driver\Graphics.MicroLayout.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\Displays.TftSpi\Driver\Displays.TftSpi.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\ICs.ADCs.Mcp3xxx\Driver\ICs.ADC.Mcp3xxx.csproj" />
<ProjectReference Include="..\..\..\..\Meadow.Foundation\Source\Meadow.Foundation.Peripherals\ICs.IOExpanders.Mcp23xxx\Driver\ICs.IOExpanders.Mcp23xxx.csproj" />
Expand Down
14 changes: 1 addition & 13 deletions Source/dotnet/Driver/YoshiPiApp.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using Meadow;
using Meadow.Foundation.Displays;
using System.Threading.Tasks;

namespace YoshiPi;

Expand All @@ -9,15 +7,5 @@ namespace YoshiPi;
/// </summary>
public abstract class YoshiPiApp : App<RaspberryPi, YoshiPiHardwareProvider, IYoshiPiHardware>
{
public virtual bool InvertDisplayColors => true;

public override Task Initialize()
{
if (InvertDisplayColors)
{
(Hardware.Display as Ili9341)?.InvertDisplayColor(true);
}

return base.Initialize();
}
}
}
4 changes: 2 additions & 2 deletions Source/dotnet/Driver/YoshiPi_v1b.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class YoshiPi_v1b : IYoshiPiHardware, IDisposable
private IButton? _button2;
private readonly IDigitalInterruptPort? _mcpInt;
private IRealTimeClock? _rtc;
private IPixelDisplay? _display;
private IColorInvertableDisplay? _display;
private ICalibratableTouchscreen? _touchscreen;
private IDigitalOutputPort _displayCsOutputPort;
private IDigitalOutputPort _displayDcOutputPort;
Expand Down Expand Up @@ -178,7 +178,7 @@ public IButton Button2
}

/// <inheritdoc/>
public IPixelDisplay Display
public IColorInvertableDisplay Display
{
get
{
Expand Down
5 changes: 3 additions & 2 deletions Source/dotnet/Samples/ValidationApp/TestService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Meadow.Foundation.Hmi;
using Meadow.Foundation.Sensors.Light;
using Meadow.Hardware;
using Meadow.Peripherals.Displays;
using System;
using System.IO;
using System.Threading.Tasks;
Expand Down Expand Up @@ -87,8 +88,8 @@ public async Task<TestResult> TestDisplay()

_display = new DisplayService(
new DisplayScreen(
_hardware.Display,
Meadow.Peripherals.Displays.RotationType._270Degrees,
(IPixelDisplay)_hardware.Display,
adrianstevens marked this conversation as resolved.
Show resolved Hide resolved
RotationType._270Degrees,
_hardware.Touchscreen)
);

Expand Down
1 change: 0 additions & 1 deletion Source/dotnet/Samples/ValidationApp/ValidationApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<AssemblyName>App</AssemblyName>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Meadow.Foundation.Graphics.MicroLayout" Version="*" />
<PackageReference Include="Meadow.Foundation.Sensors.Light.Veml7700" Version="*" />
</ItemGroup>
<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("YoshiPi.Templates")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Jorge Ramirez")]
[assembly: AssemblyProduct("YoshiPi.Templates")]
[assembly: AssemblyCopyright("Copyright © Jorge Ramirez 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("38652c8d-9855-4a4b-9d7d-836866856e93")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
47 changes: 47 additions & 0 deletions Source/dotnet/Templates/YoshiPi.Templates/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# YoshiMaker.YoshiPi.Template

Contains a collection of Project Template(s) for the .NET IoT YoshiPi that runs Meadow.

Meadow is a complete, IoT platform with defense-grade security that runs full .NET applications on embeddable microcontrollers and Linux single-board computers including Raspberry Pi and NVIDIA Jetson.

For more information, visit [developer.wildernesslabs.co](http://developer.wildernesslabs.co/).

To view all Wilderness Labs open-source projects, including samples, visit [github.com/wildernesslabs](https://github.com/wildernesslabs/).

## Installation

You can install YoshiPi project templates with the command:

```console
dotnet new install YoshiMaker.YoshiPi.Template
```

Once installed, it will list all the project templates included:

```console
Template Name Short Name Language Tags
----------------- ------------- -------- ---------------
YoshiPi Basic App yoshipi-basic [C#] YoshiPi/Console
```

## Usage

Open Visual Studio 2022, click on File -> New -> Project, in the _Create a new Project_ window, search for YoshiPi, and you will see the list of YoshiPi template(s) available you've just installed.

Alternatively, you can create a YoshiPi project via console using the _Short Name_ values on the list. For example:

```console
C:\Users\ramir>dotnet new yoshipi-basic --name hello
The template "YoshiPi Basic App" was created successfully.
```

Creates a basic YoshiPi application that shows an HMI with a button you can press on its touch-capable display.

## How to Contribute

- **Found a bug?** [Report an issue](https://github.com/yoshimoshi-garage/yoshipi/issues)
- Have a **feature idea or enhancement request?** [Open a new feature request](https://github.com/yoshimoshi-garage/yoshipi/issues)

## Need Help?

If you have questions or need assistance, please join the .NET IoT Hardware [community on Discord](https://discord.gg/6fKG7UXGQK).
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "http://json.schemastore.org/template",
"classifications": [ "YoshiPi", "Console" ],
"name": "YoshiPi Basic App",
"description": "A Meadow application that runs on a YoshiPi board",
"identity": "YoshiMaker.YoshiPi.CSharp.Template",
"groupIdentity": "YoshiMaker.YoshiPi",
"shortName": "yoshipi-basic",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "YoshiPiApplication.Template",
"preferNameDirectory": true,
"primaryOutputs": [
{ "path": "YoshiPiApplication.Template.csproj" }
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Deploy",
"type": "meadow",
"request": "launch",
"preLaunchTask": "meadow: Build"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
using Meadow;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.MicroLayout;
using Meadow.Foundation.Hmi;
using Meadow.Hardware;
using Meadow.Peripherals.Displays;
using System;
using System.IO;
using System.Threading.Tasks;

namespace YoshiPiApplication.Template;

public class DisplayController
{
private IColorInvertableDisplay display;
private ICalibratableTouchscreen touchscreen;
private DisplayScreen displayScreen;
private Label label;

private int count = 0;

public DisplayController(IColorInvertableDisplay display, ICalibratableTouchscreen touchscreen)
{
this.display = display;
this.touchscreen = touchscreen;

displayScreen = new DisplayScreen((IPixelDisplay)display, RotationType._270Degrees, touchscreen);
}

public async Task Start()
{
await CheckTouchscreenCalibration();
CreateLayouts();
}

private async Task CheckTouchscreenCalibration()
{
var calfile = new FileInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ts.cal"));

Resolver.Log.Info($"Using calibration data at {calfile.FullName}");

var cal = new TouchscreenCalibrationService(displayScreen, calfile);

var existing = cal.GetSavedCalibrationData();

if (existing != null)
{
touchscreen.SetCalibrationData(existing);
}
else
{
await cal.Calibrate(true);
}
}

private void CreateLayouts()
{
displayScreen.BackgroundColor = Color.FromHex("FFFFFF");

var assembly = typeof(Program).Assembly;
var resourceName = $"{assembly.GetName().Name}.Resources.image.bmp";
var image = Image.LoadFromResource(resourceName);
displayScreen.Controls.Add(new Picture(
left: 99,
top: 18,
width: 122,
height: 129,
image: image));

label = new Label(
left: 0,
top: 162,
width: displayScreen.Width,
height: 16)
{
Text = "Hello, World",
Font = new Font12x16(),
TextColor = Color.FromHex("1E2834"),
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center
};
displayScreen.Controls.Add(label);

var button = new Button(
left: 92,
top: 193,
width: 140,
height: 28)
{
Text = "Click Me",
Font = new Font12x16(),
ForeColor = Color.White,
TextColor = Color.FromHex("1E2834"),
ShadowColor = Color.FromHex("1E2834"),
HighlightColor = Color.FromHex("1E2834"),
};
button.Clicked += ButtonClicked;
displayScreen.Controls.Add(button);
}

private void ButtonClicked(object sender, EventArgs e)
{
count++;
string message = $"Clicked {count} times!";
label.Text = message;
Resolver.Log.Info(message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using Meadow;
using System.Threading.Tasks;
using YoshiPi;

namespace YoshiPiApplication.Template;

public class MeadowApp : YoshiPiApp
{
private DisplayController? displayController;

public override Task Initialize()
{
Resolver.Log.Info("Initialize...");

Hardware.Display.InvertDisplayColor(true);

displayController = new DisplayController(Hardware.Display, Hardware.Touchscreen);

return Task.CompletedTask;
}

public override async Task Run()
{
Resolver.Log.Info("Run...");

await displayController?.Start();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Meadow;
using System.Threading.Tasks;

namespace YoshiPiApplication.Template;

public class Program
{
public static async Task Main(string[] args)
{
await MeadowOS.Start(args);
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<None Remove="Resources\image.bmp" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\image.bmp" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="YoshiMaker.YoshiPi" Version="*" />
</ItemGroup>
<ItemGroup>
<None Update="app.config.yaml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>
Loading
Loading