From f2613dd93690231cfae5d7b79a9c6da90cdd82f2 Mon Sep 17 00:00:00 2001 From: Hexa Dust Date: Fri, 18 Jul 2025 20:31:23 +0100 Subject: [PATCH] more operations; state fixes --- src/main.rs | 54 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7b092cd..a8a0173 100644 --- a/src/main.rs +++ b/src/main.rs @@ -602,7 +602,11 @@ fn main() -> ! { ufmt::uwriteln!(&mut serial, "key: {:?} state: {:?}", key, state).unwrap_infallible(); let res = match state { State::EnterSignificant => match key { - InputKey::C => Ok(number_input.reset()), + InputKey::C => { + number_input.reset(); + calc.reset(); + Ok(()) + } InputKey::Num(val) => number_input.input(val), InputKey::Minus => Ok(number_input.toggle_minus()), InputKey::E => { @@ -615,6 +619,7 @@ fn main() -> ! { State::EnterExponent => match key { InputKey::C => { number_input.reset(); + calc.reset(); state = State::EnterSignificant; Ok(()) } @@ -625,13 +630,15 @@ fn main() -> ! { match calc.push(number_input.to_decimal()) { Ok(()) => { number_input.reset(); - state = State::EnterSignificant; - } - Err(_) => { - state = State::EnterOperation; + state = if calc.is_full() { + State::EnterOperation + } else { + State::EnterSignificant + }; + Ok(()) } + Err(_) => Err(()), } - Ok(()) } _ => Ok(()), }, @@ -639,26 +646,50 @@ fn main() -> ! { InputKey::Up => todo!(), InputKey::C => { number_input.reset(); + calc.reset(); state = State::EnterSignificant; Ok(()) } InputKey::Num(_) => todo!(), - InputKey::Mul => todo!(), - InputKey::Div => todo!(), - InputKey::Plus => match calc.add() { + InputKey::Mul => match calc.mul() { Ok(dec) => { number_input.set_decimal(dec); + state = State::EnterSignificant; + Ok(()) + } + Err(_) => Err(()), + }, + InputKey::Div => match calc.div() { + Ok(dec) => { + number_input.set_decimal(dec); + state = State::EnterSignificant; + Ok(()) + } + Err(_) => Err(()), + }, + InputKey::Plus => match calc.add() { + Ok(dec) => { + number_input.set_decimal(dec); + state = State::EnterSignificant; + Ok(()) + } + Err(_) => Err(()), + }, + InputKey::Minus => match calc.sub() { + Ok(dec) => { + number_input.set_decimal(dec); + state = State::EnterSignificant; Ok(()) } Err(_) => Err(()), }, - InputKey::Minus => todo!(), InputKey::Down => todo!(), InputKey::E => todo!(), }, State::Err => match key { InputKey::C => { number_input.reset(); + calc.reset(); state = State::EnterSignificant; Ok(()) } @@ -669,7 +700,8 @@ fn main() -> ! { state = State::Err } - ufmt::uwriteln!(&mut serial, "state: {:?}", state).unwrap_infallible(); + ufmt::uwriteln!(&mut serial, "state: {:?} stack: {}", state, calc.len()) + .unwrap_infallible(); match state { State::EnterSignificant | State::EnterExponent | State::EnterOperation => { number_input.show(&mut display)