Skip to content

Commit

Permalink
Merge #89
Browse files Browse the repository at this point in the history
89: Fix bugs from Nationals r=TristanDebrunner a=TristanDebrunner

- Clear scheduled start time when timing parameters change (fixes #87)
- Fix refbox checking wrong game num from uwhscores at end of game
- Ignore duplicates of some messages
- Allow time between games to exceed 99:59 (fixes #76)
- Timeout HTTP requests after 10s, retry up to 6 times (fixes #85)
- Change default post-game duration to 120s
- Set time to next game with uwhscores start time when user switches game num
- Add windows CLI running instructions to README

Co-authored-by: Tristan Debrunner <tdebrunner@atlantissports.org>
  • Loading branch information
bors[bot] and TristanDebrunner authored Jul 27, 2022
2 parents fffd453 + 93bc8ee commit e9f4849
Show file tree
Hide file tree
Showing 13 changed files with 325 additions and 119 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,21 @@

The main software component here is the [`uwh-refbox`](uwh-refbox) crate. The other crates are support crates that are also used by other binaries, not included here.

# Running
# Running the Binary

On Windows and Mac the app can be run by downloading the latest relase from GitHub and following the bundled instructions.

If you want to change the size of the simulated panels, you will need to run via the command line:

## Windows

1. Open `PowerShell` (to open `PowerShell`, start by typing "PowerShell" into the search bar by the windows icon, then clicking the app)
2. Drag the `.exe` from `File Explorer` into the `PowerShell` window (this will insert the location of the `.exe` into the command line)
3. Add the following to the command line: `-s N` (with a space before `-s`) where `N` is any positive decimal number (`4` and `4.0` are both acceptable). `N` sets the size of the panels, the default value is `4`
4. Confrim that the command line now looks something like this: `'<PATH TO EXE>' -s 5.5`
5. Press `enter` to start the program

# Running From Source

1. You will need to [Install Rust](https://rustup.rs/)
2. Ensure that you have the following libraries installed:
Expand Down
2 changes: 1 addition & 1 deletion fonts/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fonts"
version = "0.1.0"
version = "0.1.1"
authors = ["Atlantis Sports <maintainers@atlantissports.org>"]
edition = "2021"

Expand Down
4 changes: 2 additions & 2 deletions uwh-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uwh-common"
version = "0.1.0"
version = "0.1.1"
authors = ["Atlantis Sports <maintainers@atlantissports.org>"]
edition = "2021"

Expand All @@ -14,7 +14,7 @@ arrayvec = { version = "0.7.2", default-features = false, features = ["serde"] }
defmt = "0.3.1"
derivative = { version = "2.2.0", features = ["use_core"] }
displaydoc = { version = "0.2.3", default-features = false }
fonts = { version = "0.1.0", path = "../fonts" }
fonts = { version = "0.1.1", path = "../fonts" }
log = "0.4.16"
serde = { version = "1.0", default-features = false }
serde_derive = "1.0"
Expand Down
4 changes: 2 additions & 2 deletions uwh-common/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl Default for Game {
pre_overtime_break: Duration::from_secs(180),
overtime_break_duration: Duration::from_secs(60),
pre_sudden_death_duration: Duration::from_secs(60),
post_game_duration: Duration::from_secs(60),
post_game_duration: Duration::from_secs(120),
nominal_break: Duration::from_secs(900),
minimum_break: Duration::from_secs(240),
}
Expand Down Expand Up @@ -169,7 +169,7 @@ mod test {
pre_sudden_death_duration = 60
sudden_death_allowed = true
team_timeouts_per_half = 1
post_game_duration = 60
post_game_duration = 120
nominal_break = 900
minimum_break = 240"#
);
Expand Down
20 changes: 13 additions & 7 deletions uwh-common/src/game_snapshot.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#[cfg(feature = "std")]
use crate::config::Game;
use crate::{config::Game, drawing_support::*};
use arrayref::array_ref;
use arrayvec::ArrayVec;
use core::{
cmp::{Ordering, PartialOrd},
cmp::{min, Ordering, PartialOrd},
time::Duration,
};
#[cfg(not(target_os = "windows"))]
Expand All @@ -15,8 +15,8 @@ use serde_derive::{Deserialize, Serialize};
const PANEL_PENALTY_COUNT: usize = 3;

/// Game snapshot information that the LED matrices need. Excludes some fields, limits to three
/// penalties (the three with the lowest remaining time), and places the penalties on a stack based
/// `ArrayVec`, instead of the heap based `Vec`
/// penalties (the three with the lowest remaining time), and places the penalties on a stack-based
/// `ArrayVec`, instead of the heap-based `Vec`
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct GameSnapshotNoHeap {
pub current_period: GamePeriod,
Expand All @@ -35,7 +35,7 @@ pub struct GameSnapshotNoHeap {
#[derive(Debug, PartialEq, Eq, Default, Clone, Serialize, Deserialize)]
pub struct GameSnapshot {
pub current_period: GamePeriod,
pub secs_in_period: u16,
pub secs_in_period: u32,
pub timeout: TimeoutSnapshot,
pub b_score: u8,
pub w_score: u8,
Expand Down Expand Up @@ -64,7 +64,13 @@ impl From<GameSnapshot> for GameSnapshotNoHeap {

Self {
current_period: snapshot.current_period,
secs_in_period: snapshot.secs_in_period,
secs_in_period: min(
snapshot
.secs_in_period
.try_into()
.unwrap_or(MAX_STRINGABLE_SECS),
MAX_STRINGABLE_SECS,
),
timeout: snapshot.timeout,
b_score: snapshot.b_score,
w_score: snapshot.w_score,
Expand Down Expand Up @@ -324,7 +330,7 @@ impl TimeoutSnapshot {
match self {
Self::None => Ok([0x00, 0x00]),
Self::Black(time) | Self::White(time) | Self::Ref(time) | Self::PenaltyShot(time) => {
if *time > 5999 {
if *time > MAX_STRINGABLE_SECS {
Err(EncodingError::TimeoutTimeTooLarge(*time))
} else {
let variant = match self {
Expand Down
6 changes: 6 additions & 0 deletions uwh-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ pub mod game_snapshot;

#[cfg(feature = "std")]
pub mod config;

pub mod drawing_support {
pub const MAX_STRINGABLE_SECS: u16 = 5999;
pub const MAX_LONG_STRINGABLE_SECS: u32 = 5_999_999;
pub const MAX_SHORT_STRINGABLE_SECS: u8 = 99;
}
6 changes: 3 additions & 3 deletions uwh-matrix-drawing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "uwh-matrix-drawing"
version = "0.1.0"
version = "0.1.1"
authors = ["Atlantis Sports <maintainers@atlantissports.org>"]
edition = "2021"

Expand All @@ -12,8 +12,8 @@ std = ["arrayvec/std", "serde/std", "uwh-common/std"]
arrayref = "0.3.6"
arrayvec = { version = "0.7.2", default-features = false }
embedded-graphics = "0.7.1"
fonts = { version = "0.1.0", path = "../fonts" }
fonts = { version = "0.1.1", path = "../fonts" }
more-asserts = "0.2"
serde = { version = "1.0", default-features = false }
serde_derive = "1.0"
uwh-common = { version = "0.1.0", path = "../uwh-common", default-features = false }
uwh-common = { version = "0.1.1", path = "../uwh-common", default-features = false }
24 changes: 19 additions & 5 deletions uwh-matrix-drawing/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use embedded_graphics::{
};
use fonts::fonts::{FONT_10X25, FONT_14X31, FONT_20X46, FONT_28X64, FONT_5X8, FONT_7X15};
use more_asserts::*;
use uwh_common::game_snapshot::*;
use uwh_common::{drawing_support::*, game_snapshot::*};

/// Draws all the details of the game onto the provided display. Assumes the dispaly is 256x64
///
Expand Down Expand Up @@ -307,8 +307,7 @@ pub fn draw_panels<D: DrawTarget<Color = Rgb888>>(
.draw(display)?;
let time: ArrayString<4> = match penalty.time {
PenaltyTime::Seconds(secs) => {
let i = if secs >= 60 { 1 } else { 2 };
ArrayString::from(secs_to_time_string(secs).get(i..).unwrap()).unwrap()
ArrayString::from(secs_to_time_string(secs).trim()).unwrap()
}
PenaltyTime::TotalDismissal => ArrayString::from("DSMS").unwrap(),
};
Expand Down Expand Up @@ -368,18 +367,33 @@ where
<T as Div>::Output: Display,
<T as Rem>::Output: Display,
{
assert_le!(secs, T::from(5999u16));
assert_le!(secs, T::from(MAX_STRINGABLE_SECS));
let min = secs / T::from(60u16);
let sec = secs % T::from(60u16);
let mut time_string = ArrayString::new();
write!(&mut time_string, "{:2}:{:02}", min, sec).unwrap();
time_string
}

pub fn secs_to_long_time_string<T>(secs: T) -> ArrayString<8>
where
T: Div<T> + Rem<T> + From<u32> + Copy + Ord + Debug,
<T as Div>::Output: Display,
<T as Rem>::Output: Display,
{
assert_le!(secs, T::from(MAX_LONG_STRINGABLE_SECS));
let min = secs / T::from(60u32);
let sec = secs % T::from(60u32);
let mut time_string = ArrayString::new();
write!(&mut time_string, "{:5}:{:02}", min, sec).unwrap();
time_string
}

pub fn secs_to_short_time_string<T>(secs: T) -> ArrayString<3>
where
T: Copy + Display,
T: From<u8> + Ord + Copy + Display + Debug,
{
assert_le!(secs, T::from(99u8));
let mut time_string = ArrayString::new();
write!(&mut time_string, ":{:02}", secs).unwrap();
time_string
Expand Down
4 changes: 2 additions & 2 deletions uwh-refbox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ time = { version = "0.3", features = ["local-offset", "macros", "serde", "serde-
tokio = { version = "1.18", features = ["io-util", "macros", "net", "sync", "time"] }
tokio-serial = "5.4"
toml = "0.5"
uwh-common = { version = "0.1.0", path = "../uwh-common"}
uwh-matrix-drawing = { version = "0.1.0", path = "../uwh-matrix-drawing"}
uwh-common = { version = "0.1.1", path = "../uwh-common"}
uwh-matrix-drawing = { version = "0.1.1", path = "../uwh-matrix-drawing"}

[target.'cfg(windows)'.build-dependencies]
winres = "0.1"
Expand Down
Loading

0 comments on commit e9f4849

Please sign in to comment.