Skip to content

Commit c0aa413

Browse files
committed
feat: possible rounds display
1 parent 8dcb2bd commit c0aa413

File tree

9 files changed

+59
-35
lines changed

9 files changed

+59
-35
lines changed

src/github/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ const GITHUB_API_URL: &str = "https://api.github.com";
66
const GH_OWNER: &str = "FKMTime";
77
const GH_REPO: &str = "firmware";
88

9-
pub async fn get_releases(
10-
client: &reqwest::Client,
11-
) -> Result<Vec<structs::ReleaseAssetItem>> {
9+
pub async fn get_releases(client: &reqwest::Client) -> Result<Vec<structs::ReleaseAssetItem>> {
1210
let url = format!("{GITHUB_API_URL}/repos/{GH_OWNER}/{GH_REPO}/releases");
1311

1412
let res = client

src/handler.rs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,23 +106,15 @@ async fn send_device_status(
106106
) -> Result<()> {
107107
let state = state.inner.read().await;
108108
let settings = state.devices_settings.get(&esp_connect_info.id);
109-
let frame = if let Some(settings) = settings {
109+
let frame = if let Some(_settings) = settings {
110110
TimerPacket {
111111
tag: None,
112-
data: TimerPacketInner::DeviceSettings {
113-
use_inspection: settings.use_inspection,
114-
secondary_text: settings.secondary_text.clone(),
115-
added: true,
116-
},
112+
data: TimerPacketInner::DeviceSettings { added: true },
117113
}
118114
} else {
119115
TimerPacket {
120116
tag: None,
121-
data: TimerPacketInner::DeviceSettings {
122-
use_inspection: false,
123-
secondary_text: "".to_string(),
124-
added: false,
125-
},
117+
data: TimerPacketInner::DeviceSettings { added: false },
126118
}
127119
};
128120

@@ -217,6 +209,7 @@ async fn on_timer_response(
217209
country_iso2: info.country_iso2.unwrap_or_default(),
218210
display: format!("{}{}", info.name, registrant_display),
219211
can_compete: info.can_compete,
212+
possible_rounds: info.possible_rounds,
220213
},
221214
};
222215

@@ -243,8 +236,9 @@ async fn on_timer_response(
243236
session_id,
244237
delegate,
245238
inspection_time,
239+
round_id,
246240
} => {
247-
trace!("Solve: {solve_time} ({penalty}) {competitor_id} {esp_id} {timestamp} {session_id} {delegate}");
241+
trace!("Solve: {solve_time} ({penalty}) {competitor_id} {esp_id} {timestamp} {session_id} {delegate} {round_id}");
248242

249243
let res = crate::socket::api::send_solve_entry(
250244
solve_time,
@@ -256,6 +250,7 @@ async fn on_timer_response(
256250
delegate,
257251
&session_id,
258252
inspection_time,
253+
&round_id,
259254
)
260255
.await;
261256

src/socket/api.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
use anyhow::Result;
2-
use unix_utils::{request::UnixRequestData, response::UnixResponseData, SnapshotData, UnixError};
2+
use unix_utils::{
3+
request::UnixRequestData,
4+
response::{PossibleRound, UnixResponseData},
5+
SnapshotData, UnixError,
6+
};
37

48
#[derive(Debug)]
59
#[allow(dead_code)]
@@ -11,6 +15,7 @@ pub struct CompetitorInfo {
1115
pub country_iso2: Option<String>,
1216
pub gender: String,
1317
pub can_compete: bool,
18+
pub possible_rounds: Vec<PossibleRound>,
1419
}
1520

1621
pub async fn get_competitor_info(card_id: u64) -> Result<CompetitorInfo, UnixError> {
@@ -28,6 +33,7 @@ pub async fn get_competitor_info(card_id: u64) -> Result<CompetitorInfo, UnixErr
2833
country_iso2,
2934
gender,
3035
can_compete,
36+
possible_rounds,
3137
} = res
3238
{
3339
return Ok(CompetitorInfo {
@@ -38,6 +44,26 @@ pub async fn get_competitor_info(card_id: u64) -> Result<CompetitorInfo, UnixErr
3844
country_iso2,
3945
gender,
4046
can_compete,
47+
possible_rounds: possible_rounds.unwrap_or(
48+
[
49+
PossibleRound {
50+
id: "333-r1".to_string(),
51+
name: "3x3 R1".to_string(),
52+
use_inspection: true,
53+
},
54+
PossibleRound {
55+
id: "222-r1".to_string(),
56+
name: "2x2 R1".to_string(),
57+
use_inspection: true,
58+
},
59+
PossibleRound {
60+
id: "other".to_string(),
61+
name: "Other room".to_string(),
62+
use_inspection: false,
63+
},
64+
]
65+
.to_vec(),
66+
),
4167
});
4268
}
4369

@@ -84,6 +110,7 @@ pub async fn send_solve_entry(
84110
is_delegate: bool,
85111
session_id: &str,
86112
inspection_time: i64,
113+
round_id: &str,
87114
) -> Result<(), UnixError> {
88115
let solved_at = chrono::DateTime::from_timestamp_millis(solved_at as i64 * 1000)
89116
.ok_or_else(|| UnixError {
@@ -103,6 +130,7 @@ pub async fn send_solve_entry(
103130
is_delegate,
104131
session_id: session_id.to_string(),
105132
inspection_time,
133+
round_id: round_id.to_string(),
106134
};
107135

108136
let res = crate::UNIX_SOCKET

src/socket/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,7 @@ async fn process_untagged_response(data: UnixResponseData) -> Result<()> {
204204

205205
let mut devices = Vec::new();
206206
for room in status.rooms {
207-
let room_settings = crate::structs::CompetitionDeviceSettings {
208-
use_inspection: room.use_inspection,
209-
secondary_text: room.secondary_text.clone(),
210-
};
207+
let room_settings = crate::structs::CompetitionDeviceSettings {};
211208

212209
for device in room.devices {
213210
devices.push(device);

src/structs.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
3-
use unix_utils::{SnapshotData, TestPacketData};
3+
use unix_utils::{response::PossibleRound, SnapshotData, TestPacketData};
44

55
#[derive(Serialize, Deserialize, Debug, Clone)]
66
pub struct TimerPacket {
@@ -28,6 +28,7 @@ pub enum TimerPacketInner {
2828
session_id: String, // UUID
2929
delegate: bool,
3030
inspection_time: i64,
31+
round_id: String,
3132
},
3233
SolveConfirm {
3334
competitor_id: u64,
@@ -57,11 +58,10 @@ pub enum TimerPacketInner {
5758
display: String,
5859
country_iso2: String,
5960
can_compete: bool,
61+
possible_rounds: Vec<PossibleRound>,
6062
},
6163
AttendanceMarked,
6264
DeviceSettings {
63-
use_inspection: bool,
64-
secondary_text: String,
6565
added: bool,
6666
},
6767
Logs {
@@ -105,10 +105,7 @@ pub struct AppState {
105105
}
106106

107107
#[derive(Debug, Clone, PartialEq)]
108-
pub struct CompetitionDeviceSettings {
109-
pub use_inspection: bool,
110-
pub secondary_text: String,
111-
}
108+
pub struct CompetitionDeviceSettings {}
112109

113110
impl SharedAppState {
114111
pub async fn new(dev_mode: bool) -> Self {

src/updater.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,9 @@ pub async fn update_client(
102102
};
103103

104104
socket
105-
.send(Message::Text(serde_json::to_string(&start_update_resp)?.into()))
105+
.send(Message::Text(
106+
serde_json::to_string(&start_update_resp)?.into(),
107+
))
106108
.await?;
107109

108110
// wait for esp to respond

unix-utils/Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

unix-utils/src/request.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ pub enum UnixRequestData {
3232
is_delegate: bool,
3333
session_id: String,
3434
inspection_time: i64,
35+
round_id: String,
3536
},
3637
UpdateBatteryPercentage {
3738
esp_id: u32,

unix-utils/src/response.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub enum UnixResponseData {
2828
country_iso2: Option<String>,
2929
gender: String,
3030
can_compete: bool,
31+
possible_rounds: Option<Vec<PossibleRound>>, // TODO: remove option,
3132
},
3233
Error {
3334
message: String,
@@ -60,11 +61,16 @@ pub struct CompetitionStatusResp {
6061
pub struct Room {
6162
pub id: String,
6263
pub name: String,
63-
pub secondary_text: String,
64-
pub use_inspection: bool,
6564
pub devices: Vec<u32>,
6665
}
6766

67+
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
68+
pub struct PossibleRound {
69+
pub id: String,
70+
pub name: String,
71+
pub use_inspection: bool,
72+
}
73+
6874
#[derive(Default, Debug, Clone, PartialEq, Serialize, Deserialize)]
6975
#[serde(rename_all = "camelCase")]
7076
pub struct WifiSettings {

0 commit comments

Comments
 (0)