@@ -96,7 +96,7 @@ static int perform_op(tricalc_op op, double a, double b, double* result) {
96
96
arity = 1 ;
97
97
break ;
98
98
default :
99
- return 0 ;
99
+ return 0 ;
100
100
}
101
101
102
102
return arity ;
@@ -110,27 +110,31 @@ static void action_commit(struct tricalc_click_context* clickcontext) {
110
110
}
111
111
if (clickcontext -> long_click ) {
112
112
tricalc_op op = get_op_for_button (clickcontext );
113
- double b = (double ) atoi (accumulator_string ); //strtod(accumulator_string, NULL);
114
- double a = 0 ;
113
+ double a = (double ) atoi (accumulator_string ); //strtod(accumulator_string, NULL);
114
+ double b = 0 ;
115
115
double result = 0 ;
116
116
int arity = 0 ;
117
117
tricalc_op_stack_entry * item = tricalc_op_stack_peek (& stack );
118
- a = item ? item -> val : b ;
118
+ b = item ? item -> val : a ;
119
+ APP_LOG (APP_LOG_LEVEL_DEBUG , "items %d" , stack .items );
119
120
120
121
arity = perform_op (op , a , b , & result );
121
122
if (arity == 2 ) {
122
123
tricalc_op_stack_pop_value (& stack , NULL );
123
124
}
125
+ APP_LOG (APP_LOG_LEVEL_DEBUG , "items2 %d" , stack .items );
124
126
125
127
if (arity != 0 ) {
126
- tricalc_op_stack_push (& stack , result , op , a , b );
128
+ if (op == OP_ENTER )
129
+ tricalc_op_stack_push (& stack , result , op , a , b );
127
130
/*XXX: Pebble snprintf doesn't support any float printing functions!*/
128
131
/*TODO: Do this properly (ugh)*/
129
132
snprintf (accumulator_string , sizeof (accumulator_string ), "%d.%03d" , (int ) result , (int )((int64_t )(result * 1000 ) % 1000 ));
130
133
//reset accumulator so next input works correctly
131
134
accumulator_string_offset = 0 ;
132
135
}
133
136
}
137
+ APP_LOG (APP_LOG_LEVEL_DEBUG , "items3 %d" , stack .items );
134
138
text_layer_set_text (op_text_layer , "" );
135
139
}
136
140
0 commit comments