You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
1.9 KiB

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
5 years ago
  1. #ifndef USERSPACE
  2. #define USERSPACE
  3. #include "quantum.h"
  4. #define NO_ACTION_ONESHOT
  5. #define NO_ACTION_MACRO
  6. #define MODS_SHIFT_MASK (MOD_BIT(KC_LSHIFT)|MOD_BIT(KC_RSHIFT))
  7. // Layer the calculator is on
  8. #define CALC_LAYER 2
  9. // 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
  10. #define CALC_FORCE_NUM_LOCK_INSIDE_CALC true
  11. #define CALC_FORCE_NUM_LOCK_OUTSIDE_CALC true
  12. // Maximum number of characters the calculator can have
  13. #define CALC_BUFFER_SIZE 32
  14. // Minimum width of the printed text / the number of decimal places
  15. #define CALC_PRINT_SIZE 6
  16. /*-----
  17. Special
  18. -----*/
  19. #define CALC_CHAR_BEG '('
  20. #define CALC_CHAR_END ')'
  21. #define CALC_CHAR_DEC '.'
  22. /*-----
  23. Operators - Can add more here such as modulo %, factorial !
  24. -----*/
  25. #define CALC_CHAR_ADD '+'
  26. #define CALC_PRIO_ADD 1
  27. #define CALC_CHAR_SUB '-'
  28. #define CALC_PRIO_SUB 1
  29. #define CALC_CHAR_MUL '*'
  30. #define CALC_PRIO_MUL 2
  31. #define CALC_CHAR_DIV '/'
  32. #define CALC_PRIO_DIV 2
  33. #define CALC_CHAR_EXP '^'
  34. #define CALC_PRIO_EXP 3
  35. /*-----
  36. Functions
  37. -----*/
  38. #define CALC_CHAR_SIN 's'
  39. #define CALC_CHAR_COS 'c'
  40. #define CALC_CHAR_TAN 't'
  41. #define CALC_CHAR_ASN 'S'
  42. #define CALC_CHAR_ACS 'C'
  43. #define CALC_CHAR_ATN 'T'
  44. #define CALC_CHAR_LGE 'l'
  45. #define CALC_CHAR_LOG 'L'
  46. #define CALC_CHAR_SQT 'q'
  47. /*-----
  48. Constants
  49. -----*/
  50. #define CALC_CHAR_EUL 'e'
  51. #define CALC_VALU_EUL 2.71828182845904523536
  52. #define CALC_CHAR_PI 'p'
  53. #define CALC_VALU_PI 3.14159265358979323846
  54. struct OP // Operator/function
  55. {
  56. char c;
  57. unsigned char priority;
  58. bool ltr;
  59. };
  60. union TokenRaw // A token after the input has been processed, can either be a number or an operator/function
  61. {
  62. double num;
  63. struct OP op;
  64. };
  65. struct Token // Encapsulator
  66. {
  67. bool isNum;
  68. union TokenRaw raw;
  69. };
  70. enum CalcFunctions // Hardware calculator key functionality
  71. {
  72. CALC = SAFE_RANGE,
  73. ENDCALC
  74. };
  75. #endif