fix enter for DUP showing X as 0, unify processing of commands
This commit is contained in:
parent
75de345f7c
commit
c42cdedc1b
61
src/main.c
61
src/main.c
@ -129,6 +129,7 @@ __xdata const char VER_STR[32+1] = "STC RPN Calculator v1.04";
|
|||||||
|
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
ENTERING_DONE_CLEARED,
|
||||||
ENTERING_DONE,
|
ENTERING_DONE,
|
||||||
ENTERING_SIGNIF,
|
ENTERING_SIGNIF,
|
||||||
ENTERING_FRAC,
|
ENTERING_FRAC,
|
||||||
@ -140,9 +141,12 @@ static uint8_t EnteringExp = ENTERING_DONE;
|
|||||||
static uint8_t Exp_i = 0;
|
static uint8_t Exp_i = 0;
|
||||||
static int8_t I_Key;
|
static int8_t I_Key;
|
||||||
|
|
||||||
|
static inline uint8_t is_entering_done(void){
|
||||||
|
return EnteringExp <= ENTERING_DONE;
|
||||||
|
}
|
||||||
|
|
||||||
static void entering_done(void){
|
static void entering_done(void){
|
||||||
//reset state as initial ENTERING_DONE state
|
//reset pointers
|
||||||
EnteringExp = ENTERING_DONE;
|
|
||||||
Entry_i = 0;
|
Entry_i = 0;
|
||||||
Exp_i = 0;
|
Exp_i = 0;
|
||||||
ExpBuf[0] = 0;
|
ExpBuf[0] = 0;
|
||||||
@ -150,18 +154,21 @@ static void entering_done(void){
|
|||||||
}
|
}
|
||||||
|
|
||||||
static inline void finish_process_entry(void){
|
static inline void finish_process_entry(void){
|
||||||
//finish entry
|
if (!is_entering_done()){
|
||||||
int8_t exponent; //exponent is only 2 digits
|
//finish entry
|
||||||
exponent = 10*ExpBuf[1] + ExpBuf[0];
|
int8_t exponent; //exponent is only 2 digits
|
||||||
if ( EnteringExp == ENTERING_EXP_NEG){
|
exponent = 10*ExpBuf[1] + ExpBuf[0];
|
||||||
exponent = -exponent;
|
if ( EnteringExp == ENTERING_EXP_NEG){
|
||||||
|
exponent = -exponent;
|
||||||
|
}
|
||||||
|
EntryBuf[Entry_i] = '\0';
|
||||||
|
//reset to done
|
||||||
|
entering_done();
|
||||||
}
|
}
|
||||||
EntryBuf[Entry_i] = '\0';
|
|
||||||
//process cmd
|
//process cmd
|
||||||
push_decn(EntryBuf, exponent);
|
push_decn(EntryBuf, exponent);
|
||||||
process_cmd(KEY_MAP[I_Key]);
|
process_cmd(KEY_MAP[I_Key]);
|
||||||
//reset to done
|
EnteringExp = ENTERING_DONE;
|
||||||
entering_done();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DESKTOP
|
#ifdef DESKTOP
|
||||||
@ -284,7 +291,7 @@ int main()
|
|||||||
Exp_i = 1;
|
Exp_i = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( EnteringExp == ENTERING_DONE){
|
} else if (is_entering_done()){
|
||||||
EnteringExp = ENTERING_SIGNIF;
|
EnteringExp = ENTERING_SIGNIF;
|
||||||
EntryBuf[Entry_i] = KEY_MAP[I_Key];
|
EntryBuf[Entry_i] = KEY_MAP[I_Key];
|
||||||
//do not increment entry_i from 0, until first non-0 entry
|
//do not increment entry_i from 0, until first non-0 entry
|
||||||
@ -304,12 +311,7 @@ int main()
|
|||||||
case '8': //fallthrough
|
case '8': //fallthrough
|
||||||
case '9': {
|
case '9': {
|
||||||
if (IsShifted){
|
if (IsShifted){
|
||||||
if ( EnteringExp != ENTERING_DONE){
|
finish_process_entry();
|
||||||
finish_process_entry();
|
|
||||||
} else {
|
|
||||||
//process key
|
|
||||||
process_cmd(KEY_MAP[I_Key]);
|
|
||||||
}
|
|
||||||
NoLift = 0;
|
NoLift = 0;
|
||||||
} else if ( EnteringExp >= ENTERING_EXP){
|
} else if ( EnteringExp >= ENTERING_EXP){
|
||||||
if ( Exp_i == 0){
|
if ( Exp_i == 0){
|
||||||
@ -323,7 +325,7 @@ int main()
|
|||||||
Exp_i = 1;
|
Exp_i = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ( EnteringExp == ENTERING_DONE){
|
} else if (is_entering_done()){
|
||||||
EnteringExp = ENTERING_SIGNIF;
|
EnteringExp = ENTERING_SIGNIF;
|
||||||
EntryBuf[Entry_i] = KEY_MAP[I_Key];
|
EntryBuf[Entry_i] = KEY_MAP[I_Key];
|
||||||
Entry_i++;
|
Entry_i++;
|
||||||
@ -334,7 +336,7 @@ int main()
|
|||||||
} break;
|
} break;
|
||||||
//////////
|
//////////
|
||||||
case '.': {
|
case '.': {
|
||||||
if ( EnteringExp == ENTERING_DONE){
|
if (is_entering_done()){
|
||||||
EntryBuf[Entry_i++] = '0';
|
EntryBuf[Entry_i++] = '0';
|
||||||
EntryBuf[Entry_i++] = '.';
|
EntryBuf[Entry_i++] = '.';
|
||||||
EnteringExp = ENTERING_FRAC;
|
EnteringExp = ENTERING_FRAC;
|
||||||
@ -353,21 +355,17 @@ int main()
|
|||||||
//////////
|
//////////
|
||||||
case '=': {
|
case '=': {
|
||||||
//track stack lift
|
//track stack lift
|
||||||
if ( EnteringExp != ENTERING_DONE){
|
finish_process_entry();
|
||||||
finish_process_entry();
|
|
||||||
} else {
|
|
||||||
//dup
|
|
||||||
process_cmd(KEY_MAP[I_Key]);
|
|
||||||
}
|
|
||||||
NoLift = 1;
|
NoLift = 1;
|
||||||
} break;
|
} break;
|
||||||
//////////
|
//////////
|
||||||
case 'c': {
|
case 'c': {
|
||||||
if (IsShifted || EnteringExp == ENTERING_DONE){
|
if (IsShifted || is_entering_done()){
|
||||||
//clear
|
//clear
|
||||||
IsShifted = 0;
|
IsShifted = 0;
|
||||||
NoLift = 1;
|
NoLift = 1;
|
||||||
entering_done();
|
entering_done();
|
||||||
|
EnteringExp = ENTERING_DONE_CLEARED;
|
||||||
//do not increment entry_i from 0, until first non-0 entry
|
//do not increment entry_i from 0, until first non-0 entry
|
||||||
} else if ( EnteringExp >= ENTERING_EXP){
|
} else if ( EnteringExp >= ENTERING_EXP){
|
||||||
//go back to digit entry
|
//go back to digit entry
|
||||||
@ -390,12 +388,7 @@ int main()
|
|||||||
case '/': //fallthrough
|
case '/': //fallthrough
|
||||||
case '<': //fallthrough //use as +/-
|
case '<': //fallthrough //use as +/-
|
||||||
case 'r': { //use as swap
|
case 'r': { //use as swap
|
||||||
if ( EnteringExp != ENTERING_DONE){
|
finish_process_entry();
|
||||||
finish_process_entry();
|
|
||||||
} else {
|
|
||||||
//process key
|
|
||||||
process_cmd(KEY_MAP[I_Key]);
|
|
||||||
}
|
|
||||||
NoLift = 0;
|
NoLift = 0;
|
||||||
} break;
|
} break;
|
||||||
//////////
|
//////////
|
||||||
@ -410,7 +403,7 @@ int main()
|
|||||||
|
|
||||||
LCD_GoTo(0,0);
|
LCD_GoTo(0,0);
|
||||||
//display y register on first line
|
//display y register on first line
|
||||||
if ( EnteringExp == ENTERING_DONE){
|
if (is_entering_done()){
|
||||||
disp_exponent = decn_to_str(get_y());
|
disp_exponent = decn_to_str(get_y());
|
||||||
} else {
|
} else {
|
||||||
//display x on 1st line, entered number on 2nd line
|
//display x on 1st line, entered number on 2nd line
|
||||||
@ -437,7 +430,7 @@ int main()
|
|||||||
printf("entry_i=%d,exp_i=%d\n", Entry_i, Exp_i );
|
printf("entry_i=%d,exp_i=%d\n", Entry_i, Exp_i );
|
||||||
print_entry_bufs();
|
print_entry_bufs();
|
||||||
#endif
|
#endif
|
||||||
if ( EnteringExp == ENTERING_DONE && !NoLift){
|
if ( EnteringExp == ENTERING_DONE){ //does not cover cleared case
|
||||||
disp_exponent = decn_to_str(get_x());
|
disp_exponent = decn_to_str(get_x());
|
||||||
if (disp_exponent == 0){
|
if (disp_exponent == 0){
|
||||||
LCD_OutString(Buf, MAX_CHARS_PER_LINE);
|
LCD_OutString(Buf, MAX_CHARS_PER_LINE);
|
||||||
|
Loading…
Reference in New Issue
Block a user