/
NotificationController.cs
58 lines (49 loc) · 1.09 KB
/
NotificationController.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
using Meadow.Peripherals.Leds;
using System;
namespace Clima_Demo;
public class NotificationController
{
[Flags]
public enum Warnings
{
None = 0,
NetworkDisconnected = 1 << 0,
SolarLoadLow = 1 << 1,
BatteryLow = 1 << 2,
}
private readonly IRgbPwmLed? rgbLed;
private Warnings activeWarnings = Warnings.None;
public NotificationController(IRgbPwmLed? rgbLed)
{
this.rgbLed = rgbLed;
}
public void SystemStarting()
{
rgbLed?.SetColor(RgbLedColors.Red);
}
public void SystemUp()
{
ReportWarnings();
}
public void SetWarning(Warnings warning)
{
activeWarnings |= warning;
ReportWarnings();
}
public void ClearWarning(Warnings warning)
{
activeWarnings &= ~warning;
ReportWarnings();
}
private void ReportWarnings()
{
if (activeWarnings != Warnings.None)
{
rgbLed?.SetColor(RgbLedColors.Yellow);
}
else
{
rgbLed?.SetColor(RgbLedColors.Green);
}
}
}