Live Fixes

nm_live
noah metz 2024-02-03 10:30:28 -07:00
parent 978a3b1570
commit 29ae52286e
2 changed files with 41 additions and 9 deletions

@ -29,13 +29,12 @@ iframe{
</head> </head>
<div> <div>
<body> <body>
<iframe src="index.html?field=2/4" width="896" height="128"></iframe>
<iframe src="index.html?field=2/5" width="1176" height="168"></iframe>
<iframe src="index.html?field=2/6" width="896" height="128"></iframe>
<iframe src="index.html?field=1/1" width="896" height="128"></iframe> <iframe src="index.html?field=1/1" width="896" height="128"></iframe>
<iframe src="index.html?field=1/2" width="1176" height="168"></iframe> <iframe src="index.html?field=1/2" width="1176" height="168"></iframe>
<iframe src="index.html?field=1/3" width="896" height="128"></iframe> <iframe src="index.html?field=1/3" width="896" height="128"></iframe>
<iframe src="index.html?field=2/1" width="896" height="128"></iframe>
<iframe src="index.html?field=2/2" width="1176" height="168"></iframe>
<iframe src="index.html?field=2/3" width="896" height="128"></iframe>
</body> </body>
</div> </div>
</html> </html>

@ -15,11 +15,17 @@ let display_class_topic;
/** @type {string} */ /** @type {string} */
let display_name_topic; let display_name_topic;
/** @type {string} */
let display_sponsor_topic;
/** @type {number} */ /** @type {number} */
let score_midpoint_current = 50; let score_midpoint_current = 50;
/** @type {number} */ /** @type {number} */
let score_midpoint_setpoint = 50; let score_midpoint_setpoint = 50;
/** @type {string} */
let sponsor_state = "westmech";
let coeff_p = 0.1; let coeff_p = 0.1;
let red_anim_x = 0; let red_anim_x = 0;
@ -43,7 +49,9 @@ let event_name = "Mecha Mayhem 2024";
let match_name = "No Match"; let match_name = "No Match";
let match_name_show = "No Match"; let match_name_show = "No Match";
let score_red = 0; let score_red = 0;
let score_red_str = "";
let score_blue = 0; let score_blue = 0;
let score_blue_str = "";
/** @type {string[]} */ /** @type {string[]} */
let teams_red = []; let teams_red = [];
/** @type {string[]} */ /** @type {string[]} */
@ -101,6 +109,14 @@ client.on("connect", () => {
} }
}); });
client.subscribe(display_sponsor_topic, (err) => {
if (err) {
console.log(err);
} else {
console.log(`subscribed to ${display_sponsor_topic}`);
}
});
client.subscribe(field_metadata_topic, (err) => { client.subscribe(field_metadata_topic, (err) => {
if (err) { if (err) {
console.log(err); console.log(err);
@ -158,14 +174,11 @@ client.on("message", (topic, message) => {
let topic_str = topic.toString(); let topic_str = topic.toString();
let message_str = message.toString(); let message_str = message.toString();
console.log(`${topic_str} - ${message_str}`);
switch(topic_str){ switch(topic_str){
case "time": case "time":
let local = Date.now(); let local = Date.now();
let server = JSON.parse(message_str) * 1000; let server = JSON.parse(message_str) * 1000;
offset = local - server; offset = local - server;
console.log(`NEW offset: ${local} - ${server} = ${offset}`);
break; break;
case field_metadata_topic: case field_metadata_topic:
const field_obj = JSON.parse(message_str); const field_obj = JSON.parse(message_str);
@ -173,6 +186,9 @@ client.on("message", (topic, message) => {
teams_blue = [field_obj.blue_teams[0], field_obj.blue_teams[1]]; teams_blue = [field_obj.blue_teams[0], field_obj.blue_teams[1]];
let num = field_obj.tuple.match_num; let num = field_obj.tuple.match_num;
let round = field_obj.tuple.round; let round = field_obj.tuple.round;
if (round == "Qualification") {
round = "Qual";
}
match_name = `${round} ${num}`; match_name = `${round} ${num}`;
break; break;
case field_state_topic: case field_state_topic:
@ -184,6 +200,10 @@ client.on("message", (topic, message) => {
switch(state_obj.state) { switch(state_obj.state) {
case "Scheduled": case "Scheduled":
timer = match_name; timer = match_name;
score_red_str = "";
score_blue_str = "";
score_blue = 0;
score_red = 0;
match_name_show = "Next Match"; match_name_show = "Next Match";
break; break;
case "Timeout": case "Timeout":
@ -197,7 +217,11 @@ client.on("message", (topic, message) => {
match_name_show = match_name; match_name_show = match_name;
break; break;
case "DriverDone": case "DriverDone":
timer = "0:00"; timer = "Scoring";
display_state = sponsor_state;
setTimeout(() => {
display_state = "timer";
}, 6000);
break; break;
case "Autonomous": case "Autonomous":
timer_end = new Date(start_ms + 15000); timer_end = new Date(start_ms + 15000);
@ -218,7 +242,8 @@ client.on("message", (topic, message) => {
match_name_show = match_name; match_name_show = match_name;
break; break;
case "Scored": case "Scored":
timer = "Scoring"; timer = "Scored";
display_state = "timer";
match_name_show = match_name; match_name_show = match_name;
break; break;
} }
@ -227,11 +252,18 @@ client.on("message", (topic, message) => {
const score_obj = JSON.parse(message_str); const score_obj = JSON.parse(message_str);
score_red = score_obj.red_total; score_red = score_obj.red_total;
score_blue = score_obj.blue_total; score_blue = score_obj.blue_total;
if (timer != "Scoring") {
score_red_str = `${score_red}`;
score_blue_str = `${score_blue}`;
}
score_midpoint_setpoint = ((score_red + 1) / (score_red + score_blue + 2)) * 100; score_midpoint_setpoint = ((score_red + 1) / (score_red + score_blue + 2)) * 100;
break; break;
case display_state_topic: case display_state_topic:
display_state = message_str; display_state = message_str;
break; break;
case display_sponsor_topic:
sponsor_state = message_str;
break;
case display_name_topic: case display_name_topic:
display_name = message_str; display_name = message_str;
break; break;
@ -265,6 +297,7 @@ onMount(() => {
display_state_topic = `display/${field_id}/state`; display_state_topic = `display/${field_id}/state`;
display_class_topic = `display/${field_id}/class`; display_class_topic = `display/${field_id}/class`;
display_name_topic = `display/${field_id}/name`; display_name_topic = `display/${field_id}/name`;
display_sponsor_topic = `display/${field_id}/sponsor`;
}); });
</script> </script>