-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathmod.rs
More file actions
86 lines (79 loc) · 2.04 KB
/
mod.rs
File metadata and controls
86 lines (79 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! Commands for Neotron OS
//!
//! Defines the top-level menu, and the commands it can call.
pub use super::Ctx;
mod block;
mod config;
mod fs;
mod hardware;
mod input;
mod ram;
mod screen;
mod sound;
mod timedate;
pub static OS_MENU: menu::Menu<Ctx> = menu::Menu {
label: "root",
items: &[
&timedate::DATE_ITEM,
&config::COMMAND_ITEM,
&hardware::LSBLK_ITEM,
&hardware::LSBUS_ITEM,
&hardware::LSI2C_ITEM,
&hardware::LSMEM_ITEM,
&hardware::LSUART_ITEM,
&hardware::I2C_ITEM,
&block::READ_ITEM,
&fs::DIR_ITEM,
&ram::HEXDUMP_ITEM,
&ram::RUN_ITEM,
&fs::LOAD_ITEM,
&fs::EXEC_ITEM,
&fs::TYPE_ITEM,
&fs::ROM_ITEM,
&screen::CLS_ITEM,
&screen::MODE_ITEM,
&input::KBTEST_ITEM,
&hardware::SHUTDOWN_ITEM,
&sound::MIXER_ITEM,
&sound::PLAY_ITEM,
],
entry: None,
exit: None,
};
/// Parse a string into a `usize`
///
/// Numbers like `0x123` are hex. Numbers like `123` are decimal.
fn parse_usize(input: &str) -> Result<usize, core::num::ParseIntError> {
if let Some(digits) = input.strip_prefix("0x") {
// Parse as hex
usize::from_str_radix(digits, 16)
} else {
// Parse as decimal
input.parse::<usize>()
}
}
/// Parse a string into a `u8`
///
/// Numbers like `0x123` are hex. Numbers like `123` are decimal.
fn parse_u8(input: &str) -> Result<u8, core::num::ParseIntError> {
if let Some(digits) = input.strip_prefix("0x") {
// Parse as hex
u8::from_str_radix(digits, 16)
} else {
// Parse as decimal
input.parse::<u8>()
}
}
/// Parse a string into a `u64`
///
/// Numbers like `0x123` are hex. Numbers like `123` are decimal.
fn parse_u64(input: &str) -> Result<u64, core::num::ParseIntError> {
if let Some(digits) = input.strip_prefix("0x") {
// Parse as hex
u64::from_str_radix(digits, 16)
} else {
// Parse as decimal
input.parse::<u64>()
}
}
// End of file