fix (or at least improve) simultaneous tts initiation crash

This commit is contained in:
bunnie 2022-03-10 04:00:09 +08:00
parent a998cf06c4
commit 71d9cc38af
5 changed files with 9 additions and 5 deletions

View file

@ -79,7 +79,7 @@ fn xmain() -> ! {
}
}),
Some(api::Opcode::PauseStream) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
if codec.is_on() && codec.is_init() {
if codec.is_on() && codec.is_init() && codec.is_live() {
codec.drain(); // this will suppress any future callbacks from firing
while codec.can_play() {
xous::yield_slice();
@ -90,7 +90,7 @@ fn xmain() -> ! {
}
}),
Some(api::Opcode::AbortStream) => xous::msg_scalar_unpack!(msg, _, _, _, _, {
if codec.is_on() && codec.is_init() {
if codec.is_on() && codec.is_init() && codec.is_live() {
codec.audio_i2s_stop();
} else {
log::error!("attempted to abort a stream on an uninitialized codec, ignoring!")

View file

@ -281,7 +281,7 @@ impl<'a> Menu<'a> {
self.gam.redraw().unwrap();
#[cfg(feature="tts")]
{
// self.tts.tts_simple(&self.name).unwrap();
self.tts.tts_simple(&self.name).unwrap();
}
}
fn num_items(&self) -> usize {

View file

@ -41,5 +41,6 @@ chrono = "0.4"
[features]
debugprint = []
braille = [] # used for braille mode, so console isn't overwhelmed with status
tts = []
# default = ["debugprint"] # "debugprint"
default = []

View file

@ -7,11 +7,13 @@ use num_traits::*;
use crate::StatusOpcode;
#[allow(unused_variables)] // quiets a warning about unused com that is emitted in tts config. Would be nice to make this more targeted...
pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com: &com::Com) {
let key_conn = keys.lock().unwrap().conn();
let mut menuitems = Vec::<MenuItem>::new();
#[cfg(not(feature="tts"))] // no backlight on versions with no display
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.backlighton", xous::LANG)),
action_conn: Some(com.conn()),
@ -20,6 +22,7 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
close_on_select: true,
});
#[cfg(not(feature="tts"))]
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.backlightoff", xous::LANG)),
action_conn: Some(com.conn()),
@ -95,6 +98,7 @@ pub fn create_main_menu(keys: Arc<Mutex<RootKeys>>, status_conn: xous::CID, com:
close_on_select: true,
});
#[cfg(not(feature="tts"))]
menuitems.push(MenuItem {
name: String::from_str(t!("mainmenu.kbd", xous::LANG)),
action_conn: Some(status_conn),

View file

@ -111,6 +111,7 @@ fn xmain() -> ! {
synth_done.store(false, Ordering::SeqCst);
tts_be.tts_simple(msg.text.as_str().unwrap()).unwrap();
just_initiated = true;
log::debug!("resuming codec");
codec.resume().unwrap();
},
Some(Opcode::CodecCb) => msg_scalar_unpack!(msg, free_play, _available_rec, _, routing_id, {
@ -158,8 +159,6 @@ fn xmain() -> ! {
if (locked_buf.len() == 0) && synth_done.load(Ordering::SeqCst) {
codec.pause().unwrap();
}
} else {
codec.pause().unwrap(); // this should stop callbacks from occurring too.
}
}),
Some(Opcode::CodecStop) => {