LEDExcute.cs
3.59 KB
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
using HHECS.Bll;
using LEDhelp;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace HHECS.Bll
{
public class LEDExcute
{
LEDHelper LeftLED;
LEDHelper RightLED;
public Queue<string> LeftInfoQueue { get; set; } = new Queue<string>();
public Queue<string> RightInfoQueue { get; set; } = new Queue<string>();
public LEDExcute()
{
string leftLedIP = ConfigurationManager.AppSettings["LeftLedIP"];
string rightLedIP = ConfigurationManager.AppSettings["RightLedIP"];
int ledPort = Convert.ToInt32(ConfigurationManager.AppSettings["ledPort"]);
LeftLED = new LEDhelp.LEDHelper(leftLedIP, (uint)ledPort, 1);
RightLED = new LEDhelp.LEDHelper(rightLedIP, (uint)ledPort, 1);
}
public void BeginSendInfo()
{
Task.Run(async () =>
{
while (true)
{
await Task.Delay(2000);
if (LeftLED != null && LeftInfoQueue != null && LeftInfoQueue.Count > 0)
{
SCREEN_ForceOnOff(LEDhelp.LEDHelper.LEFT, LEDhelp.LEDHelper.OPEN);
SCREEN_DelDynamicArea(LEDhelp.LEDHelper.LEFT, 0);
sendLedInfo(LEDhelp.LEDHelper.LEFT, LEDhelp.LEDHelper.GREEN, LeftInfoQueue.Dequeue());
setBrightness(LEDhelp.LEDHelper.LEFT, 10);
//int i = leftLED.SendLedInfo(LeftInfoQueue.Dequeue());
//Console.WriteLine("LED发送返回值:" + i);
//if (i != 0)
//{
// leftLED = new LEDHelper(AppSession.le, AppCommon.LedPort, AppCommon.LedTimer);
//}
}
}
});
}
private void sendLedInfo(int direction, int color, String sendText)
{
if (color == LEDhelp.LEDHelper.GREEN)
{
sendText = "\\C2" + sendText;
}
else if (color == LEDhelp.LEDHelper.YELLOW)
{
sendText = "\\C3" + sendText;
}
else
{
sendText = "\\C1" + sendText;
}
if (direction == LEDhelp.LEDHelper.RIGHT)
{
RightLED.SendLedInfo(sendText);
}
else
{
LeftLED.SendLedInfo(sendText);
}
}
private void SCREEN_ForceOnOff(int direction, byte status)
{
if (direction == LEDhelp.LEDHelper.RIGHT)
{
RightLED.SCREEN_ForceOnOff(status);
}
else
{
LeftLED.SCREEN_ForceOnOff(status);
}
}
// value 0-15 值越大亮度越大
public void setBrightness(int direction, byte value)
{
if (direction == LEDhelp.LEDHelper.RIGHT)
{
RightLED.setBrightness(1, value, null);
}
else
{
LeftLED.setBrightness(1, value, null);
}
}
public void SCREEN_DelDynamicArea(int direction, byte DeleteAreaId)
{
if (direction == LEDhelp.LEDHelper.RIGHT)
{
RightLED.SCREEN_DelDynamicArea(DeleteAreaId);
}
else
{
LeftLED.SCREEN_DelDynamicArea(DeleteAreaId);
}
}
}
}