fix bug for entering numbers such as 0.01

This commit is contained in:
Jeff Wang 2019-04-04 02:29:11 -04:00
parent cb255bc7d1
commit 8550049335
4 changed files with 24 additions and 9 deletions

View File

@ -13,10 +13,10 @@ This is a replacement firmware for the [diyleyuan calculator](http://www.diyleyu
- CMakeLists.txt is for building the Qt desktop application.
- (still a work in progress)
- build similarly to other cmake projects:
- mkdir build_qt && cd build_qt
- cmake -DCMAKE_BUILD_TYPE=Debug -G "Eclipse CDT4 - Ninja" ..
- `mkdir build_qt && cd build_qt`
- `cmake -DCMAKE_BUILD_TYPE=Debug -G "Eclipse CDT4 - Ninja" ..`
- (you can choose a different generator, I prefer using Ninja to build, because it's fast)
- ninja
- `ninja`
# Installing
The STC microcontroller used has a bootloader permanently stored in ROM that allows downloading new firmware over a serial port. You can re-program it using a USB-to-logic-level-serial (5V) dongle, and the stcgal program. WARNING: a lot of USB-to-logic-level-serial dongles are for 3.3V logic levels. The diyleyuan calculator runs at 5V to make it easier to power/drive the LCD display. You have a couple of options:
@ -112,7 +112,7 @@ The calculator uses RPN. To calculate (2+3)/(9^2), enter:
- `*`
- `÷`
The = key is used for Enter. There is automatic stack lift so that `9`, `Enter`, `*` is equivalent to 9^2.
The = key is used for Enter. There is automatic stack lift so that `9`, `Enter`, `*` is equivalent to 9^2. The stack is a classic 4-level RPN stack, where the T register duplicates.
## Keys
The keys on the original calculator map as follows:

View File

@ -8,3 +8,6 @@ target_link_libraries(calc Qt5::Widgets)
add_executable(keytest key.c)
target_compile_definitions(keytest PRIVATE KEY_TEST_APP=1)
add_executable(decn_test decn/decn_test.c utils.c)
target_link_libraries(decn_test decn)

View File

@ -191,11 +191,6 @@ void build_dec80(dec80* dest, const char* signif_str, int16_t exponent){
}
}
nibble_i++;
//track number of digits R of decimal point
//must do this before changing is_zero
if (curr_sign == SIGN_ZERO_SEEN_POINT || curr_sign == SIGN_NEG_ZERO_SEEN_POINT){
num_lr_points = -1;
}
//track sign
if (curr_sign == SIGN_ZERO){
curr_sign = SIGN_POS;

View File

@ -195,6 +195,23 @@ int main(void){
decn_to_str_complete(Buf, &diff);
printf(" : %s\n\n", Buf);
//new acc and b for divide test
build_dec80(&acc, "0.02", 0);
build_dec80(&b, "0.03", 0);
decn_to_str_complete(Buf, &acc);
printf(" acc: %s\n", Buf);
decn_to_str_complete(Buf, &b);
printf(" b: %s\n", Buf);
div_decn(&acc, &b);
decn_to_str_complete(Buf, &acc);
printf("acc/b: %s\n", Buf);
printf(" : %s\n", "0.666666666666666672");
build_dec80(&diff, "0.666666666666666672", 0);
negate_decn(&diff);
add_decn(&diff, &acc);
decn_to_str_complete(Buf, &diff);
printf(" : %s\n\n", Buf);
return 0;
}