Merge remote-tracking branch 'fork/add_simple_calculator_face' into add_simple_calculator_face

This commit is contained in:
mcguirepr89 2024-08-31 17:51:01 -04:00
commit 20946e88f4
2 changed files with 17 additions and 11 deletions

View File

@ -115,7 +115,7 @@ static void set_operation(simple_calculator_state_t *state) {
static void cycle_operation(simple_calculator_state_t *state) { static void cycle_operation(simple_calculator_state_t *state) {
state->operation = (state->operation + 1) % OPERATIONS_COUNT; // Assuming there are 6 operations state->operation = (state->operation + 1) % OPERATIONS_COUNT; // Assuming there are 6 operations
printf("Current operation: %d\n", state->operation); // For debugging //printf("Current operation: %d\n", state->operation); // For debugging
} }
@ -131,9 +131,9 @@ static calculator_number_t convert_to_string(float number) {
int int_part = (int)number; int int_part = (int)number;
float decimal_part_float = ((number - int_part) * 100); // two decimal places float decimal_part_float = ((number - int_part) * 100); // two decimal places
printf("decimal_part_float = %f\n", decimal_part_float); //For debugging //printf("decimal_part_float = %f\n", decimal_part_float); //For debugging
int decimal_part = round(decimal_part_float); int decimal_part = round(decimal_part_float);
printf("decimal_part = %d\n", decimal_part); //For debugging //printf("decimal_part = %d\n", decimal_part); //For debugging
result.thousands = int_part / 1000 % 10; result.thousands = int_part / 1000 % 10;
result.hundreds = int_part / 100 % 10; result.hundreds = int_part / 100 % 10;
@ -183,10 +183,10 @@ static void view_results(simple_calculator_state_t *state, char *display_string)
// Convert the numbers to float // Convert the numbers to float
first_num_float = convert_to_float(state->first_num); first_num_float = convert_to_float(state->first_num);
if (state->first_num.negative) first_num_float = first_num_float * -1; if (state->first_num.negative) first_num_float = first_num_float * -1;
printf("first_num_float = %f\n", first_num_float); // For debugging // For debugging //printf("first_num_float = %f\n", first_num_float); // For debugging // For debugging
second_num_float = convert_to_float(state->second_num); second_num_float = convert_to_float(state->second_num);
if (state->second_num.negative) second_num_float = second_num_float * -1; if (state->second_num.negative) second_num_float = second_num_float * -1;
printf("second_num_float = %f\n", second_num_float); // For debugging //printf("second_num_float = %f\n", second_num_float); // For debugging
// Perform the calculation based on the selected operation // Perform the calculation based on the selected operation
switch (state->operation) { switch (state->operation) {
@ -229,7 +229,7 @@ static void view_results(simple_calculator_state_t *state, char *display_string)
} }
result_float = roundf(result_float * 100.0f) / 100.0f; // Might not be needed result_float = roundf(result_float * 100.0f) / 100.0f; // Might not be needed
printf("result as float = %f\n", result_float); // For debugging //printf("result as float = %f\n", result_float); // For debugging
// Convert the float result to a string // Convert the float result to a string
state->result = convert_to_string(result_float); state->result = convert_to_string(result_float);
@ -341,7 +341,7 @@ bool simple_calculator_face_loop(movement_event_t event, movement_settings_t *se
break; break;
case MODE_CHOOSING: case MODE_CHOOSING:
// Confirm and select the current operation // Confirm and select the current operation
printf("Selected operation: %d\n", state->operation); // For debugging //printf("Selected operation: %d\n", state->operation); // For debugging
state->mode = MODE_ENTERING_SECOND_NUM; state->mode = MODE_ENTERING_SECOND_NUM;
break; break;
case MODE_ENTERING_SECOND_NUM: case MODE_ENTERING_SECOND_NUM:
@ -380,6 +380,14 @@ bool simple_calculator_face_loop(movement_event_t event, movement_settings_t *se
case EVENT_MODE_BUTTON_UP: case EVENT_MODE_BUTTON_UP:
if (state->mode == MODE_ERROR) { if (state->mode == MODE_ERROR) {
reset_from_error(state); reset_from_error(state);
} else if (state->mode == MODE_ENTERING_FIRST_NUM &&
state->first_num.hundredths == 0 &&
state->first_num.tenths == 0 &&
state->first_num.ones== 0 &&
state->first_num.tens == 0 &&
state->first_num.hundreds == 0 &&
state->first_num.thousands == 0) {
movement_move_to_next_face();
} else { } else {
state->placeholder = PLACEHOLDER_ONES; state->placeholder = PLACEHOLDER_ONES;
state->mode = (state->mode + 1) % 4; state->mode = (state->mode + 1) % 4;
@ -387,12 +395,12 @@ bool simple_calculator_face_loop(movement_event_t event, movement_settings_t *se
state->first_num = state->result; state->first_num = state->result;
reset_to_zero(&state->second_num); reset_to_zero(&state->second_num);
} }
printf("Current mode: %d\n", state->mode); // For debugging //printf("Current mode: %d\n", state->mode); // For debugging
} }
break; break;
case EVENT_MODE_LONG_PRESS: case EVENT_MODE_LONG_PRESS:
movement_move_to_next_face(); movement_move_to_face(0);
break; break;
case EVENT_TIMEOUT: case EVENT_TIMEOUT:

View File

@ -32,8 +32,6 @@
* *
* How to use: * How to use:
* *
* Important note: LONG PRESS MODE to move to next watch face
*
* Flow: * Flow:
* Enter first number -> Select operator -> Enter second number -> View Results * Enter first number -> Select operator -> Enter second number -> View Results
* *