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

Feature/amg8833 #874

Merged
merged 24 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
a2f0eba
Starting implementation of CP2112
ctacke May 19, 2023
51b1fb6
more CP2112 bits
ctacke May 19, 2023
c0a5f87
working on CP2112 I2C implementation
ctacke May 22, 2023
47bedc7
updated CP2112 assembly info
ctacke May 30, 2023
66b7207
starting FT232 refactor
ctacke Sep 5, 2023
eba7582
re-doing FT232 for I2C
ctacke Sep 13, 2023
a71fe9b
FT232 SPI and GPIO rework
ctacke Sep 14, 2023
6b65c73
FT232 GPIO updates for new driver
ctacke Sep 20, 2023
41ac82f
Merge branch 'develop' into feature/ft232
ctacke Oct 7, 2023
b55b85e
Merge branch 'develop' into feature/cp2112
ctacke Jan 3, 2024
e8f039d
added native CP2112 libraries
ctacke Jan 3, 2024
711dd59
trying (and failing) to get the CP2112 to do an I2CWrite
ctacke Jan 3, 2024
f06bf7c
Starting work on the AMG8833
ctacke Jan 3, 2024
fd4d7e3
Merge branch 'feature/ft232' into feature/amg8388
ctacke Jan 3, 2024
e76761f
Updated AMG8833 driver and sample
ctacke Jan 3, 2024
d00b704
start for Amg8833 for raspi
ctacke Jan 4, 2024
2bd6e3f
Working on Ascii display
ctacke Jan 4, 2024
2838a45
fixes for ascii driver and updates to linux sample
ctacke Jan 5, 2024
70e4282
Update AsciiConsole display naming and add csproj metadata
adrianstevens Jan 7, 2024
d59cc7e
Cleanup
adrianstevens Jan 8, 2024
46b7f18
Merge remote-tracking branch 'origin/develop' into feature/amg8388
ctacke Jan 8, 2024
0105b5c
FT232 warning clean-up
ctacke Jan 8, 2024
11d973a
Clean up CP2112 doc warnings
ctacke Jan 8, 2024
86ad3bf
change ascii display sample to .net 7 so it will build in CI
ctacke Jan 8, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,12 @@ private void DrawLoopThreaded()
{
Resolver.App.InvokeOnMainThread((_) =>
{
if (!_updateInProgress && (IsInvalid || Controls.Any(c => c.IsInvalid)))
lock (Controls.SyncRoot)
{
_graphics.Clear(BackgroundColor);

lock (Controls.SyncRoot)
if (!_updateInProgress && (IsInvalid || Controls.Any(c => c.IsInvalid)))
{
_graphics.Clear(BackgroundColor);

foreach (var control in Controls)
{
if (control != null)
Expand All @@ -207,13 +207,11 @@ private void DrawLoopThreaded()
RefreshTree(control);
}
}
_graphics.Show();
IsInvalid = false;
}
_graphics.Show();
IsInvalid = false;
}
}

);
});

Thread.Sleep(50);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.Buffers;
using System;

