mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
fix warnings in initial API
This commit is contained in:
parent
e62256b3df
commit
2b768e9b86
8 changed files with 57 additions and 47 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -532,6 +532,7 @@ version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"graphics-server",
|
"graphics-server",
|
||||||
"heapless",
|
"heapless",
|
||||||
|
"keyboard",
|
||||||
"log",
|
"log",
|
||||||
"log-server",
|
"log-server",
|
||||||
"rkyv",
|
"rkyv",
|
||||||
|
|
|
||||||
|
|
@ -136,11 +136,10 @@ fn xmain() -> ! {
|
||||||
xous::create_thread_simple(status_thread, chatlayout.status.gid()).expect("GAM: couldn't create status thread");
|
xous::create_thread_simple(status_thread, chatlayout.status.gid()).expect("GAM: couldn't create status thread");
|
||||||
|
|
||||||
// connect to the IME front end, and set its canvas
|
// connect to the IME front end, and set its canvas
|
||||||
/*
|
|
||||||
info!("GAM: acquiring connection to IMEF...");
|
info!("GAM: acquiring connection to IMEF...");
|
||||||
let imef_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_IME_FRONT).expect("GAM: can't connect to the IME front end");
|
let imef_conn = xous_names::request_connection_blocking(xous::names::SERVER_NAME_IME_FRONT).expect("GAM: can't connect to the IME front end");
|
||||||
ime_frontend::set_canvas(imef_conn, chatlayout.input).expect("GAM: couldn't set IMEF canvas");
|
ime_frontend::set_canvas(imef_conn, chatlayout.input).expect("GAM: couldn't set IMEF canvas");
|
||||||
*/
|
|
||||||
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
let mut last_time: u64 = ticktimer_server::elapsed_ms(ticktimer_conn).unwrap();
|
||||||
info!("GAM: entering main loop");
|
info!("GAM: entering main loop");
|
||||||
loop {
|
loop {
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ xous-names = { path = "../xous-names" }
|
||||||
graphics-server = {path = "../graphics-server"}
|
graphics-server = {path = "../graphics-server"}
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
rkyv = { version = "0.3.1", default_features = false }
|
rkyv = { version = "0.3.1", default_features = false }
|
||||||
|
keyboard = {path="../keyboard"}
|
||||||
|
|
||||||
|
|
||||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,10 @@ use log::{error, info};
|
||||||
use graphics_server::Gid;
|
use graphics_server::Gid;
|
||||||
use heapless::Vec;
|
use heapless::Vec;
|
||||||
use heapless::consts::U32;
|
use heapless::consts::U32;
|
||||||
|
use core::pin::Pin;
|
||||||
|
|
||||||
|
use rkyv::Unarchive;
|
||||||
|
use rkyv::archived_value;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
what else do we need:
|
what else do we need:
|
||||||
|
|
@ -20,12 +24,13 @@ what else do we need:
|
||||||
fn draw_canvas(gam_conn: xous::CID, canvas: Gid, pred_conn: xous::CID, newkeys: [char; 4]) {
|
fn draw_canvas(gam_conn: xous::CID, canvas: Gid, pred_conn: xous::CID, newkeys: [char; 4]) {
|
||||||
|
|
||||||
// this is just reference to remind me how to decode the key array
|
// this is just reference to remind me how to decode the key array
|
||||||
|
/*
|
||||||
for &k in newkeys.iter() {
|
for &k in newkeys.iter() {
|
||||||
if k != '\u{0000}' {
|
if k != '\u{0000}' {
|
||||||
key_queue.push(k).unwrap();
|
key_queue.push(k).unwrap();
|
||||||
if debug1{info!("IMEF: got key '{}'", k);}
|
if debug1{info!("IMEF: got key '{}'", k);}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -56,6 +61,7 @@ fn xmain() -> ! {
|
||||||
match opcode {
|
match opcode {
|
||||||
Opcode::SetCanvas(g) => {
|
Opcode::SetCanvas(g) => {
|
||||||
canvas = g;
|
canvas = g;
|
||||||
|
break;
|
||||||
},
|
},
|
||||||
_ => info!("IMEF: expected canvas Gid, but got {:?}", opcode)
|
_ => info!("IMEF: expected canvas Gid, but got {:?}", opcode)
|
||||||
}
|
}
|
||||||
|
|
@ -68,6 +74,7 @@ fn xmain() -> ! {
|
||||||
info!("IMEF: entering main loop");
|
info!("IMEF: entering main loop");
|
||||||
loop {
|
loop {
|
||||||
let envelope = xous::receive_message(imef_sid).unwrap();
|
let envelope = xous::receive_message(imef_sid).unwrap();
|
||||||
|
if debug1{info!("IMEF: got message {:?}", envelope);}
|
||||||
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
if let Ok(opcode) = Opcode::try_from(&envelope.body) {
|
||||||
match opcode {
|
match opcode {
|
||||||
Opcode::SetCanvas(g) => {
|
Opcode::SetCanvas(g) => {
|
||||||
|
|
@ -77,7 +84,7 @@ fn xmain() -> ! {
|
||||||
},
|
},
|
||||||
_ => info!("IMEF: unhandled opcode {:?}", opcode)
|
_ => info!("IMEF: unhandled opcode {:?}", opcode)
|
||||||
}
|
}
|
||||||
} else if let xous::Message::Borrow(m) = &msg.body {
|
} else if let xous::Message::Borrow(m) = &envelope.body {
|
||||||
let buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
let buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
||||||
let bytes = Pin::new(buf.as_ref());
|
let bytes = Pin::new(buf.as_ref());
|
||||||
let value = unsafe {
|
let value = unsafe {
|
||||||
|
|
@ -86,7 +93,10 @@ fn xmain() -> ! {
|
||||||
match &*value {
|
match &*value {
|
||||||
rkyv::Archived::<api::Opcode>::SetPrediction(rkyv_s) => {
|
rkyv::Archived::<api::Opcode>::SetPrediction(rkyv_s) => {
|
||||||
let s: xous::String<4096> = rkyv_s.unarchive();
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
||||||
prediction_conn = xous_names::request_connection(s.as_str());
|
match xous_names::request_connection(s.as_str().expect("IMEF: SetPrediction received malformed server name")) {
|
||||||
|
Ok(pc) => prediction_conn = pc,
|
||||||
|
_ => error!("IMEF: can't find predictive engine {}, retaining existign one.", s.as_str().expect("IMEF: SetPrediction received malformed server name")),
|
||||||
|
}
|
||||||
},
|
},
|
||||||
_ => panic!("IME_SH: invalid response from server -- corruption occurred in MemoryMessage")
|
_ => panic!("IME_SH: invalid response from server -- corruption occurred in MemoryMessage")
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,19 +1,17 @@
|
||||||
use xous::{Message, ScalarMessage};
|
|
||||||
|
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Unarchive)]
|
#[derive(Debug, rkyv::Archive, rkyv::Unarchive)]
|
||||||
pub struct Prediction {
|
pub struct Prediction {
|
||||||
index: u32,
|
pub index: u32,
|
||||||
string: xous::String,
|
pub string: xous::String<4096>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
#[derive(Debug, rkyv::Archive, rkyv::Unarchive)]
|
#[derive(Debug, rkyv::Archive, rkyv::Unarchive)]
|
||||||
pub enum Opcode {
|
pub enum Opcode {
|
||||||
/// update with the latest input candidate. Replaces the previous input.
|
/// update with the latest input candidate. Replaces the previous input.
|
||||||
Input(xous::String),
|
Input(xous::String<4096>),
|
||||||
|
|
||||||
/// feed back to the IME plugin as to what was picked, so predictions can be updated
|
/// feed back to the IME plugin as to what was picked, so predictions can be updated
|
||||||
Picked(xous::String),
|
Picked(xous::String<4096>),
|
||||||
|
|
||||||
/// fetch the prediction at a given index, where the index is ordered from 0..N, where 0 is the most likely prediction
|
/// fetch the prediction at a given index, where the index is ordered from 0..N, where 0 is the most likely prediction
|
||||||
/// if there is no prediction available, just return an empty string
|
/// if there is no prediction available, just return an empty string
|
||||||
|
|
|
||||||
|
|
@ -1,44 +1,43 @@
|
||||||
#![cfg_attr(target_os = "none", no_std)]
|
#![cfg_attr(target_os = "none", no_std)]
|
||||||
|
|
||||||
pub mod api;
|
pub mod api;
|
||||||
use xous::{CID, send_message, String};
|
use xous::{CID, String};
|
||||||
|
|
||||||
pub fn set_input(cid: CID, s: String) -> Result<(), xous::Error> {
|
pub fn set_input(cid: CID, s: String<4096>) -> Result<(), xous::Error> {
|
||||||
use rkyv::Write;
|
use rkyv::Write;
|
||||||
|
|
||||||
let mut rkyv_input = api::Opcode::Input(*s);
|
let rkyv_input = api::Opcode::Input(s);
|
||||||
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
||||||
let pos = writer.archive(&rkyv_s).expect("IMES|API: couldn't archive input string");
|
let pos = writer.archive(&rkyv_input).expect("IMES|API: couldn't archive input string");
|
||||||
let mut xous_buffer = writer.into_inner();
|
let xous_buffer = writer.into_inner();
|
||||||
|
|
||||||
xous_buffer.lend(cid, pos as u32).expect("IMES|API: set_input operation failure");
|
xous_buffer.lend(cid, pos as u32).expect("IMES|API: set_input operation failure");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn feedback_picked(cid: CID, s: String) -> Result<(), xous::Error> {
|
pub fn feedback_picked(cid: CID, s: String<4096>) -> Result<(), xous::Error> {
|
||||||
use rkyv::Write;
|
use rkyv::Write;
|
||||||
|
|
||||||
let mut rkyv_input = api::Opcode::Picked(*s);
|
let rkyv_picked = api::Opcode::Picked(s);
|
||||||
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
||||||
let pos = writer.archive(&rkyv_s).expect("IMES|API: couldn't archive picked string");
|
let pos = writer.archive(&rkyv_picked).expect("IMES|API: couldn't archive picked string");
|
||||||
let mut xous_buffer = writer.into_inner();
|
let xous_buffer = writer.into_inner();
|
||||||
|
|
||||||
xous_buffer.lend(cid, pos as u32).expect("IMES|API: feedback_picked operation failure");
|
xous_buffer.lend(cid, pos as u32).expect("IMES|API: feedback_picked operation failure");
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_prediction(cid: CID, index: u32) -> Result<xous::String, xous::Error> {
|
pub fn get_prediction(cid: CID, index: u32) -> Result<xous::String<4096>, xous::Error> {
|
||||||
use rkyv::Write;
|
use rkyv::Write;
|
||||||
use rkyv::Unarchive;
|
use rkyv::Unarchive;
|
||||||
|
|
||||||
let mut mutstr = xous::String::new();
|
let prediction = api::Prediction {
|
||||||
let mut prediction = api::Prediction {
|
|
||||||
index,
|
index,
|
||||||
string: mutstr
|
string: xous::String::<4096>::new(),
|
||||||
};
|
};
|
||||||
let mut pred_op = api::Opcode::Prediction(*prediction);
|
let pred_op = api::Opcode::Prediction(prediction);
|
||||||
|
|
||||||
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
let mut writer = rkyv::ArchiveBuffer::new(xous::XousBuffer::new(4096));
|
||||||
let pos = writer.archive(&pred_op).expect("IMES|API: couldn't archive prediction request");
|
let pos = writer.archive(&pred_op).expect("IMES|API: couldn't archive prediction request");
|
||||||
|
|
@ -50,11 +49,11 @@ pub fn get_prediction(cid: CID, index: u32) -> Result<xous::String, xous::Error>
|
||||||
if let rkyv::Archived::<api::Opcode>::Prediction(result) = returned {
|
if let rkyv::Archived::<api::Opcode>::Prediction(result) = returned {
|
||||||
let pred_r: api::Prediction = result.unarchive();
|
let pred_r: api::Prediction = result.unarchive();
|
||||||
|
|
||||||
let retstring: xous::String = pred_r.string.clone();
|
let retstring: xous::String<4096> = pred_r.string.clone();
|
||||||
Ok(retstring)
|
Ok(retstring)
|
||||||
} else {
|
} else {
|
||||||
let r = returned.unarchive();
|
let r = returned.unarchive();
|
||||||
info!("get_prediciton saw an unhandled return of {:?}", r);
|
log::info!("get_prediciton saw an unhandled return of {:?}", r);
|
||||||
Err(xous::Error::InvalidString)
|
Err(xous::Error::InvalidString)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -4,13 +4,14 @@
|
||||||
mod api;
|
mod api;
|
||||||
use api::*;
|
use api::*;
|
||||||
|
|
||||||
use core::convert::TryFrom;
|
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
|
||||||
use heapless::spsc::Queue;
|
use heapless::spsc::Queue;
|
||||||
use heapless::consts::U3;
|
use heapless::consts::U3;
|
||||||
|
|
||||||
|
use rkyv::Unarchive;
|
||||||
|
use core::pin::Pin;
|
||||||
|
use rkyv::{archived_value, archived_value_mut};
|
||||||
|
|
||||||
#[xous::xous_main]
|
#[xous::xous_main]
|
||||||
fn xmain() -> ! {
|
fn xmain() -> ! {
|
||||||
let debug1 = true;
|
let debug1 = true;
|
||||||
|
|
@ -24,12 +25,12 @@ fn xmain() -> ! {
|
||||||
|
|
||||||
info!("IME_SH: ready to accept requests");
|
info!("IME_SH: ready to accept requests");
|
||||||
|
|
||||||
let mut history: Queue<xous::String, U3> = Queue::new(); // this has 2^3 elements = 8
|
let mut history: Queue<xous::String<4096>, U3> = Queue::new(); // this has 2^3 elements = 8
|
||||||
let history_max = 8;
|
let history_max = 8;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let envelope = xous::receive_message(ime_sh_sid).unwrap();
|
let envelope = xous::receive_message(ime_sh_sid).unwrap();
|
||||||
if let xous::Message::Borrow(m) = &msg.body {
|
if let xous::Message::Borrow(m) = &envelope.body {
|
||||||
let buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
let buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
||||||
let bytes = Pin::new(buf.as_ref());
|
let bytes = Pin::new(buf.as_ref());
|
||||||
let value = unsafe {
|
let value = unsafe {
|
||||||
|
|
@ -39,7 +40,7 @@ fn xmain() -> ! {
|
||||||
rkyv::Archived::<api::Opcode>::Input(rkyv_s) => {
|
rkyv::Archived::<api::Opcode>::Input(rkyv_s) => {
|
||||||
let s: xous::String<4096> = rkyv_s.unarchive();
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
||||||
if history.len() == history_max {
|
if history.len() == history_max {
|
||||||
history.dequeue()?;
|
history.dequeue().expect("IME_SH: couldn't dequeue history");
|
||||||
}
|
}
|
||||||
history.enqueue(s).expect("IME_SH: couldn't store history");
|
history.enqueue(s).expect("IME_SH: couldn't store history");
|
||||||
},
|
},
|
||||||
|
|
@ -47,9 +48,9 @@ fn xmain() -> ! {
|
||||||
let s: xous::String<4096> = rkyv_s.unarchive();
|
let s: xous::String<4096> = rkyv_s.unarchive();
|
||||||
if debug1{info!("Received prediction feedback but ignored: {}", s);}
|
if debug1{info!("Received prediction feedback but ignored: {}", s);}
|
||||||
},
|
},
|
||||||
_ => panic!("IME_SH: invalid response from server -- corruption occurred in MemoryMessage")
|
_ => error!("IME_SH: unknown Borrow message")
|
||||||
};
|
};
|
||||||
} else if let xous::Message::MutableBorrow(m) = &msg.body {
|
} else if let xous::Message::MutableBorrow(m) = &envelope.body {
|
||||||
let mut buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
let mut buf = unsafe { xous::XousBuffer::from_memory_message(m) };
|
||||||
let value = unsafe {
|
let value = unsafe {
|
||||||
archived_value_mut::<api::Opcode>(Pin::new(buf.as_mut()), m.id as usize)
|
archived_value_mut::<api::Opcode>(Pin::new(buf.as_mut()), m.id as usize)
|
||||||
|
|
@ -59,28 +60,29 @@ fn xmain() -> ! {
|
||||||
let mut prediction: api::Prediction = pred_r.unarchive();
|
let mut prediction: api::Prediction = pred_r.unarchive();
|
||||||
if history.len() > 0 {
|
if history.len() > 0 {
|
||||||
let mut index = prediction.index;
|
let mut index = prediction.index;
|
||||||
if index >= history.len() {
|
if index >= history.len() as u32 {
|
||||||
index = history.len() - 1;
|
index = history.len() as u32 - 1;
|
||||||
}
|
}
|
||||||
let mut i = history_len();
|
let mut i = history.len() as u32;
|
||||||
let mut retstr = xous::String::new();
|
let mut retstr = xous::String::new();
|
||||||
for s in history.iter() {
|
for &s in history.iter() {
|
||||||
// iterator is from oldest to newest, so do some math to go from newest to oldest
|
// iterator is from oldest to newest, so do some math to go from newest to oldest
|
||||||
if (history.len() - i) == index {
|
if (history.len() as u32 - i) == index {
|
||||||
retstr = s;
|
retstr = s;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i = i + 1;
|
i = i + 1;
|
||||||
}
|
}
|
||||||
prediction.string = s;
|
prediction.string = retstr;
|
||||||
} else { // there is no history
|
} else { // there is no history
|
||||||
// return the empty string
|
// return the empty string
|
||||||
prediction.string = xous::String::new();
|
prediction.string = xous::String::new();
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
|
_ => error!("IME_SH: unknown MutableBorrow message"),
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
info!("IME_SH: received unknown message type {}", envelope);
|
info!("IME_SH: received unknown message type {:?}", envelope);
|
||||||
panic!("IME_SH: received unknown message type");
|
panic!("IME_SH: received unknown message type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ fn try_main() -> Result<(), DynError> {
|
||||||
let hw_pkgs = [
|
let hw_pkgs = [
|
||||||
"gam",
|
"gam",
|
||||||
//"shell",
|
//"shell",
|
||||||
//"ime-frontend",
|
"ime-frontend",
|
||||||
//"ime-plugin-shell",
|
"ime-plugin-shell",
|
||||||
"graphics-server",
|
"graphics-server",
|
||||||
"ticktimer-server",
|
"ticktimer-server",
|
||||||
"log-server",
|
"log-server",
|
||||||
|
|
@ -192,8 +192,8 @@ fn run(debug: bool) -> Result<(), DynError> {
|
||||||
let init = [
|
let init = [
|
||||||
//"shell",
|
//"shell",
|
||||||
"gam",
|
"gam",
|
||||||
//"ime-frontend",
|
"ime-frontend",
|
||||||
//"ime-plugin-shell",
|
"ime-plugin-shell",
|
||||||
//"benchmark",
|
//"benchmark",
|
||||||
//"benchmark-target",
|
//"benchmark-target",
|
||||||
"log-server",
|
"log-server",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue