-
Notifications
You must be signed in to change notification settings - Fork 2
/
MainController.cs
69 lines (52 loc) · 1.57 KB
/
MainController.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
using GalleryViewer.Controllers;
using GalleryViewer.Hardware;
using Meadow;
using Meadow.Peripherals.Leds;
using System;
using System.Threading.Tasks;
namespace GalleryViewer;
internal class MainController
{
IGalleryViewerHardware hardware;
DisplayController displayController;
IRgbPwmLed onboardLed;
int selectedIndex = 0;
public MainController(IGalleryViewerHardware hardware)
{
this.hardware = hardware;
}
public void Initialize()
{
hardware.Initialize();
displayController = new DisplayController(hardware.Display);
hardware.RightButton.Clicked += ButtonRightClicked;
hardware.LeftButton.Clicked += ButtonLeftClicked;
onboardLed = hardware.RgbPwmLed;
onboardLed.SetColor(Color.Green);
}
void ButtonLeftClicked(object sender, EventArgs e)
{
onboardLed.SetColor(Color.Red);
if (selectedIndex + 1 > 2)
selectedIndex = 0;
else
selectedIndex++;
displayController.DrawImage(selectedIndex);
onboardLed.SetColor(Color.Green);
}
void ButtonRightClicked(object sender, EventArgs e)
{
onboardLed.SetColor(Color.Red);
if (selectedIndex - 1 < 0)
selectedIndex = 2;
else
selectedIndex--;
displayController.DrawImage(selectedIndex);
onboardLed.SetColor(Color.Green);
}
public Task Run()
{
displayController.DrawImage(0);
return Task.CompletedTask;
}
}