mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
change name of the repl demo command to be more general
This commit is contained in:
parent
617fc3b8f6
commit
fcb27919d4
3 changed files with 22 additions and 24 deletions
|
|
@ -4,22 +4,22 @@
|
||||||
"zh": "简单的 repl 演示活动",
|
"zh": "简单的 repl 演示活动",
|
||||||
"en-audio": "Welcome to the simple REPL demo."
|
"en-audio": "Welcome to the simple REPL demo."
|
||||||
},
|
},
|
||||||
"replapp.beep.start": {
|
"replapp.audio.start": {
|
||||||
"en": "beep started...",
|
"en": "tone started...",
|
||||||
"zh": "哔声开始...",
|
"zh": "哔声开始...",
|
||||||
"en-audio": "beep started..."
|
"en-audio": "tone started..."
|
||||||
},
|
},
|
||||||
"replapp.beep.help": {
|
"replapp.audio.help": {
|
||||||
"en": "beep [tone [freq [duration]]]",
|
"en": "audio [tone [freq [duration]]]",
|
||||||
"zh": "beep [tone [音频 [时长]]]",
|
"zh": "audio [tone [音频 [时长]]]",
|
||||||
"en-audio": "beep tone, then optional frequency plus optional duration."
|
"en-audio": "audio tone, then optional frequency plus optional duration."
|
||||||
},
|
},
|
||||||
"replapp.beep.completion_a": {
|
"replapp.audio.completion_a": {
|
||||||
"en": "Playback stopped at",
|
"en": "Playback stopped at",
|
||||||
"zh": "播放停止在",
|
"zh": "播放停止在",
|
||||||
"en-audio": "Playback stopped at"
|
"en-audio": "Playback stopped at"
|
||||||
},
|
},
|
||||||
"replapp.beep.completion_b": {
|
"replapp.audio.completion_b": {
|
||||||
"en": "frames",
|
"en": "frames",
|
||||||
"zh": "帧",
|
"zh": "帧",
|
||||||
"en-audio": "frames"
|
"en-audio": "frames"
|
||||||
|
|
|
||||||
|
|
@ -78,13 +78,13 @@ impl CommonEnv {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
///// 1. add your module here, and pull its namespace into the local crate
|
///// 1. add your module here, and pull its namespace into the local crate
|
||||||
mod beep; use beep::*;
|
mod audio; use audio::*;
|
||||||
|
|
||||||
pub struct CmdEnv {
|
pub struct CmdEnv {
|
||||||
common_env: CommonEnv,
|
common_env: CommonEnv,
|
||||||
lastverb: String::<256>,
|
lastverb: String::<256>,
|
||||||
///// 2. declare storage for your command here.
|
///// 2. declare storage for your command here.
|
||||||
beep_cmd: Beep,
|
audio_cmd: Audio,
|
||||||
}
|
}
|
||||||
impl CmdEnv {
|
impl CmdEnv {
|
||||||
pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
|
pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
|
||||||
|
|
@ -105,7 +105,7 @@ impl CmdEnv {
|
||||||
common_env: common,
|
common_env: common,
|
||||||
lastverb: String::<256>::new(),
|
lastverb: String::<256>::new(),
|
||||||
///// 3. initialize your storage, by calling new()
|
///// 3. initialize your storage, by calling new()
|
||||||
beep_cmd: Beep::new(&xns),
|
audio_cmd: Audio::new(&xns),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -114,7 +114,7 @@ impl CmdEnv {
|
||||||
|
|
||||||
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
let commands: &mut [& mut dyn ShellCmdApi] = &mut [
|
||||||
///// 4. add your command to this array, so that it can be looked up and dispatched
|
///// 4. add your command to this array, so that it can be looked up and dispatched
|
||||||
&mut self.beep_cmd,
|
&mut self.audio_cmd,
|
||||||
];
|
];
|
||||||
|
|
||||||
if let Some(cmdline) = maybe_cmdline {
|
if let Some(cmdline) = maybe_cmdline {
|
||||||
|
|
|
||||||
|
|
@ -6,19 +6,17 @@ use core::fmt::Write;
|
||||||
use locales::t;
|
use locales::t;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Beep {
|
pub struct Audio {
|
||||||
callback_id: Option<u32>,
|
callback_id: Option<u32>,
|
||||||
callback_conn: u32,
|
callback_conn: u32,
|
||||||
framecount: u32,
|
framecount: u32,
|
||||||
play_sample: f32, // count of play samples generated. in f32 to avoid int<->f32 conversions
|
play_sample: f32, // count of play samples generated. in f32 to avoid int<->f32 conversions
|
||||||
freq: f32,
|
freq: f32,
|
||||||
}
|
}
|
||||||
impl Beep {
|
impl Audio {
|
||||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||||
log::info!("initializing beep");
|
|
||||||
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_REPL).unwrap();
|
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_REPL).unwrap();
|
||||||
log::info!("beep init returning");
|
Audio {
|
||||||
Beep {
|
|
||||||
callback_id: None,
|
callback_id: None,
|
||||||
callback_conn,
|
callback_conn,
|
||||||
framecount: 0,
|
framecount: 0,
|
||||||
|
|
@ -32,12 +30,12 @@ const STOP_ID: usize = 1;
|
||||||
const SAMPLE_RATE_HZ: f32 = 8000.0;
|
const SAMPLE_RATE_HZ: f32 = 8000.0;
|
||||||
// note to self: A4 = 440.0, E4 = 329.63, C4 = 261.63
|
// note to self: A4 = 440.0, E4 = 329.63, C4 = 261.63
|
||||||
|
|
||||||
impl<'a> ShellCmdApi<'a> for Beep {
|
impl<'a> ShellCmdApi<'a> for Audio {
|
||||||
cmd_api!(beep);
|
cmd_api!(audio);
|
||||||
|
|
||||||
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||||
let mut ret = String::<1024>::new();
|
let mut ret = String::<1024>::new();
|
||||||
let helpstring = t!("replapp.beep.help", xous::LANG);
|
let helpstring = t!("replapp.audio.help", xous::LANG);
|
||||||
let mut tokens = args.as_str().unwrap().split(' ');
|
let mut tokens = args.as_str().unwrap().split(' ');
|
||||||
|
|
||||||
if let Some(sub_cmd) = tokens.next() {
|
if let Some(sub_cmd) = tokens.next() {
|
||||||
|
|
@ -88,7 +86,7 @@ impl<'a> ShellCmdApi<'a> for Beep {
|
||||||
xous::send_message(conn, Message::new_scalar(cb_id as usize, 0, 0, 0, STOP_ID)).unwrap();
|
xous::send_message(conn, Message::new_scalar(cb_id as usize, 0, 0, 0, STOP_ID)).unwrap();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
write!(ret, "{}", t!("replapp.beep.start", xous::LANG)).unwrap();
|
write!(ret, "{}", t!("replapp.audio.start", xous::LANG)).unwrap();
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
write!(ret, "{}", helpstring).unwrap();
|
write!(ret, "{}", helpstring).unwrap();
|
||||||
|
|
@ -134,9 +132,9 @@ impl<'a> ShellCmdApi<'a> for Beep {
|
||||||
let mut ret = String::<1024>::new();
|
let mut ret = String::<1024>::new();
|
||||||
env.codec.pause().unwrap(); // this should stop callbacks from occurring too.
|
env.codec.pause().unwrap(); // this should stop callbacks from occurring too.
|
||||||
write!(ret, "{} {} {}.",
|
write!(ret, "{} {} {}.",
|
||||||
t!("replapp.beep.completion_a", xous::LANG),
|
t!("replapp.audio.completion_a", xous::LANG),
|
||||||
self.framecount,
|
self.framecount,
|
||||||
t!("replapp.beep.completion_b", xous::LANG),
|
t!("replapp.audio.completion_b", xous::LANG),
|
||||||
).unwrap();
|
).unwrap();
|
||||||
self.framecount = 0;
|
self.framecount = 0;
|
||||||
self.play_sample = 0.0;
|
self.play_sample = 0.0;
|
||||||
Loading…
Reference in a new issue