Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
68 lines (64 loc) · 1.51 KB
/
Copy pathProgram.cs
File metadata and controls
68 lines (64 loc) · 1.51 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
using System;
using MonoBrickFirmware.UserInput;
using MonoBrickFirmware.Display;
using MonoBrickFirmware.Sensors;
using System.Threading;
namespace SensorFactoryExample
{
class MainClass
{
public static void Main(string[] args)
{
object sensorLock = new object();
bool run = true;
ISensor[] sensor = new ISensor[4];
for (int i = 0; i < 4; i++)
{
sensor[i] = null;
}
using (SensorListner listner = new SensorListner())
{
listner.SensorAttached += delegate(ISensor obj)
{
lock (sensorLock)
{
if (obj != null)
{
sensor[(int) obj.Port] = obj;
}
}
};
listner.SensorDetached += delegate(SensorPort obj)
{
lock (sensorLock)
{
sensor[(int) obj] = null;
}
};
ButtonEvents buts = new ButtonEvents();
buts.EscapePressed += delegate
{
run = false;
};
while (run)
{
lock (sensorLock)
{
/*for (int i = 0; i < sensor.Length; i++) {
if (sensor[i] != null) {
typeLabel [i].Text = sensor[i].GetSensorName ();
modeLabel [i].Text = sensor[i].SelectedMode ();
valueLabel[i].Text = sensor[i].ReadAsString ();
} else {
typeLabel [i].Text = "Not connected";
modeLabel [i].Text = "-";
valueLabel [i].Text = "-";
}
}*/
}
System.Threading.Thread.Sleep(1000);
}
}
}
}
}