-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeadowApp.cs
156 lines (135 loc) · 5.31 KB
/
MeadowApp.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
using Meadow;
using Meadow.Devices;
using Meadow.Foundation;
using Meadow.Foundation.Graphics;
using System;
using System.IO;
using System.Threading.Tasks;
namespace Ws2812Display
{
// Change F7FeatherV2 to F7FeatherV1 for V1.x boards
public class MeadowApp : App<F7FeatherV2>
{
private Random rand = new Random();
private Ws2812Display display;
private MicroGraphics graphics;
public override Task Initialize()
{
Resolver.Log.Info("Initialize...");
// For the display test function, at least one panel with 8x8 is required.
// If the panel / grid is larger, the corresponding parameters of the Ws2812Display must be adjusted.
display = new Ws2812Display(
spiBus: Device.CreateSpiBus(),
panelWidth: 8,
panelHeight: 8,
panelCountWidth: 1,
panelCountHeight: 1,
brightness: Ws2812Display.DisplayBrightness.Level_3);
graphics = new MicroGraphics(display)
{
IgnoreOutOfBoundsPixels = true
};
return Task.CompletedTask;
}
public override async Task Run()
{
Resolver.Log.Info("Run...");
while(true)
{
// Ws2812 Display Test
for (int i = 0; i < 8; i++)
{
display.Brightness = (Ws2812Display.DisplayBrightness)i;
byte r = (byte)rand.Next(0, 255);
byte g = (byte)rand.Next(0, 255);
byte b = (byte)rand.Next(0, 255);
display.Fill(new Color(r, g, b));
display.Show();
await Task.Delay(250);
display.Clear();
}
await Task.Delay(250);
display.Fill(Color.Red);
display.Show();
await Task.Delay(250);
display.Fill(5, 5, 2, 2, Color.Green);
display.Show();
await Task.Delay(250);
display.Clear();
await Task.Delay(250);
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
display.DrawPixel(x, y, Color.OldLace); // R=253, G=245, B=230
display.Show();
await Task.Delay(5);
}
}
Resolver.Log.Info("Current color: " + display.PixelBuffer.GetPixel(0, 0).ToString());
await Task.Delay(250);
for (int x = 0; x < 8; x++)
{
for (int y = 0; y < 8; y++)
{
display.InvertPixel(x, y);
display.Show();
await Task.Delay(5);
}
}
Resolver.Log.Info("Current color: " + display.PixelBuffer.GetPixel(0, 0).ToString());
display.Brightness = Ws2812Display.DisplayBrightness.Level_2;
// MicroGraphics Test
graphics.Clear();
graphics.DrawTriangle(1, 0, 7, 0, 7, 6, Color.HotPink, true);
graphics.DrawTriangle(0, 1, 0, 7, 6, 7, Color.DarkSlateBlue, true);
graphics.Show();
await Task.Delay(250);
graphics.Clear();
await Task.Delay(250);
graphics.DrawRectangle(3, 3, 2, 2, Color.Navy, true);
graphics.Show();
await Task.Delay(150);
graphics.Clear();
graphics.DrawRectangle(2, 2, 4, 4, Color.Navy, true);
graphics.Show();
await Task.Delay(150);
graphics.Clear();
graphics.DrawRectangle(1, 1, 6, 6, Color.Navy, false);
graphics.Show();
await Task.Delay(150);
graphics.Clear();
await Task.Delay(250);
graphics.CurrentFont = new Font4x6();
graphics.DrawText(0, 1, "HI", Color.Red);
graphics.Show();
await Task.Delay(2000);
graphics.Clear();
await Task.Delay(250);
// Image Test
display.Brightness = Ws2812Display.DisplayBrightness.Level_7;
DrawImageFromFile(0, 0);
await Task.Delay(2000);
DrawImageFromResource(0, 0);
await Task.Delay(2000);
}
}
private void DrawImageFromFile(int x = 0, int y = 0)
{
Resolver.Log.Info("Showing file...");
var filePath = Path.Combine(MeadowOS.FileSystem.UserFileSystemRoot, $"snake.bmp");
var image = Image.LoadFromFile(filePath);
graphics.Clear();
graphics.DrawImage(x, y, image);
graphics.Show();
}
private void DrawImageFromResource(int x = 0, int y = 0)
{
Resolver.Log.Info("Showing resource...");
var image = Image.LoadFromResource($"zombie_res.bmp");
graphics.Clear();
graphics.DrawImage(x, y, image);
graphics.Show();
}
}
}