Skip to content

Commit

Permalink
orb-ui: load new sounds on new language
Browse files Browse the repository at this point in the history
dynamically on dbus event
  • Loading branch information
fouge authored and karelispanagiotis committed Apr 16, 2024
1 parent 1e66392 commit 6db248d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 11 deletions.
7 changes: 5 additions & 2 deletions orb-ui/examples/ui-replay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl FromStr for EventRecord {
// split line to take everything after "UI event:"
let (_, event) = line
.split_once("UI event: ")
.wrap_err("Unable to split line")?;
.wrap_err(format!("Unable to split line: {}", line))?;
let event = event.to_string();
match timestamp_str.parse::<DateTime<Utc>>() {
Ok(timestamp) => {
Expand Down Expand Up @@ -100,7 +100,10 @@ async fn main() -> Result<()> {
let event = record.event;
info!("Sending: {}", event);
// send the event to orb-ui over dbus
if let Err(e) = proxy.orb_signup_state_event(format!("{event}")).await {
if let Err(e) = proxy
.orb_signup_state_event(event.clone().to_string())
.await
{
warn!("Error sending event {event}: {:?}", e);
}

Expand Down
14 changes: 11 additions & 3 deletions orb-ui/src/engine/diamond.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
#[allow(clippy::too_many_lines)]
fn event(&mut self, event: &Event) -> Result<()> {
tracing::info!("UI event: {:?}", event);
tracing::info!("UI event: {}", serde_json::to_string(event)?.as_str());
match event {
Event::Bootup => {
self.stop_ring(LEVEL_NOTICE, true);
Expand Down Expand Up @@ -790,8 +790,16 @@ impl EventHandler for Runner<DIAMOND_RING_LED_COUNT, DIAMOND_CENTER_LED_COUNT> {
Event::SoundVolume { level } => {
self.sound.set_master_volume(*level);
}
Event::SoundLanguage { lang: _lang } => {
// fixme
Event::SoundLanguage { lang } => {
let language = lang.clone();
let sound = self.sound.clone();
// spawn a new task because we need some async work here
tokio::task::spawn(async move {
let language: Option<&str> = language.as_deref();
if let Err(e) = sound.load_sound_files(language, true).await {
tracing::error!("Error loading sound files: {:?}", e);
}
});
}
}
Ok(())
Expand Down
22 changes: 16 additions & 6 deletions orb-ui/src/engine/pearl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use std::f64::consts::PI;
use std::time::Duration;

use async_trait::async_trait;
use eyre::Result;
use futures::channel::mpsc;
Expand All @@ -6,13 +9,12 @@ use futures::future::Either;
use futures::{future, StreamExt};
use orb_messages::mcu_main::mcu_message::Message;
use orb_messages::mcu_main::{jetson_to_mcu, JetsonToMcu};
use pid::{InstantTimer, Timer};
use std::f64::consts::PI;
use std::time::Duration;
use tokio::sync::mpsc::UnboundedReceiver;
use tokio::time;
use tokio_stream::wrappers::{IntervalStream, UnboundedReceiverStream};

use pid::{InstantTimer, Timer};

use crate::engine::rgb::Argb;
use crate::engine::{
center, operator, ring, Animation, AnimationsStack, CenterFrame, Event,
Expand Down Expand Up @@ -184,7 +186,7 @@ impl Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
#[allow(clippy::too_many_lines)]
fn event(&mut self, event: &Event) -> Result<()> {
tracing::info!("UI event: {:?}", serde_json::to_string(event)?);
tracing::info!("UI event: {}", serde_json::to_string(event)?.as_str());
match event {
Event::Bootup => {
self.stop_ring(LEVEL_NOTICE, true);
Expand Down Expand Up @@ -777,8 +779,16 @@ impl EventHandler for Runner<PEARL_RING_LED_COUNT, PEARL_CENTER_LED_COUNT> {
Event::SoundVolume { level } => {
self.sound.set_master_volume(*level);
}
Event::SoundLanguage { lang: _lang } => {
// fixme
Event::SoundLanguage { lang } => {
let language = lang.clone();
let sound = self.sound.clone();
// spawn a new task because we need some async work here
tokio::task::spawn(async move {
let language: Option<&str> = language.as_deref();
if let Err(e) = sound.load_sound_files(language, true).await {
tracing::error!("Error loading sound files: {:?}", e);
}
});
}
}
Ok(())
Expand Down

0 comments on commit 6db248d

Please sign in to comment.