mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-16 08:38:26 +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 演示活动",
|
||||
"en-audio": "Welcome to the simple REPL demo."
|
||||
},
|
||||
"replapp.beep.start": {
|
||||
"en": "beep started...",
|
||||
"replapp.audio.start": {
|
||||
"en": "tone started...",
|
||||
"zh": "哔声开始...",
|
||||
"en-audio": "beep started..."
|
||||
"en-audio": "tone started..."
|
||||
},
|
||||
"replapp.beep.help": {
|
||||
"en": "beep [tone [freq [duration]]]",
|
||||
"zh": "beep [tone [音频 [时长]]]",
|
||||
"en-audio": "beep tone, then optional frequency plus optional duration."
|
||||
"replapp.audio.help": {
|
||||
"en": "audio [tone [freq [duration]]]",
|
||||
"zh": "audio [tone [音频 [时长]]]",
|
||||
"en-audio": "audio tone, then optional frequency plus optional duration."
|
||||
},
|
||||
"replapp.beep.completion_a": {
|
||||
"replapp.audio.completion_a": {
|
||||
"en": "Playback stopped at",
|
||||
"zh": "播放停止在",
|
||||
"en-audio": "Playback stopped at"
|
||||
},
|
||||
"replapp.beep.completion_b": {
|
||||
"replapp.audio.completion_b": {
|
||||
"en": "frames",
|
||||
"zh": "帧",
|
||||
"en-audio": "frames"
|
||||
|
|
|
|||
|
|
@ -78,13 +78,13 @@ impl CommonEnv {
|
|||
*/
|
||||
|
||||
///// 1. add your module here, and pull its namespace into the local crate
|
||||
mod beep; use beep::*;
|
||||
mod audio; use audio::*;
|
||||
|
||||
pub struct CmdEnv {
|
||||
common_env: CommonEnv,
|
||||
lastverb: String::<256>,
|
||||
///// 2. declare storage for your command here.
|
||||
beep_cmd: Beep,
|
||||
audio_cmd: Audio,
|
||||
}
|
||||
impl CmdEnv {
|
||||
pub fn new(xns: &xous_names::XousNames) -> CmdEnv {
|
||||
|
|
@ -105,7 +105,7 @@ impl CmdEnv {
|
|||
common_env: common,
|
||||
lastverb: String::<256>::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 [
|
||||
///// 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 {
|
||||
|
|
|
|||
|
|
@ -6,19 +6,17 @@ use core::fmt::Write;
|
|||
use locales::t;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Beep {
|
||||
pub struct Audio {
|
||||
callback_id: Option<u32>,
|
||||
callback_conn: u32,
|
||||
framecount: u32,
|
||||
play_sample: f32, // count of play samples generated. in f32 to avoid int<->f32 conversions
|
||||
freq: f32,
|
||||
}
|
||||
impl Beep {
|
||||
impl Audio {
|
||||
pub fn new(xns: &xous_names::XousNames) -> Self {
|
||||
log::info!("initializing beep");
|
||||
let callback_conn = xns.request_connection_blocking(crate::SERVER_NAME_REPL).unwrap();
|
||||
log::info!("beep init returning");
|
||||
Beep {
|
||||
Audio {
|
||||
callback_id: None,
|
||||
callback_conn,
|
||||
framecount: 0,
|
||||
|
|
@ -32,12 +30,12 @@ const STOP_ID: usize = 1;
|
|||
const SAMPLE_RATE_HZ: f32 = 8000.0;
|
||||
// note to self: A4 = 440.0, E4 = 329.63, C4 = 261.63
|
||||
|
||||
impl<'a> ShellCmdApi<'a> for Beep {
|
||||
cmd_api!(beep);
|
||||
impl<'a> ShellCmdApi<'a> for Audio {
|
||||
cmd_api!(audio);
|
||||
|
||||
fn process(&mut self, args: String::<1024>, env: &mut CommonEnv) -> Result<Option<String::<1024>>, xous::Error> {
|
||||
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(' ');
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
write!(ret, "{}", t!("replapp.beep.start", xous::LANG)).unwrap();
|
||||
write!(ret, "{}", t!("replapp.audio.start", xous::LANG)).unwrap();
|
||||
}
|
||||
_ => {
|
||||
write!(ret, "{}", helpstring).unwrap();
|
||||
|
|
@ -134,9 +132,9 @@ impl<'a> ShellCmdApi<'a> for Beep {
|
|||
let mut ret = String::<1024>::new();
|
||||
env.codec.pause().unwrap(); // this should stop callbacks from occurring too.
|
||||
write!(ret, "{} {} {}.",
|
||||
t!("replapp.beep.completion_a", xous::LANG),
|
||||
t!("replapp.audio.completion_a", xous::LANG),
|
||||
self.framecount,
|
||||
t!("replapp.beep.completion_b", xous::LANG),
|
||||
t!("replapp.audio.completion_b", xous::LANG),
|
||||
).unwrap();
|
||||
self.framecount = 0;
|
||||
self.play_sample = 0.0;
|
||||
Loading…
Reference in a new issue