From 027e3bb42ed0f0e0f6c2bacbc0c896d721e7cd63 Mon Sep 17 00:00:00 2001 From: Christian Chapman <1360262+enthdegree@users.noreply.github.com> Date: Fri, 20 Jan 2023 20:15:28 -0500 Subject: Morse-code based RPN calculator (#164) * 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 Co-authored-by: Christian Chapman Co-authored-by: joeycastillo --- movement/lib/morsecalc/calc_fns.h | 123 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 movement/lib/morsecalc/calc_fns.h (limited to 'movement/lib/morsecalc/calc_fns.h') diff --git a/movement/lib/morsecalc/calc_fns.h b/movement/lib/morsecalc/calc_fns.h new file mode 100644 index 00000000..fd1d7aba --- /dev/null +++ b/movement/lib/morsecalc/calc_fns.h @@ -0,0 +1,123 @@ +/* + * MIT License + * + * Copyright (c) 2023 Christian Chapman + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +#include "calc.h" + +// Stack and register control +int calc_delete(calc_state_t *cs); +int calc_clear_stack(calc_state_t *cs); +int calc_flip(calc_state_t *cs); +int calc_mem_clear(calc_state_t *cs); +int calc_mem_recall(calc_state_t *cs); +int calc_mem_add(calc_state_t *cs); +int calc_mem_subtract(calc_state_t *cs); + +// Basic operations +int calc_add(calc_state_t *cs); +int calc_subtract(calc_state_t *cs); +int calc_negate(calc_state_t *cs); +int calc_multiply(calc_state_t *cs); +int calc_divide(calc_state_t *cs); +int calc_invert(calc_state_t *cs); + +// Constants +int calc_e(calc_state_t *cs); +int calc_pi(calc_state_t *cs); + +// Exponential/logarithmic +int calc_exp(calc_state_t *cs); +int calc_pow(calc_state_t *cs); +int calc_ln(calc_state_t *cs); +int calc_log(calc_state_t *cs); +int calc_sqrt(calc_state_t *cs); + +// Trigonometric +int calc_sin(calc_state_t *cs); +int calc_cos(calc_state_t *cs); +int calc_tan(calc_state_t *cs); +int calc_asin(calc_state_t *cs); +int calc_acos(calc_state_t *cs); +int calc_atan(calc_state_t *cs); +int calc_atan2(calc_state_t *cs); +int calc_sind(calc_state_t *cs); +int calc_cosd(calc_state_t *cs); +int calc_tand(calc_state_t *cs); +int calc_asind(calc_state_t *cs); +int calc_acosd(calc_state_t *cs); +int calc_atand(calc_state_t *cs); +int calc_atan2d(calc_state_t *cs); + +// Dictionary definition +typedef int (*calc_fn_t)(calc_state_t *cs); +typedef struct { + char *names[3]; // Token to use to run this function + calc_fn_t fn; // Pointer to function +} calc_dict_entry_t; + +static const calc_dict_entry_t calc_dict[] = { + // Stack and register control + {{"x"}, &calc_delete}, + {{"xx"}, &calc_clear_stack}, + {{"xxx"}, &calc_init}, + {{"f"}, &calc_flip}, + {{"mc"}, &calc_mem_clear}, + {{"mr"}, &calc_mem_recall}, + {{"ma"}, &calc_mem_add}, + {{"ms"}, &calc_mem_subtract}, + + // Basic operations + {{"a"}, &calc_add}, + {{"s"}, &calc_subtract}, + {{"n"}, &calc_negate}, + {{"m"}, &calc_multiply}, + {{"d"}, &calc_divide}, + {{"i"}, &calc_invert}, + + // Constants + {{"e"}, &calc_e}, + {{"pi"}, &calc_pi}, + + // Exponential/logarithmic + {{"exp"}, &calc_exp}, + {{"pow"}, &calc_pow}, + {{"ln"}, &calc_ln}, + {{"log"}, &calc_log}, + {{"sqrt"}, &calc_sqrt}, + + // Trigonometric + {{"sin", "sn"}, &calc_sin}, + {{"cos"}, &calc_cos}, + {{"tan"}, &calc_tan}, + {{"asin"}, &calc_asin}, + {{"acos"}, &calc_acos}, + {{"atan"}, &calc_atan}, + {{"atan2"}, &calc_atan2}, + {{"sind"}, &calc_sind}, + {{"cosd"}, &calc_cosd}, + {{"tand"}, &calc_tand}, + {{"asind"}, &calc_asind}, + {{"acosd"}, &calc_acosd}, + {{"atand"}, &calc_atand}, + {{"atan2d"}, &calc_atan2d}, +}; -- cgit v1.2.3