console_interface.c

Functions

ledInterface_init

 9void ledInterface_init(void)
10{
11    previousLightValue.red = 255;
12    previousLightValue.green = 255;
13    previousLightValue.blue = 255;
14}

ledInterface

16void ledInterface(void)
17{
18    RGBColor lightValue;
19
20    RteGetLightValue(&lightValue);
21
22    // Check if the light value has changed
23    if (lightValue.red != previousLightValue.red ||
24        lightValue.green != previousLightValue.green ||
25        lightValue.blue != previousLightValue.blue)
26    {
27
28        // Update the previous light value
29        previousLightValue = lightValue;
30
31        // printf("%d\n", previousLightValue.blue);
32
33        // Get the handle to the current output buffer ...
34        HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
35
36        // and hide the cursor ...
37        CONSOLE_CURSOR_INFO cursorInfo;
38        GetConsoleCursorInfo(hConsole, &cursorInfo);
39        cursorInfo.bVisible = FALSE;
40        SetConsoleCursorInfo(hConsole, &cursorInfo);
41
42        // and print the LED representation.
43        printf("\x1b[48;2;%d;%d;%dm", lightValue.red, lightValue.green, lightValue.blue);
44        printf("LED\r");
45    }
46}