Add a color (2 colors can be now defined for a machine).
[temp2RGB.git] / IntelOC / Program.cs
1 using System.Net.Sockets;
2 using System.Net;
3
4 using static System.Console;
5
6 var vgaControl = new CVGAControl(true);
7 vgaControl.Initialize(false);
8 int numOfAdaptors = vgaControl.GetNumOfAdaptors();
9
10 WriteLine($"Number of adaptors: {numOfAdaptors}");
11
12 for (int i = 0; i < numOfAdaptors; i++)
13 {
14 //vgaControl.SelectAdaptor(i);
15 /*var id = vgaControl.GetAdaptorID(i);
16 var name = vgaControl.GetAdaptorName(i);
17 WriteLine($"Id: {id}, name: {name}");
18 */
19 WriteLine($"Id: {vgaControl.GetAdaptorID(i)}");
20 WriteLine($"Name: {vgaControl.GetAdaptorName(i)}");
21 }
22
23 var nbEffects = CVGAControl.GetNumOfEffects(1);
24 for (int nEffect = 0; nEffect < nbEffects; ++nEffect)
25 {
26 WriteLine($"Effect id: {CVGAControl.GetEffectID(1, nEffect)}, name: {CVGAControl.GetEffectName(1, nEffect)}");
27 int nOptionTypes = 0;
28 CVGAControl.GetEffectOptionTypes(1, nEffect, out nOptionTypes);
29 WriteLine($"option types: {nOptionTypes}");
30 WriteLine($"----------");
31 }
32
33 /*
34 for (int i = 0; i <= 100; i++)
35 {
36 var n = 1.0 - (double)i / 100;
37 vgaControl.SetLEDColor(1, (byte)(255.0 * (1.0 - n)), (byte)(255.0 * n), (byte)(20.0 * n));
38
39 Thread.Sleep(50);
40 }*/
41
42 byte effectId = 0;
43 var optionType = 40;
44 int nType = (optionType & 32) != 0 ? 0 : 1;
45
46 vgaControl.SetLEDBehavior(
47 1, // 1 : ALL.
48 effectId, // effectId
49 0, // nEffect
50 (byte)optionType, // nParams
51 0, // nSpeed
52 0, // nDuration
53 (byte)nType,
54 0,
55 255 // Brightness.
56 );
57
58 // Default color.
59 vgaControl.SetLEDColor(1, 0, 255, 40);
60
61 vgaControl.SetLEDBehavior(
62 1, // 1 : ALL.
63 effectId, // effectId
64 0, // nEffect
65 (byte)optionType, // nParams
66 0, // nSpeed
67 0, // nDuration
68 (byte)nType,
69 0,
70 255 // Brightness.
71 );
72
73 // Default color.
74 vgaControl.SetLEDColor(1, 0, 255, 40);
75
76 var server = new TcpListener(IPAddress.Loopback, 6577);
77 server.Start();
78 var buffer = new byte[3];
79
80 while (true)
81 {
82 WriteLine("Waiting new client...");
83 var socket = server.AcceptSocket();
84 socket.Blocking = true;
85 socket.ReceiveTimeout = 10_000;
86
87 try
88 {
89 while (socket.Connected)
90 {
91 var n = socket.Receive(buffer, buffer.Length, SocketFlags.None);
92 if (n == 0)
93 {
94 socket.Close();
95 break;
96 }
97 //WriteLine($"n: {n}, {socket.Connected}");
98
99 var r = buffer[0];
100 var g = buffer[1];
101 var b = buffer[2];
102
103 //WriteLine($"RGB: {r}, {g}, {b}");
104 vgaControl.SetLEDColor(1, r, g, b);
105 }
106 }
107 catch (SocketException exception)
108 {
109 WriteLine(exception.ToString());
110 }
111 }
112
113 vgaControl.Terminate();
114
115 WriteLine("Press any key");
116 Console.ReadKey();