-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
204 lines (180 loc) · 5.19 KB
/
index.js
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
const fs = require('fs')
const irsdk = require('node-irsdk-2021')
const iracing = irsdk.init({telemetryUpdateInterval: 1000})
const Govee = require("govee-lan-control");
const govee = new Govee.default();
govee.on("deviceAdded", async (device) => {
console.log(`Device "${device.model}" has been detected`);
device.actions.setColor({
rgb: [0, 0, 0],
});
let sessionFlags = []; // Array to store currently triggered flags
let cautionWavingInterval;
let greenInterval;
let blueInterval;
let yellowWavingInterval;
iracing.on('Telemetry', function (evt) {
const flagsToCheck = ["Checkered", "White", "Green", "Yellow", "Blue", "YellowWaving", "GreenHeld", "Caution", "CautionWaving", "Disqualify"];
const matchingFlags = flagsToCheck.filter(flag => evt.values.SessionFlags.includes(flag));
const newFlags = matchingFlags.filter(flag => !sessionFlags.includes(flag));
const removedFlags = sessionFlags.filter(flag => !matchingFlags.includes(flag));
newFlags.forEach(flag => {
sessionFlags.push(flag);
trigger_light(flag);
console.log(`Flag "${flag}" is appearing for the first time.`);
});
removedFlags.forEach(flag => {
sessionFlags = sessionFlags.filter(f => f !== flag);
console.log(`Flag "${flag}" has been removed.`);
stop_light(flag);
});
});
function stop_light(flag) {
if (flag === "CautionWaving") {
clearInterval(cautionWavingInterval);
cautionWavingInterval = undefined;
device.actions.setColor({
rgb: [0, 0, 0],
});
}
if (flag === "YellowWaving") {
clearInterval(yellowWavingInterval);
yellowWavingInterval = undefined;
device.actions.setColor({
rgb: [0, 0, 0],
});
}
if (flag === "Green") {
clearInterval(greenInterval);
greenInterval = undefined;
device.actions.setColor({
rgb: [0, 0, 0],
});
}
if (flag === "Blue") {
clearInterval(blueInterval);
blueInterval = undefined;
device.actions.setColor({
rgb: [0, 0, 0],
});
}
}
let brightness = 10;
let isIncreasing = true;
let checkeredCount = 0;
function trigger_light(flag) {
if (flag === "CautionWaving") {
console.log("CautionWaving");
cautionWavingInterval = setInterval(() => {
device.actions.setColor({
rgb: [255, 76, 0],
});
device.actions.setBrightness(brightness);
if (brightness === 0) {
isIncreasing = true;
} else if (brightness === 100) {
isIncreasing = false;
}
if (isIncreasing) {
brightness = 100;
} else {
brightness = 0;
}
}, 700);
}
if (flag === "YellowWaving") {
console.log("YellowWaving");
yellowWavingInterval = setInterval(() => {
device.actions.setColor({
rgb: [255, 237, 0],
});
device.actions.setBrightness(brightness);
if (brightness === 0) {
isIncreasing = true;
} else if (brightness === 100) {
isIncreasing = false;
}
if (isIncreasing) {
brightness = 100;
} else {
brightness = 0;
}
}, 700);
}
if (flag === "Caution") {
console.log("Caution");
device.actions.setColor({
rgb: [255, 76, 0],
});
device.actions.setBrightness(100);
}
if (flag === "Yellow") {
console.log("Yellow");
device.actions.setColor({
rgb: [255, 237, 0],
});
device.actions.setBrightness(100);
}
if (flag === "Green") {
greenInterval = setInterval(() => {
device.actions.setColor({
rgb: [0, 255, 0],
});
device.actions.setBrightness(brightness);
if (brightness === 0) {
isIncreasing = true;
} else if (brightness === 100) {
isIncreasing = false;
}
if (isIncreasing) {
brightness = 100;
} else {
brightness = 0;
}
}, 700);
}
if(flag === "Checkered"){
const checkered = setInterval(() => {
device.actions.setColor({
rgb: [255, 255, 255],
});
device.actions.setBrightness(brightness);
if (brightness === 0) {
isIncreasing = true;
} else if (brightness === 100) {
isIncreasing = false;
}
if (isIncreasing) {
brightness = 100;
} else {
brightness = 0;
}
checkeredCount++;
console.log(checkeredCount);
if (checkeredCount === 10) {
device.actions.setColor({
rgb: [0, 0, 0],
});
clearInterval(checkered); // Stop the checkered after 10 iterations
}
}, 700);
}
if (flag === "Blue") {
console.log("Blue");
device.actions.setColor({
rgb: [0, 0, 255],
});
device.actions.setBrightness(100);
}
}
});
// Checkered = All White
// White = Fuck This we don't need it
// Green = Green
// Yellow = Solid Yellow
// Blue = Blue
// YellowWaving = Pulsing Yellow
// GreenHeld = Solid Green
// Caution = Solid Orange
// CautionWaving = Pulsing Orange
// Disqualify = Lights off