more operations; state fixes

This commit is contained in:
2025-07-18 20:31:23 +01:00
parent 5ffe1ea03c
commit f2613dd936

View File

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