namespace Meadow.Foundation.Displays
{
public partial class AsciiConsoleDisplay
{
internal class CharacterBuffer : IPixelBuffer
{
public int Width { get; }
public int Height { get; }
public ColorMode ColorMode => ColorMode.Format8bppGray;
public int BitDepth => 6;

public int ByteCount => throw new NotImplementedException();

public byte[] Buffer => throw new NotImplementedException();

private char[,] _buffer;

public CharacterBuffer(int width, int height)
{
Width = width;
Height = height;

_buffer = new char[width, height];
}

public void Clear()
{
Fill(Color.Black);
}

public void Fill(Color color)
{
for (var y = 0; y < Height; y++)
{
for (var x = 0; x < Width; x++)
{
SetPixel(x, y, color);
}
}
}

public void Fill(int originX, int originY, int width, int height, Color color)
{
for (var y = originY; y < height + originY; y++)
{
for (var x = originX; x < width + originX; x++)
{
SetPixel(x, y, color);
}
}
}

internal char GetPixelCharacter(int x, int y)
{
return _buffer[x, y];
}

public Color GetPixel(int x, int y)
{
throw new NotImplementedException();
}

public void InvertPixel(int x, int y)
{
throw new NotImplementedException();
}

public void SetPixel(int x, int y, Color color)
{
_buffer[x, y] = ColorToCharacter(color);
}

public void WriteBuffer(int originX, int originY, IPixelBuffer buffer)
{
throw new NotImplementedException();
}

private char ColorToCharacter(Color color)
{
var index = (int)((color.Color8bppGray / 255d) * (_colors.Length - 1));
return _colors[index];
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.Buffers;
using System;

namespace Meadow.Foundation.Displays;

public partial class AsciiConsoleDisplay : IGraphicsDisplay
{
private readonly CharacterBuffer _buffer;
private const string _colors = " `.-':_,^=;><+!rc*/z?sLTv)J7(|Fi{C}fI31tlu[neoZ5Yxjya]2ESwqkP6h9d4VpOGbUAKXHm8RD#$Bg0MNWQ%&@"; // 92 "colors"

public ColorMode ColorMode => PixelBuffer.ColorMode;

public ColorMode SupportedColorModes => ColorMode.Format8bppGray;

public int Width => PixelBuffer.Width;
public int Height => PixelBuffer.Height;
public IPixelBuffer PixelBuffer => _buffer;

public AsciiConsoleDisplay(int width, int height)
{
Console.Clear();
Console.SetCursorPosition(0, 0);

_buffer = new CharacterBuffer(width, height);
PixelBuffer.Clear();
}

public void Clear(bool updateDisplay = false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt all these public methods have XML comments?

{
PixelBuffer.Clear();
}

public void DrawPixel(int x, int y, Color color)
{
PixelBuffer.SetPixel(x, y, color);
}

public void DrawPixel(int x, int y, bool enabled)
{
PixelBuffer.SetPixel(x, y, enabled ? Color.White : Color.Black);
}

public void Fill(Color fillColor, bool updateDisplay = false)
{
PixelBuffer.Fill(fillColor);
if (updateDisplay)
{
Show();
}
}

public void Fill(int x, int y, int width, int height, Color fillColor)
{
PixelBuffer.Fill(x, y, width, height, fillColor);
}

public void InvertPixel(int x, int y)
{
PixelBuffer.InvertPixel(x, y);
}

public void Show()
{
for (var y = 0; y < Height; y++)
{
for (var x = 0; x < Width; x++)
{
Console.SetCursorPosition(x, y);
Console.Write(_buffer.GetPixelCharacter(x, y));
}
}
}

public void Show(int left, int top, int right, int bottom)
{
for (; left < right; left++)
{
for (; top < bottom; top++)
{
Console.SetCursorPosition(left, top);
Console.Write(_buffer.GetPixelCharacter(left, top));
}
}
}

public void WriteBuffer(int x, int y, IPixelBuffer displayBuffer)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<Project Sdk="Meadow.Sdk/1.1.0">
<PropertyGroup>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Nullable>enable</Nullable>
<LangVersion>10.0</LangVersion>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<PackageIcon>icon.png</PackageIcon>
<Authors>Wilderness Labs, Inc</Authors>
<TargetFramework>netstandard2.1</TargetFramework>
<OutputType>Library</OutputType>
<AssemblyName>AsciiConsole</AssemblyName>
<Company>Wilderness Labs, Inc</Company>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.Foundation/</PackageProjectUrl>
<PackageId>Meadow.Foundation.Displays.AsciiConsole</PackageId>
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.Foundation</RepositoryUrl>
<PackageTags>Meadow,Meadow.Foundation,Displays,Ascii,Console</PackageTags>
<Version>1.6.0.1</Version>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Description>Ascii console display</Description>
</PropertyGroup>
<ItemGroup>
<None Include=".\Readme.md" Pack="true" PackagePath="" />
<None Include="..\..\..\icon.png" Pack="true" PackagePath="" />
<ProjectReference Include="..\..\..\Meadow.Foundation.Core\Meadow.Foundation.Core.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Meadow.Foundation.Displays.AsciiConsoleDisplay

## How to Contribute

- **Found a bug?** [Report an issue](https://github.com/WildernessLabs/Meadow_Issues/issues)
- Have a **feature idea or driver request?** [Open a new feature request](https://github.com/WildernessLabs/Meadow_Issues/issues)
- Want to **contribute code?** Fork the [Meadow.Foundation](https://github.com/WildernessLabs/Meadow.Foundation) repository and submit a pull request against the `develop` branch


## Need Help?

If you have questions or need assistance, please join the Wilderness Labs [community on Slack](http://slackinvite.wildernesslabs.co/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

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

<ItemGroup>
<ProjectReference Include="..\..\..\..\Meadow.Foundation.Libraries_and_Frameworks\Graphics.MicroLayout\Driver\Graphics.MicroLayout.csproj" />
<ProjectReference Include="..\..\Driver\Meadow.Displays.AsciiConsole.csproj" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
using Meadow;
using Meadow.Foundation.Displays;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Graphics.MicroLayout;

namespace AsciiConsoleDisplay_Sample;

internal class Program
{
private static void Main(string[] args)
{
DrawShapes();
}

private static async Task MovingBox()
{
var colors = typeof(Color)
.GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public)
.Where(f => f.FieldType == typeof(Color))
.Select(c => (Color)c.GetValue(null)!)
.ToArray();

var colorIndex = 0;
var display = new AsciiConsoleDisplay(20, 15);
var screen = new DisplayScreen(display);
var box = new Box(0, 0, 4, 3)
{
ForeColor = colors[colorIndex]
};
screen.Controls.Add(box);

var x = 0;
var y = 0;
var xdir = 1;
var ydir = 1;

while (true)
{
screen.BeginUpdate();
box.Top = y;
box.Left = x;
box.ForeColor = colors[colorIndex];
screen.EndUpdate();

await Task.Delay(500);

if ((x >= display.Width - 4) || (x < 0))
{
xdir *= -1;
}
if ((y >= display.Height - 4) || (y < 0))
{
ydir *= -1;
}
x += (1 * xdir);
y += (1 * ydir);

colorIndex++;
if (colorIndex >= colors.Length) colorIndex = 0;
}
}

private static void DrawShapes()
{
var display = new AsciiConsoleDisplay(80, 60);

var graphics = new MicroGraphics(display)
{
IgnoreOutOfBoundsPixels = true,
};

graphics.Clear();

graphics.DrawTriangle(5, 5, 30, 30, 5, 30, Color.Red, false);
graphics.DrawRectangle(10, 12, 40, 20, Color.Yellow, false);
graphics.DrawCircle(20, 20, 20, Color.White, false);

graphics.Show();
}

private static async Task CycleColors()
{
var display = new AsciiConsoleDisplay(40, 30);

var colors = typeof(Color).GetFields(System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public).Where(c => c.FieldType == typeof(Color));
foreach (var color in colors)
{
for (var x = 0; x < 16; x++)
{
for (var y = 0; y < 16; y++)
{
var c = (Color)color.GetValue(null)!;

display.DrawPixel(x, y, c);
}
}

display.Show();

await Task.Delay(100);
}
}
}
Binary file not shown.
Binary file not shown.
Loading
Loading