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.

97 lines
3.2 KiB

  1. /* Copyright 2023 9R
  2. *
  3. * This program is free software: you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation, either version 2 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "oled.h"
  17. uint8_t shiftbits =32 ;
  18. //////////// OLED output helpers //////////////
  19. void draw_mode(controller_state_t controller_state) {
  20. //draw oled row showing thumbstick mode
  21. oled_write_P(PSTR("Mode: "), false);
  22. if (controller_state.wasdShiftMode) {
  23. oled_write_ln_P(PSTR("WASD + Shift"), false);
  24. } else if (controller_state.wasdMode) {
  25. oled_write_ln_P(PSTR("WASD"), false);
  26. } else {
  27. oled_write_ln_P(PSTR("JoyStick"), false);
  28. }
  29. }
  30. void draw_wasd_key(wasd_state_t wasd_state) {
  31. //draw oled row showing active keypresses emulated from thumbstick
  32. const char* keys = "wasd" ;
  33. bool keystates [] = {wasd_state.w, wasd_state.a, wasd_state.s, wasd_state.d } ;
  34. // iterate over keystates
  35. for ( int i = 0 ; i < 4 ; i++ ){
  36. if ( keystates[i]) {
  37. char k = keys[i] ;
  38. //bitshift char to upper case
  39. if (wasd_state.shift) {
  40. k &= ~shiftbits;
  41. }
  42. sprintf (stringbuffer , "%c", k);
  43. oled_write(stringbuffer , false);
  44. }
  45. else {
  46. oled_write_P(PSTR(" "), false);
  47. }
  48. }
  49. }
  50. void draw_thumb_debug(thumbstick_polar_position_t thumbstick_polar_position) {
  51. //draw oled row showing thumbstick direction and distance from center
  52. oled_write_P(PSTR("Dir: "), false);
  53. sprintf (stringbuffer , "%d", thumbstick_polar_position.angle);
  54. oled_write(stringbuffer , false);
  55. oled_write_P(PSTR(" Dist: "), false);
  56. sprintf (stringbuffer , "%d", thumbstick_polar_position.distance);
  57. oled_write_ln(stringbuffer , false);
  58. //print registered key codes
  59. oled_write_P(PSTR("Keycodes: "), false);
  60. draw_wasd_key( wasd_state );
  61. }
  62. //////////// draw OLED output //////////////
  63. void draw_oled(controller_state_t controller_state) {
  64. oled_write_P(PSTR("Layer: "), false);
  65. switch (controller_state.activeLayer) {
  66. case LAYER_SHOOTER:
  67. oled_write_ln_P(PSTR("Shooter"), false);
  68. draw_mode(controller_state);
  69. oled_write_ln_P(PSTR(" "), false);
  70. oled_write_ln_P(PSTR(" "), false);
  71. break;
  72. case LAYER_MISC:
  73. oled_write_ln_P(PSTR("Misc"), false);
  74. draw_mode(controller_state);
  75. oled_write_ln_P(PSTR(" "), false);
  76. oled_write_ln_P(PSTR(" "), false);
  77. break;
  78. case LAYER_SETTINGS:
  79. oled_write_ln_P(PSTR("Settings"), false);
  80. draw_mode(controller_state);
  81. draw_thumb_debug(thumbstick_polar_position);
  82. oled_write_ln_P(PSTR(" "), false);
  83. break;
  84. default:
  85. oled_write_ln_P(PSTR("Default"), false);
  86. draw_mode(controller_state);
  87. oled_write_ln_P(PSTR(" "), false);
  88. oled_write_ln_P(PSTR(" "), false);
  89. }
  90. }