more operations; state fixes
This commit is contained in:
54
src/main.rs
54
src/main.rs
@@ -602,7 +602,11 @@ fn main() -> ! {
|
|||||||
ufmt::uwriteln!(&mut serial, "key: {:?} state: {:?}", key, state).unwrap_infallible();
|
ufmt::uwriteln!(&mut serial, "key: {:?} state: {:?}", key, state).unwrap_infallible();
|
||||||
let res = match state {
|
let res = match state {
|
||||||
State::EnterSignificant => match key {
|
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::Num(val) => number_input.input(val),
|
||||||
InputKey::Minus => Ok(number_input.toggle_minus()),
|
InputKey::Minus => Ok(number_input.toggle_minus()),
|
||||||
InputKey::E => {
|
InputKey::E => {
|
||||||
@@ -615,6 +619,7 @@ fn main() -> ! {
|
|||||||
State::EnterExponent => match key {
|
State::EnterExponent => match key {
|
||||||
InputKey::C => {
|
InputKey::C => {
|
||||||
number_input.reset();
|
number_input.reset();
|
||||||
|
calc.reset();
|
||||||
state = State::EnterSignificant;
|
state = State::EnterSignificant;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -625,13 +630,15 @@ fn main() -> ! {
|
|||||||
match calc.push(number_input.to_decimal()) {
|
match calc.push(number_input.to_decimal()) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
number_input.reset();
|
number_input.reset();
|
||||||
state = State::EnterSignificant;
|
state = if calc.is_full() {
|
||||||
}
|
State::EnterOperation
|
||||||
Err(_) => {
|
} else {
|
||||||
state = State::EnterOperation;
|
State::EnterSignificant
|
||||||
|
};
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Err(_) => Err(()),
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
_ => Ok(()),
|
_ => Ok(()),
|
||||||
},
|
},
|
||||||
@@ -639,26 +646,50 @@ fn main() -> ! {
|
|||||||
InputKey::Up => todo!(),
|
InputKey::Up => todo!(),
|
||||||
InputKey::C => {
|
InputKey::C => {
|
||||||
number_input.reset();
|
number_input.reset();
|
||||||
|
calc.reset();
|
||||||
state = State::EnterSignificant;
|
state = State::EnterSignificant;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
InputKey::Num(_) => todo!(),
|
InputKey::Num(_) => todo!(),
|
||||||
InputKey::Mul => todo!(),
|
InputKey::Mul => match calc.mul() {
|
||||||
InputKey::Div => todo!(),
|
|
||||||
InputKey::Plus => match calc.add() {
|
|
||||||
Ok(dec) => {
|
Ok(dec) => {
|
||||||
number_input.set_decimal(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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
Err(_) => Err(()),
|
Err(_) => Err(()),
|
||||||
},
|
},
|
||||||
InputKey::Minus => todo!(),
|
|
||||||
InputKey::Down => todo!(),
|
InputKey::Down => todo!(),
|
||||||
InputKey::E => todo!(),
|
InputKey::E => todo!(),
|
||||||
},
|
},
|
||||||
State::Err => match key {
|
State::Err => match key {
|
||||||
InputKey::C => {
|
InputKey::C => {
|
||||||
number_input.reset();
|
number_input.reset();
|
||||||
|
calc.reset();
|
||||||
state = State::EnterSignificant;
|
state = State::EnterSignificant;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -669,7 +700,8 @@ fn main() -> ! {
|
|||||||
state = State::Err
|
state = State::Err
|
||||||
}
|
}
|
||||||
|
|
||||||
ufmt::uwriteln!(&mut serial, "state: {:?}", state).unwrap_infallible();
|
ufmt::uwriteln!(&mut serial, "state: {:?} stack: {}", state, calc.len())
|
||||||
|
.unwrap_infallible();
|
||||||
match state {
|
match state {
|
||||||
State::EnterSignificant | State::EnterExponent | State::EnterOperation => {
|
State::EnterSignificant | State::EnterExponent | State::EnterOperation => {
|
||||||
number_input.show(&mut display)
|
number_input.show(&mut display)
|
||||||
|
|||||||
Reference in New Issue
Block a user