Compare commits
2 Commits
298117ee90
...
0636253f06
Author | SHA1 | Date |
---|---|---|
kirbylife | 0636253f06 | |
kirbylife | 8705519c0b |
|
@ -150,7 +150,8 @@ fn main() -> ! {
|
||||||
tokens.next();
|
tokens.next();
|
||||||
}
|
}
|
||||||
if down_button.update() == button::Event::PressUp {
|
if down_button.update() == button::Event::PressUp {
|
||||||
todo!("To be implemented");
|
changed = true;
|
||||||
|
tokens.prev();
|
||||||
}
|
}
|
||||||
let curr_time = INTERVAL - (timestamp % INTERVAL);
|
let curr_time = INTERVAL - (timestamp % INTERVAL);
|
||||||
if curr_time == last_time {
|
if curr_time == last_time {
|
||||||
|
|
|
@ -158,37 +158,22 @@ impl<
|
||||||
self.write_str(core::str::from_utf8(&buff[..=num_len]).unwrap());
|
self.write_str(core::str::from_utf8(&buff[..=num_len]).unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_u32(&mut self, num: u32) {
|
pub fn write_u32(&mut self, mut num: u32) {
|
||||||
// This function is for debugging purposes only, it does not show
|
if num == 0 {
|
||||||
// The 0's to the right of the number
|
self.write_char('0');
|
||||||
// The max number in an u32 is: 4,294,967,295
|
return;
|
||||||
let mut buff = [0; 10];
|
}
|
||||||
let len = num_chars(num, &mut buff);
|
|
||||||
self.write_str(&core::str::from_utf8(&buff[..len]).unwrap());
|
let mut buff = [0u8; 10];
|
||||||
|
let num_len = num.ilog10() as usize;
|
||||||
|
for i in (0..=num_len).rev() {
|
||||||
|
buff[i] = (num % 10) as u8 + '0' as u8;
|
||||||
|
num /= 10;
|
||||||
|
}
|
||||||
|
self.write_str(core::str::from_utf8(&buff[..=num_len]).unwrap());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_bit(n: u8) -> bool {
|
fn last_bit(n: u8) -> bool {
|
||||||
(n & 1) != 0
|
(n & 1) != 0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn num_rev(mut num: u32) -> u32 {
|
|
||||||
let mut rev_num = 0;
|
|
||||||
while num > 0 {
|
|
||||||
let digit = num % 10;
|
|
||||||
rev_num = rev_num * 10 + digit;
|
|
||||||
num /= 10;
|
|
||||||
}
|
|
||||||
rev_num
|
|
||||||
}
|
|
||||||
|
|
||||||
fn num_chars(n: u32, output: &mut [u8]) -> usize {
|
|
||||||
let mut n = num_rev(n);
|
|
||||||
let mut i = 0;
|
|
||||||
while n > 0 {
|
|
||||||
output[i] = (n % 10) as u8 + '0' as u8;
|
|
||||||
n = n / 10;
|
|
||||||
i += 1;
|
|
||||||
}
|
|
||||||
i
|
|
||||||
}
|
|
||||||
|
|
|
@ -59,7 +59,15 @@ impl<'a> Tokens<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prev(&mut self) -> Option<u16> {
|
pub fn prev(&mut self) -> Option<u16> {
|
||||||
todo!();
|
let mut index = self.current.unwrap();
|
||||||
|
for _ in 0..self.capacity {
|
||||||
|
index = (index - 1) % self.capacity;
|
||||||
|
if self.mem.read_byte(index * SECRET_KEY_FULL_LEN) != ENDL {
|
||||||
|
self.current = Some(index);
|
||||||
|
return Some(index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&self, index: u16, name: &mut [u8], key: &mut [u8]) -> Result<(usize, usize), ()> {
|
pub fn read(&self, index: u16, name: &mut [u8], key: &mut [u8]) -> Result<(usize, usize), ()> {
|
||||||
|
|
Loading…
Reference in New Issue