2021-03-25 15:39:35 +00:00
|
|
|
#![cfg_attr(target_os = "none", no_std)]
|
|
|
|
|
#![cfg_attr(target_os = "none", no_main)]
|
|
|
|
|
|
2021-03-26 04:33:30 +00:00
|
|
|
use core::fmt::Write;
|
|
|
|
|
|
2021-03-25 15:39:35 +00:00
|
|
|
fn print_log_messages(log_message: &str, prefix: &str) {
|
2021-03-26 04:16:26 +00:00
|
|
|
log::info!(
|
|
|
|
|
"Got a message hook! Message: [{}], prefix: [{}]",
|
|
|
|
|
log_message,
|
|
|
|
|
prefix
|
|
|
|
|
);
|
2021-03-25 15:39:35 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-02 08:40:17 +00:00
|
|
|
fn handle_battstats(bs: com::BattStats) {
|
|
|
|
|
log::info!("battstats: {:?}", bs);
|
2021-04-02 09:58:03 +00:00
|
|
|
// note: at this point to repatriate data into the core main loop, you have two options:
|
|
|
|
|
// 1. send a new message to the server, using your own private API. This feels "wasteful"
|
|
|
|
|
// as you're bouncing a message twice but it keeps the API spaces strictly on crate boundaries
|
|
|
|
|
// 2. use an Atomic type to transfer primitive data types from the handler thread to the main thread
|
2021-04-02 08:40:17 +00:00
|
|
|
}
|
|
|
|
|
|
2021-04-03 18:15:46 +00:00
|
|
|
fn handle_keyevents(keys: [char; 4]) {
|
|
|
|
|
for &k in keys.iter() {
|
|
|
|
|
if k != '\u{0000}' {
|
|
|
|
|
log::info!("KEYEVENT: {}", k);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 15:39:35 +00:00
|
|
|
#[xous::xous_main]
|
|
|
|
|
fn rkyv_test_client() -> ! {
|
|
|
|
|
log_server::init_wait().unwrap();
|
|
|
|
|
log::info!(
|
|
|
|
|
"Hello, world! This is the client, PID {}",
|
|
|
|
|
xous::current_pid().unwrap().get()
|
|
|
|
|
);
|
2021-03-28 10:14:41 +00:00
|
|
|
let ticktimer = ticktimer_server::Ticktimer::new().expect("couldn't create ticktimer object");
|
2021-03-25 15:39:35 +00:00
|
|
|
|
|
|
|
|
rkyv_test_server::hook_log_messages(print_log_messages);
|
|
|
|
|
|
|
|
|
|
let mut idx = 0;
|
2021-03-26 04:40:47 +00:00
|
|
|
|
|
|
|
|
// This is just some number. It should change width, ensuring our padding
|
|
|
|
|
// is working and we're not overwriting the buffer weirdly.
|
|
|
|
|
let mut some_number = 98653i32;
|
|
|
|
|
let mut double_src = xous::String::<256>::new();
|
2021-03-26 04:33:30 +00:00
|
|
|
|
|
|
|
|
let mut message_string = xous::String::<64>::new();
|
2021-04-02 08:40:17 +00:00
|
|
|
|
|
|
|
|
let xns = xous_names::XousNames::new().unwrap();
|
2021-04-05 15:50:00 +00:00
|
|
|
|
2021-04-29 15:15:47 +00:00
|
|
|
let mut susres = susres::Susres::new_without_hook(&xns).unwrap();
|
2021-04-29 08:37:43 +00:00
|
|
|
let mut com = com::Com::new(&xns).unwrap();
|
2021-04-02 10:07:39 +00:00
|
|
|
com.hook_batt_stats(handle_battstats).unwrap();
|
2021-04-29 08:37:43 +00:00
|
|
|
/*
|
2021-04-03 18:15:46 +00:00
|
|
|
let mut kbd = keyboard::Keyboard::new(&xns).unwrap();
|
2021-04-05 17:52:26 +00:00
|
|
|
kbd.hook_keyboard_events(handle_keyevents).unwrap();*/
|
2021-03-25 15:39:35 +00:00
|
|
|
loop {
|
|
|
|
|
log::info!("2 + {} = {}", idx, rkyv_test_server::add(2, idx).unwrap());
|
2021-04-04 10:23:26 +00:00
|
|
|
ticktimer.sleep_ms(3000).ok();
|
2021-03-26 04:33:30 +00:00
|
|
|
|
|
|
|
|
message_string.clear();
|
2021-08-19 15:33:23 +00:00
|
|
|
write!(
|
|
|
|
|
message_string,
|
|
|
|
|
"I'm at loop # {:^4} (some numer: {})",
|
|
|
|
|
idx, some_number
|
|
|
|
|
)
|
|
|
|
|
.unwrap();
|
2021-03-26 04:40:47 +00:00
|
|
|
some_number = some_number.wrapping_mul(53);
|
2021-03-26 04:33:30 +00:00
|
|
|
rkyv_test_server::log_message("prefix", message_string);
|
2021-03-26 04:40:47 +00:00
|
|
|
|
|
|
|
|
double_src.clear();
|
|
|
|
|
write!(double_src, "12345678 Loop {} 🎉 你好", idx).unwrap();
|
2021-03-26 04:16:26 +00:00
|
|
|
log::info!("Doubling string {}", double_src);
|
2021-08-19 15:33:23 +00:00
|
|
|
log::info!(
|
|
|
|
|
"Doubled string: {}",
|
|
|
|
|
rkyv_test_server::double_string(&double_src)
|
|
|
|
|
);
|
2021-03-26 09:17:03 +00:00
|
|
|
|
|
|
|
|
let sent_str = xous::String::<32>::from_str("This got moved");
|
|
|
|
|
log::info!("Sending a string \"{}\"", sent_str);
|
|
|
|
|
rkyv_test_server::log_message("prefix", sent_str);
|
|
|
|
|
|
2021-08-19 15:33:23 +00:00
|
|
|
if (idx % 2) == 0 {
|
2021-04-30 18:26:28 +00:00
|
|
|
com.req_batt_stats().unwrap();
|
|
|
|
|
}
|
2021-04-02 08:40:17 +00:00
|
|
|
|
2021-04-28 18:56:53 +00:00
|
|
|
// let the loop run a bit, then try a suspend
|
2021-05-01 12:56:12 +00:00
|
|
|
if idx == 3 {
|
2021-04-28 18:56:53 +00:00
|
|
|
// TODO: add a self-wakeup RTC alarm once we're beyond the touch-and-go phase
|
|
|
|
|
susres.initiate_suspend().unwrap();
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-25 15:39:35 +00:00
|
|
|
idx += 1;
|
|
|
|
|
}
|
|
|
|
|
}
|