-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
Copy pathLed.cs
90 lines (76 loc) · 2.15 KB
/
Led.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
//
// Copyright (c) .NET Foundation and Contributors
// See LICENSE file in the project root for full license information.
//
using System;
using System.Drawing;
using System.Threading;
using nanoFramework.Runtime.Native;
using CCSWE.nanoFramework.NeoPixel;
using CCSWE.nanoFramework.NeoPixel.Drivers;
using nanoFramework.Networking.Thread;
namespace Samples
{
public class Led
{
private NeoPixelStrip _led;
private ThreadDeviceRole _role;
/// <summary>
/// Open _led for inbuilt Neopixel
/// </summary>
public Led()
{
if (SystemInfo.TargetName.Contains("ESP32_H2") || SystemInfo.TargetName.Contains("ESP32_C6"))
{
var driver = new Ws2812B(CCSWE.nanoFramework.NeoPixel.ColorOrder.GRB);
_led = new NeoPixelStrip(8, 1, driver);
}
else
{
_led = null;
}
}
public void SetRxTX()
{
Set(_role, 0.2f);
Thread.Sleep(50);
Set(_role, 0.1f);
}
public void Set(ThreadDeviceRole role)
{
Set(role, 0.1f);
}
private void Set(ThreadDeviceRole role, float brightness)
{
Color col;
if (_led == null)
{
return;
}
// Save it for RXTX
_role = role;
switch (role)
{
case ThreadDeviceRole.Detached:
col = Color.White;
break;
case ThreadDeviceRole.Child:
col = Color.Green;
break;
case ThreadDeviceRole.Router:
col = Color.Blue;
break;
case ThreadDeviceRole.Leader:
col = Color.Red;
break;
case ThreadDeviceRole.Disabled:
default:
col = Color.Black;
brightness = 0;
break;
}
_led.SetLed(0, col, brightness);
_led.Update();
}
}
}