summaryrefslogtreecommitdiffstats
path: root/movement/lib/morsecalc/calc.c
diff options
context:
space:
mode:
authorChristian Chapman <1360262+enthdegree@users.noreply.github.com>2023-04-16 10:01:03 -0400
committerGitHub <noreply@github.com>2023-04-16 10:01:03 -0400
commit0a836ceceaa7a0d7bc4b27e34b769a2691b9dea6 (patch)
treecb147ee34a40a20380669b758d69833590352161 /movement/lib/morsecalc/calc.c
parent16a96d16b24d3d0ce1e22537f1df06c5df5a0d98 (diff)
downloadSensor-Watch-0a836ceceaa7a0d7bc4b27e34b769a2691b9dea6.tar.gz
Sensor-Watch-0a836ceceaa7a0d7bc4b27e34b769a2691b9dea6.tar.bz2
Sensor-Watch-0a836ceceaa7a0d7bc4b27e34b769a2691b9dea6.zip
Morsecalc refactor (#229)
* Added Morse code based RPN calculator * added manual and memory register * fixed morsecalc negative indicator, edited header comment * adjusted stack display controls * Fixed warnings. Added calculator token aliasing ability. Added binary shorthand for numeral entry. Extended morse code binary tree. * ui tweaks * Update movement_config.h * silence warning * Reorganized codebase and simplified morse code reading routines. * added 'quit if submission is empty' behavior * reverted rules.mk change for merge into main * corrected timeout behavior * consolidated morsecode lib into one file; deleted old mc.c mc.h * consolidated morsecode lib into one file; deleted old mc.c mc.h * removed specious null in morsecode bintree string --------- Co-authored-by: Christian Chapman <user@debian> Co-authored-by: joeycastillo <joeycastillo@utexas.edu>
Diffstat (limited to 'movement/lib/morsecalc/calc.c')
-rw-r--r--movement/lib/morsecalc/calc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/movement/lib/morsecalc/calc.c b/movement/lib/morsecalc/calc.c
index 49b19a00..ed7eb25b 100644
--- a/movement/lib/morsecalc/calc.c
+++ b/movement/lib/morsecalc/calc.c
@@ -24,6 +24,7 @@
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include "calc.h"
#include "calc_fns.h"
@@ -41,12 +42,11 @@ int calc_init(calc_state_t *cs) {
}
/* calc_input_function
- * Try to execut the token as a calculator function
- * TODO: Maybe replace this loop with binary search for token in a sorted calc_dict
+ * Try to execute the token as a calculator function
*/
int calc_input_function(calc_state_t *cs, char *token) {
for(uint8_t idx=0; idx<sizeof(calc_dict)/sizeof(calc_dict[0]); idx++) {
- for(uint8_t idxn=0; idxn<sizeof(calc_dict[idx].names)/sizeof(calc_dict[idx].names[0]); idxn++) {
+ for(uint8_t idxn=0; idxn<calc_dict[idx].n_names; idxn++) {
if(0 == strcmp(calc_dict[idx].names[idxn], token)) { // Found a match
return (*calc_dict[idx].fn)(cs); // Run calculator function
}
@@ -108,6 +108,6 @@ int calc_input_float(calc_state_t *cs, char *token) {
*/
int calc_input(calc_state_t *cs, char *token) {
int retval = calc_input_function(cs, token);
- if(retval == -1) retval = calc_input_float(cs, token);
+ if(-1 == retval) retval = calc_input_float(cs, token);
return retval;
}