-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMeadowApp.cs
95 lines (81 loc) · 2.75 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
using Meadow;
using Meadow.Devices;
using Meadow.Foundation.Displays;
using Meadow.Foundation.Graphics;
using Meadow.Foundation.Leds;
using Meadow.Foundation.Sensors.Hid;
using Meadow.Hardware;
using Meadow.Peripherals.Displays;
using System.Threading.Tasks;
namespace TouchKeypad;
// public class MeadowApp : App<F7FeatherV1> <- If you have a Meadow F7v1.*
public class MeadowApp : App<F7FeatherV2>
{
Mpr121 sensor;
MicroGraphics graphics;
public override Task Initialize()
{
var onboardLed = new RgbPwmLed(
redPwmPin: Device.Pins.OnboardLedRed,
greenPwmPin: Device.Pins.OnboardLedGreen,
bluePwmPin: Device.Pins.OnboardLedBlue);
onboardLed.SetColor(Color.Red);
var display = new St7789(
spiBus: Device.CreateSpiBus(),
chipSelectPin: Device.Pins.D02,
dcPin: Device.Pins.D01,
resetPin: Device.Pins.D00,
width: 240, height: 240);
graphics = new MicroGraphics(display)
{
Stroke = 2,
Rotation = RotationType._180Degrees,
CurrentFont = new Font12x16(),
};
sensor = new Mpr121(Device.CreateI2cBus(I2cBusSpeed.Standard), 90, 100);
sensor.ChannelStatusesChanged += SensorChannelStatusesChanged;
onboardLed.SetColor(Color.Green);
return base.Initialize();
}
void DrawGrid()
{
graphics.Clear();
for (int columns = 0; columns < 3; columns++)
{
for (int rows = 3; rows >= 0; rows--)
{
graphics.DrawRectangle(columns * 57 + 38, rows * 57 + 10, 51, 51, Color.Cyan);
}
}
graphics.Show();
}
void SensorChannelStatusesChanged(object sender, ChannelStatusChangedEventArgs e)
{
graphics.Clear();
graphics.Stroke = 1;
for (int i = 0; i < e.ChannelStatus.Count; i++)
{
int numpadIndex = 0;
for (int columns = 0; columns < 3; columns++)
{
for (int rows = 3; rows >= 0; rows--)
{
if (numpadIndex == i)
{
if (e.ChannelStatus[(Mpr121.Channels)i])
graphics.DrawRectangle(columns * 57 + 38, rows * 57 + 10, 51, 51, Color.Cyan, true);
else
graphics.DrawRectangle(columns * 57 + 38, rows * 57 + 10, 51, 51, Color.Cyan);
}
numpadIndex++;
}
}
}
graphics.Show();
}
public override Task Run()
{
DrawGrid();
return base.Run();
}
}