hbcp.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* Copyright 2019 Josh Hinnebusch
  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 "hbcp.h"
  17. // Indicator color definitions
  18. #ifndef HSV_CAPS
  19. #define HSV_CAPS 0, 0, 120 // Define caps lock color (H, S, V)
  20. #endif
  21. #ifndef HSV_NLCK
  22. #define HSV_NLCK 0, 0, 120 // Define num lock color (H, S, V)
  23. #endif
  24. #ifndef HSV_SCRL
  25. #define HSV_SCRL 0, 0, 120 // Define scroll lock color (H, S, V)
  26. #endif
  27. #ifndef HSV_BLACK
  28. #define HSV_BLACK 0, 0, 0 // Define 'black' color, more like 'LED off' (H, S, V)
  29. #endif
  30. // #define HSV_custom_color H, S, V
  31. // Optional override functions below.
  32. // You can leave any or all of these undefined.
  33. // These are only required if you want to perform custom actions.
  34. void matrix_init_kb(void) {
  35. // put your keyboard start-up code here
  36. // runs once when the firmware starts up
  37. matrix_init_user();
  38. }
  39. void matrix_scan_kb(void) {
  40. // put your looping keyboard code here
  41. // runs every cycle (a lot)
  42. matrix_scan_user();
  43. }
  44. bool process_record_kb(uint16_t keycode, keyrecord_t *record) {
  45. // put your per-action keyboard code here
  46. // runs for every action, just before processing by the firmware
  47. return process_record_user(keycode, record);
  48. }
  49. void led_set_kb(uint8_t usb_led) {
  50. // put your keyboard LED indicator (ex: Caps Lock LED) toggling code here
  51. led_set_user(usb_led);
  52. }
  53. void eeconfig_init_kb(void) { // EEPROM is getting reset!
  54. rgblight_enable(); // Enable RGB by default
  55. rgblight_sethsv(0, 255, 128); // Set default HSV - red hue, full saturation, medium brightness
  56. rgblight_mode(RGBLIGHT_MODE_RAINBOW_SWIRL + 2); // set to RGB_RAINBOW_SWIRL by default
  57. eeconfig_update_kb(0);
  58. eeconfig_init_user();
  59. }
  60. #ifdef RGBLIGHT_ENABLE
  61. __attribute__ ((weak))
  62. void led_set_user(uint8_t usb_led) {
  63. if (IS_LED_ON(usb_led, USB_LED_CAPS_LOCK)) {
  64. sethsv_raw(HSV_CAPS, (LED_TYPE *)&led[0]);
  65. } else {
  66. sethsv(HSV_BLACK, (LED_TYPE *)&led[0]);
  67. }
  68. if (IS_LED_ON(usb_led, USB_LED_NUM_LOCK)) {
  69. sethsv_raw(HSV_NLCK, (LED_TYPE *)&led[1]);
  70. } else {
  71. sethsv(HSV_BLACK, (LED_TYPE *)&led[1]);
  72. }
  73. if (IS_LED_ON(usb_led, USB_LED_SCROLL_LOCK)) {
  74. sethsv_raw(HSV_SCRL, (LED_TYPE *)&led[2]);
  75. } else {
  76. sethsv(HSV_BLACK, (LED_TYPE *)&led[2]);
  77. }
  78. rgblight_set();
  79. }
  80. __attribute__ ((weak))
  81. void keyboard_post_init_user(void) {
  82. rgblight_set_effect_range(3, RGBLED_NUM-3);
  83. led_set_user(_BV(USB_LED_CAPS_LOCK)|_BV(USB_LED_NUM_LOCK)|_BV(USB_LED_SCROLL_LOCK));
  84. wait_ms(300);
  85. led_set_user(0);
  86. }
  87. __attribute__ ((weak))
  88. void hbcp_sethsv_range(uint8_t hue, uint8_t sat, uint8_t val, uint8_t start, uint8_t end) {
  89. LED_TYPE tmp_led;
  90. sethsv_raw(hue, sat, val, &tmp_led);
  91. for (uint8_t i = start; i < end; i++) {
  92. led[i] = tmp_led;
  93. }
  94. rgblight_set();
  95. }
  96. #endif