summaryrefslogtreecommitdiffstats
path: root/users/doogle999/doogle999.h
diff options
context:
space:
mode:
authorAjax <doogle999@users.noreply.github.com>2018-10-23 15:44:48 -0400
committerDrashna Jaelre <drashna@live.com>2018-10-23 12:44:48 -0700
commitb0a021c07aa38905090058bd57b9304425594557 (patch)
tree6f4523df1269052759a94a579d9ea184873cf9fc /users/doogle999/doogle999.h
parentc8267d9fea5e8b0dbdeb8521238c922ff4a83a99 (diff)
Made a userspace that allows you to use your keyboard as an order of operations based calculator (#2864)
* Made DZ60 layout with calculator * Cleaned up and commented, preparing to fix bug with negative in front of open parenthesis as first character * Fixed bug where negative sign infront of parenthesis as first character was parsed incorrectly * Made a better solution for the bug from the previous commit * Modularized and added a userfile so that this code can be used on various keyboards, found in doogle999 * Removed commented code from keymap * Made the layer that is used for calculations a define so that it can be changed per keyboard * Made the readme * Made the readme in the correct place * Revert "Made the readme in the correct place" This reverts commit 7f8b59ed9e59c77401a48be3a7ac1e8fd8e84e32. * Manually synced with qmk upstream * Stopped repeat, made keys print character that they are defined as rather than what the keyboard wants them to do * Added support for numpad, might make all keycodes custom so that there is no need to change doogle999.c if you want to change the keycode that is associated with a function, also made numpad automatically activating an option * Fixed some bugs with backspacing, updated the readme * Fixed some bugs with numlock turning on at the wrong times when a shift key was down * Made the return to layer work automatically instead of just forcing it to layer 0 * fixes and style changes, 20% decreased binary size * Fixed some bugs with double printing and compilation errors on my side * Fixed bug with exceeding the buffer size * Removed changes that added const-ness * Made changes so that backspace does not repeat to remove backspace bugs, still some bugs with recalculating without having typed anything * Fixed obo error with calc main loop * Made includes more accurate in keymap for dz60 * Moved flags to user makefile
Diffstat (limited to 'users/doogle999/doogle999.h')
-rw-r--r--users/doogle999/doogle999.h99
1 files changed, 99 insertions, 0 deletions
diff --git a/users/doogle999/doogle999.h b/users/doogle999/doogle999.h
new file mode 100644
index 0000000000..7ed38fbcc8
--- /dev/null
+++ b/users/doogle999/doogle999.h
@@ -0,0 +1,99 @@
+#ifndef USERSPACE
+#define USERSPACE
+
+#include "quantum.h"
+
+#define NO_ACTION_ONESHOT
+#define NO_ACTION_MACRO
+
+#define MODS_SHIFT_MASK (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT))
+
+// Layer the calculator is on
+#define CALC_LAYER 2
+
+// Inside is whether when you are in calc mode it should automatically force numlock, outside is whether it should do it outside of calculator mode
+#define CALC_FORCE_NUM_LOCK_INSIDE_CALC true
+#define CALC_FORCE_NUM_LOCK_OUTSIDE_CALC true
+
+// Maximum number of characters the calculator can have
+#define CALC_BUFFER_SIZE 32
+
+// Minimum width of the printed text / the number of decimal places
+#define CALC_PRINT_SIZE 6
+
+/*-----
+ Special
+-----*/
+#define CALC_CHAR_BEG '('
+#define CALC_CHAR_END ')'
+#define CALC_CHAR_DEC '.'
+
+/*-----
+ Operators - Can add more here such as modulo %, factorial !
+-----*/
+#define CALC_CHAR_ADD '+'
+#define CALC_PRIO_ADD 1
+
+#define CALC_CHAR_SUB '-'
+#define CALC_PRIO_SUB 1
+
+#define CALC_CHAR_MUL '*'
+#define CALC_PRIO_MUL 2
+
+#define CALC_CHAR_DIV '/'
+#define CALC_PRIO_DIV 2
+
+#define CALC_CHAR_EXP '^'
+#define CALC_PRIO_EXP 3
+
+/*-----
+ Functions
+-----*/
+#define CALC_CHAR_SIN 's'
+#define CALC_CHAR_COS 'c'
+#define CALC_CHAR_TAN 't'
+
+#define CALC_CHAR_ASN 'S'
+#define CALC_CHAR_ACS 'C'
+#define CALC_CHAR_ATN 'T'
+
+#define CALC_CHAR_LGE 'l'
+#define CALC_CHAR_LOG 'L'
+
+#define CALC_CHAR_SQT 'q'
+
+/*-----
+ Constants
+-----*/
+#define CALC_CHAR_EUL 'e'
+#define CALC_VALU_EUL 2.71828182845904523536
+
+#define CALC_CHAR_PI 'p'
+#define CALC_VALU_PI 3.14159265358979323846
+
+struct OP // Operator/function
+{
+ char c;
+ unsigned char priority;
+ bool ltr;
+};
+
+union TokenRaw // A token after the input has been processed, can either be a number or an operator/function
+{
+ double num;
+ struct OP op;
+};
+
+struct Token // Encapsulator
+{
+ bool isNum;
+ union TokenRaw raw;
+};
+
+enum CalcFunctions // Hardware calculator key functionality
+{
+ CALC = SAFE_RANGE,
+ ENDCALC
+};
+
+#endif