Implement the prev button

main
kirbylife 2023-04-27 23:34:55 -06:00
parent 298117ee90
commit 8705519c0b
2 changed files with 11 additions and 2 deletions

View File

@ -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 {

View File

@ -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), ()> {