From 8705519c0ba78cd1d1b3ae3b6c782a91a700a3f7 Mon Sep 17 00:00:00 2001 From: kirbylife Date: Thu, 27 Apr 2023 23:34:55 -0600 Subject: [PATCH] Implement the prev button --- src/main.rs | 3 ++- src/storage.rs | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index a343b59..4154b0b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -150,7 +150,8 @@ fn main() -> ! { tokens.next(); } if down_button.update() == button::Event::PressUp { - todo!("To be implemented"); + changed = true; + tokens.prev(); } let curr_time = INTERVAL - (timestamp % INTERVAL); if curr_time == last_time { diff --git a/src/storage.rs b/src/storage.rs index 643c72c..4c6c810 100644 --- a/src/storage.rs +++ b/src/storage.rs @@ -59,7 +59,15 @@ impl<'a> Tokens<'a> { } pub fn prev(&mut self) -> Option { - 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), ()> {