Skip to content

Commit

Permalink
Merge #152
Browse files Browse the repository at this point in the history
152: Add whistle and flash panels r=TristanDebrunner a=TristanDebrunner

- Change the ref warning to a whistle sound effect, and change timing to be correct for a whistle (fixes #125)
- Flash the LED panels teal when the buzzer is triggered (fixes #86)
  - Flashing white was too large a current surge, and caused the panels to brown out. Electronics upgrades may enable switching from teal to white

Co-authored-by: Tristan Debrunner <tdebrunner@atlantissports.org>
  • Loading branch information
bors[bot] and TristanDebrunner authored Jan 25, 2023
2 parents a63024a + 923ef31 commit 2564036
Show file tree
Hide file tree
Showing 23 changed files with 356 additions and 145 deletions.
10 changes: 5 additions & 5 deletions Cargo.lock

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

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.3"
version = "0.1.4"
authors = ["Atlantis Sports <maintainers@atlantissports.org>"]
edition = "2021"

Expand Down
6 changes: 3 additions & 3 deletions matrix-drawing/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "matrix-drawing"
version = "0.1.3"
version = "0.1.4"
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.3", path = "../fonts" }
fonts = { version = "0.1.4", path = "../fonts" }
more-asserts = "0.2"
serde = { version = "1.0", default-features = false }
serde_derive = "1.0"
uwh-common = { version = "0.1.3", path = "../uwh-common", default-features = false }
uwh-common = { version = "0.1.4", path = "../uwh-common", default-features = false }
12 changes: 12 additions & 0 deletions matrix-drawing/src/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ use core::{
ops::{Div, Rem},
};
use embedded_graphics::{
geometry::{Point, Size},
mono_font::MonoTextStyle,
pixelcolor::Rgb888,
prelude::*,
primitives::{rectangle::Rectangle, PrimitiveStyle},
text::{Alignment, Baseline, LineHeight, Text, TextStyle, TextStyleBuilder},
};
use fonts::fonts::{FONT_10X25, FONT_14X31, FONT_20X46, FONT_28X64, FONT_5X8, FONT_7X15};
Expand All @@ -20,12 +22,14 @@ pub fn draw_panels<D: DrawTarget<Color = Rgb888>>(
display: &mut D,
state: GameSnapshotNoHeap,
white_on_right: bool,
flash: bool,
) -> Result<(), D::Error> {
const RED: Rgb888 = Rgb888::RED;
const YELLOW: Rgb888 = Rgb888::YELLOW;
const GREEN: Rgb888 = Rgb888::GREEN;
const BLUE: Rgb888 = Rgb888::new(64, 128, 255); //purple (225, 0, 255)
const WHITE: Rgb888 = Rgb888::WHITE;
const FLASH_COLOR: Rgb888 = Rgb888::new(0, 200, 200);

const CENTERED: TextStyle = TextStyleBuilder::new()
.alignment(Alignment::Center)
Expand All @@ -45,6 +49,14 @@ pub fn draw_panels<D: DrawTarget<Color = Rgb888>>(
.line_height(LineHeight::Percent(100))
.build();

if flash {
// display.clear(WHITE)?;
Rectangle::new(Point::new(0, 0), Size::new(255, 64))
.into_styled(PrimitiveStyle::with_fill(FLASH_COLOR))
.draw(display)?;
return Ok(());
}

let game_color = match state.timeout {
TimeoutSnapshot::PenaltyShot(_) => RED,
TimeoutSnapshot::Ref(_) => YELLOW,
Expand Down
15 changes: 13 additions & 2 deletions matrix-drawing/src/transmitted_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use uwh_common::game_snapshot::{DecodingError, EncodingError, GameSnapshotNoHeap
#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
pub struct TransmittedData {
pub white_on_right: bool,
pub flash: bool,
pub snapshot: GameSnapshotNoHeap,
}

Expand All @@ -13,14 +14,15 @@ impl TransmittedData {

pub fn encode(&self) -> Result<[u8; Self::ENCODED_LEN], EncodingError> {
let mut val = [0u8; Self::ENCODED_LEN];
val[0] = self.white_on_right as u8;
val[0] = ((self.flash as u8) << 1) | self.white_on_right as u8;
val[1..].copy_from_slice(&self.snapshot.encode()?);
Ok(val)
}

pub fn decode(bytes: &[u8; Self::ENCODED_LEN]) -> Result<Self, DecodingError> {
Ok(Self {
white_on_right: bytes[0] != 0,
white_on_right: bytes[0] & 0x01 != 0,
flash: bytes[0] & 0x02 != 0,
snapshot: GameSnapshotNoHeap::decode(array_ref![
bytes,
1,
Expand Down Expand Up @@ -51,6 +53,7 @@ mod test {

let mut data = TransmittedData {
white_on_right: true,
flash: true,
snapshot: state,
};

Expand Down Expand Up @@ -84,6 +87,14 @@ mod test {

test_data(&mut data)?;

data.flash = false;

test_data(&mut data)?;

data.white_on_right = true;

test_data(&mut data)?;

Ok(())
}
}
2 changes: 1 addition & 1 deletion overlay/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "overlay"
version = "0.1.3"
version = "0.1.4"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
8 changes: 4 additions & 4 deletions refbox/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "refbox"
version = "0.1.3"
version = "0.1.4"
description = "UI for Atlantis Sports's Underwater Hockey Refbox"
authors = ["Atlantis Sports <maintainers@atlantissports.org>"]
edition = "2021"
Expand All @@ -21,6 +21,7 @@ directories = "4"
embedded-graphics = "0.7.1"
enum-derive-2018 = "2"
env_logger = "0.9.0"
futures-lite = "1"
iced = { version = "0.4", default-features = false, features = ["canvas", "glow", "pure", "tokio"] }
iced_futures = { version = "0.4", features = ["async-std"] }
iced_native = "0.5"
Expand All @@ -40,12 +41,11 @@ 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.3", path = "../uwh-common"}
matrix-drawing = { version = "0.1.3", path = "../matrix-drawing"}
uwh-common = { version = "0.1.4", path = "../uwh-common"}
matrix-drawing = { version = "0.1.4", path = "../matrix-drawing"}
web-audio-api = { version = "0.26", default-features = false, features = ["cpal"] }

[target.'cfg(target_os = "linux")'.dependencies]
futures-lite = "1"
rppal = "0.14"

[target.'cfg(windows)'.build-dependencies]
Expand Down
Binary file removed refbox/resources/sounds/ref-alert-1.aup3
Binary file not shown.
Binary file removed refbox/resources/sounds/ref-alert-1.raw
Binary file not shown.
Binary file removed refbox/resources/sounds/ref-alert-2.aup3
Binary file not shown.
Binary file removed refbox/resources/sounds/ref-alert-2.raw
Binary file not shown.
Binary file added refbox/resources/sounds/whistle-0.aup3
Binary file not shown.
Binary file added refbox/resources/sounds/whistle-0.raw
Binary file not shown.
Binary file added refbox/resources/sounds/whistle-1.aup3
Binary file not shown.
Binary file added refbox/resources/sounds/whistle-1.raw
Binary file not shown.
23 changes: 12 additions & 11 deletions refbox/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ impl RefBoxApp {
}

fn maybe_play_sound(&self, new_snapshot: &GameSnapshot) {
let (play_ref_alert, play_buzzer) = match new_snapshot.timeout {
let (play_whistle, play_buzzer) = match new_snapshot.timeout {
TimeoutSnapshot::Black(time) | TimeoutSnapshot::White(time) => {
match self.snapshot.timeout {
TimeoutSnapshot::Black(old_time) | TimeoutSnapshot::White(old_time) => (
time != old_time && time == 20,
time != old_time && time == 15,
time != old_time && time == 0,
),
_ => (false, false),
Expand All @@ -142,7 +142,7 @@ impl RefBoxApp {
let prereqs = new_snapshot.current_period != GamePeriod::SuddenDeath
&& new_snapshot.secs_in_period != self.snapshot.secs_in_period;

let is_alert_period = match new_snapshot.current_period {
let is_whistle_period = match new_snapshot.current_period {
GamePeriod::BetweenGames
| GamePeriod::HalfTime
| GamePeriod::PreOvertime
Expand Down Expand Up @@ -172,15 +172,15 @@ impl RefBoxApp {
|| end_stops_play && self.config.sound.auto_sound_stop_play;

(
prereqs && is_alert_period && new_snapshot.secs_in_period == 35,
prereqs && is_whistle_period && new_snapshot.secs_in_period == 30,
prereqs && is_buzz_period && new_snapshot.secs_in_period == 0,
)
}
};

if play_ref_alert {
info!("Triggering ref alert");
self.sound.trigger_ref_alert();
if play_whistle {
info!("Triggering whistle");
self.sound.trigger_whistle();
} else if play_buzzer {
info!("Triggering buzzer");
self.sound.trigger_buzzer();
Expand Down Expand Up @@ -451,8 +451,6 @@ impl Application for RefBoxApp {
list_all_tournaments,
} = flags;

let sound = SoundController::new(config.sound.clone());

let (msg_tx, rx) = mpsc::unbounded_channel();
let message_listener = MessageListener {
rx: Arc::new(Mutex::new(Some(rx))),
Expand Down Expand Up @@ -481,6 +479,9 @@ impl Application for RefBoxApp {

let update_sender = UpdateSender::new(serial_ports, binary_port, json_port);

let sound =
SoundController::new(config.sound.clone(), update_sender.get_trigger_flash_fn());

let snapshot = Default::default();

(
Expand Down Expand Up @@ -1215,7 +1216,7 @@ impl Application for RefBoxApp {
BoolGameParameter::UsingUwhScores => edited_settings.using_uwhscores ^= true,
BoolGameParameter::SoundEnabled => edited_settings.sound.sound_enabled ^= true,
BoolGameParameter::RefAlertEnabled => {
edited_settings.sound.ref_alert_enabled ^= true
edited_settings.sound.whistle_enabled ^= true
}
BoolGameParameter::AutoSoundStartPlay => {
edited_settings.sound.auto_sound_start_play ^= true
Expand All @@ -1230,7 +1231,7 @@ impl Application for RefBoxApp {
match param {
CyclingParameter::BuzzerSound => sound.buzzer_sound.cycle(),
CyclingParameter::RemoteBuzzerSound(idx) => sound.remotes[idx].sound.cycle(),
CyclingParameter::AlertVolume => sound.ref_alert_vol.cycle(),
CyclingParameter::AlertVolume => sound.whistle_vol.cycle(),
CyclingParameter::AboveWaterVol => sound.above_water_vol.cycle(),
CyclingParameter::UnderWaterVol => sound.under_water_vol.cycle(),
}
Expand Down
Loading

0 comments on commit 2564036

Please sign in to comment.