qmk-keychron-q3-colemak-dh/users/doogle999/doogle999.h
Ajax b0a021c07a 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
2018-10-23 12:44:48 -07:00

100 lines
1.9 KiB
C

#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