mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-08 04:56:43 +00:00
fixups and debug
This commit is contained in:
parent
8553aea95e
commit
116015dff8
6 changed files with 69 additions and 7 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
|
@ -1949,7 +1949,6 @@ name = "modals"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bit_field 0.9.0",
|
||||
"dither",
|
||||
"fast_image_resize",
|
||||
"gam",
|
||||
"image",
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ qrcode = { version = "0.12", default-features = false }
|
|||
#dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28
|
||||
dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
|
||||
# note: image version is matched to version used by dither
|
||||
image = { version = "0.23", default-features = false, features = ["jpeg", "png"], optional = true }
|
||||
image = { version = "0.23", default-features = false, features = ["png"], optional = true }
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
utralib = {path = "../../utralib"}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ impl Tile {
|
|||
pub fn get_word(&self, point: Point) -> Word {
|
||||
self.words[self.word_index(point)]
|
||||
}
|
||||
|
||||
|
||||
pub fn set_word(&mut self, point: Point, word: Word) {
|
||||
self.words[self.word_index(point)] = word;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ locales = {path = "../../locales"}
|
|||
bit_field = "0.9.0"
|
||||
|
||||
#dither = "1.3.10" pending https://gitlab.com/efronlicht/dither/-/merge_requests/28
|
||||
dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
|
||||
#dither = { git = "https://gitlab.com/nworbnhoj/dither", default-features = false, optional = true }
|
||||
# note: image version is matched to version used by dither
|
||||
image = { version = "0.23", default-features = false, features = ["jpeg", "png"], optional = true }
|
||||
image = { version = "0.23", default-features = false, features = ["png"], optional = true }
|
||||
fast_image_resize = {version = "0.9.2", optional = true}
|
||||
|
||||
[target.'cfg(not(any(windows,unix)))'.dependencies]
|
||||
|
|
@ -33,5 +33,5 @@ utralib = { path = "../../utralib"}
|
|||
|
||||
[features]
|
||||
tts = []
|
||||
ditherpunk = ["image", "dither", "fast_image_resize"]
|
||||
ditherpunk = ["image", "fast_image_resize"]
|
||||
default = []
|
||||
|
|
|
|||
|
|
@ -449,7 +449,7 @@ fn xmain() -> ! {
|
|||
let mut image = gam::modal::Image::new(
|
||||
renderer_cid,
|
||||
Opcode::ImageReturn.to_u32().unwrap(),
|
||||
);
|
||||
);
|
||||
image.set_bitmap(Some(Bitmap::from(config.tiles)));
|
||||
renderer_modal.modify(
|
||||
Some(ActionType::Image(image)),
|
||||
|
|
|
|||
|
|
@ -283,6 +283,63 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
|
|||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature="ditherpunk")]
|
||||
"image" => {
|
||||
const MAX_IMAGE_LEN: usize = 256 * 1024; // includes HTTP headers
|
||||
if let Some(url) = tokens.next() {
|
||||
match url.split_once('/') {
|
||||
Some((host, path)) => {
|
||||
match TcpStream::connect((host, 80)) {
|
||||
Ok(mut stream) => {
|
||||
let mut heap_image = match xous::syscall::map_memory(
|
||||
None,
|
||||
None,
|
||||
MAX_IMAGE_LEN,
|
||||
xous::MemoryFlags::R | xous::MemoryFlags::W,
|
||||
) {
|
||||
Ok(d) => d,
|
||||
Err(e) => {
|
||||
log::error!("couldn't allocate data for image, aborting");
|
||||
write!(ret, "Couldn't allocate memory for image, aborting: {:?}", e).unwrap();
|
||||
return Ok(Some(ret));
|
||||
}
|
||||
};
|
||||
stream.set_read_timeout(Some(Duration::from_millis(10_000))).unwrap();
|
||||
stream.set_write_timeout(Some(Duration::from_millis(10_000))).unwrap();
|
||||
match write!(stream, "GET /{} HTTP/1.1\r\n", path) {
|
||||
Ok(_) => log::trace!("sent GET"),
|
||||
Err(e) => {
|
||||
log::error!("GET err {:?}", e);
|
||||
write!(ret, "Error sending GET: {:?}", e).unwrap();
|
||||
}
|
||||
}
|
||||
write!(stream, "Host: {}\r\nAccept: */*\r\nUser-Agent: Precursor/0.9.6\r\n", host).expect("stream error");
|
||||
write!(stream, "Connection: close\r\n").expect("stream error");
|
||||
write!(stream, "\r\n").expect("stream error");
|
||||
log::info!("fetching response....");
|
||||
match stream.read(heap_image.as_slice_mut()) {
|
||||
Ok(len) => {
|
||||
log::info!("fetched {} bytes of http data", len);
|
||||
}
|
||||
Err(e) => write!(ret, "Didn't get response from host: {:?}", e).unwrap(),
|
||||
}
|
||||
if let Some(start) = find_subsequence(
|
||||
heap_image.as_slice::<u8>(),
|
||||
&[0x0d, 0x0a, 0x0d, 0x0a], // this is \r\n\r\n, which indicates end of header.
|
||||
) {
|
||||
log::info!("image data is {} bytes long", heap_image.len() - start);
|
||||
}
|
||||
xous::syscall::unmap_memory(heap_image).expect("couldn't de-allocate image memory");
|
||||
}
|
||||
Err(e) => write!(ret, "Couldn't connect to {}:80: {:?}", host, e).unwrap(),
|
||||
}
|
||||
}
|
||||
_ => write!(ret, "Usage: image bunniefoo.com/bunnie/bunny.png").unwrap(),
|
||||
}
|
||||
} else {
|
||||
write!(ret, "Usage: image bunniefoo.com/bunnie/bunny.png").unwrap();
|
||||
}
|
||||
}
|
||||
"tls" => {
|
||||
write!(ret, "Work in progress. Please check back later!").unwrap();
|
||||
}
|
||||
|
|
@ -417,6 +474,12 @@ impl<'a> ShellCmdApi<'a> for NetCmd {
|
|||
}
|
||||
}
|
||||
|
||||
// yep. this is from stackoverflow copypasta
|
||||
#[cfg(feature="ditherpunk")]
|
||||
fn find_subsequence(haystack: &[u8], needle: &[u8]) -> Option<usize> {
|
||||
haystack.windows(needle.len()).position(|window| window == needle)
|
||||
}
|
||||
|
||||
enum Responses {
|
||||
Uptime,
|
||||
NotFound,
|
||||
|
|
|
|||
Loading…
Reference in a new issue