m256ws.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* Copyright 2022 Gondolindrim
  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 "quantum.h"
  17. #ifdef VIA_ENABLE
  18. bool is_second_rgb_row_active;
  19. enum via_secondrow_enable {
  20. id_is_second_rgb_row_active = 0
  21. };
  22. // Sets the second RGB row on or off; done by setting effect range.
  23. void set_second_rgb_row(bool is_active) {
  24. rgblight_disable_noeeprom();
  25. switch (is_active)
  26. {
  27. case true:
  28. {
  29. rgblight_set_effect_range(0,30);
  30. break;
  31. }
  32. case false:
  33. {
  34. rgblight_set_effect_range(0,15);
  35. break;
  36. }
  37. }
  38. rgblight_enable_noeeprom();
  39. }
  40. // At the keyboard start, retrieves PMEM stored configs
  41. void keyboard_post_init_kb(void) {
  42. rgblight_disable_noeeprom();
  43. wait_ms(20);
  44. eeconfig_read_kb_datablock(&is_second_rgb_row_active);
  45. set_second_rgb_row(is_second_rgb_row_active);
  46. rgblight_reload_from_eeprom();
  47. rgblight_set();
  48. }
  49. void eeconfig_init_kb(void) { // EEPROM is getting reset!
  50. // rgblight_disable(); // Enable RGB by default
  51. // Define the defualt value and write it to EEPROM
  52. is_second_rgb_row_active = true;
  53. set_second_rgb_row(is_second_rgb_row_active);
  54. eeconfig_update_kb_datablock(&is_second_rgb_row_active);
  55. // Disable rgblight by default on EEPROM initialization
  56. rgblight_disable();
  57. // Run user code, if any
  58. eeconfig_init_user();
  59. }
  60. void secondrow_config_set_value( uint8_t *data )
  61. {
  62. // data = [ value_id, value_data ]
  63. uint8_t *value_id = &(data[0]);
  64. uint8_t *value_data = &(data[1]);
  65. switch ( *value_id )
  66. {
  67. case id_is_second_rgb_row_active:
  68. {
  69. is_second_rgb_row_active = (bool) *value_data;
  70. break;
  71. }
  72. default:
  73. {
  74. is_second_rgb_row_active = true;
  75. }
  76. }
  77. set_second_rgb_row(is_second_rgb_row_active);
  78. }
  79. void secondrow_config_get_value( uint8_t *data )
  80. {
  81. // data = [ value_id, value_data ]
  82. uint8_t *value_id = &(data[0]);
  83. uint8_t *value_data = &(data[1]);
  84. switch ( *value_id )
  85. {
  86. case id_is_second_rgb_row_active:
  87. {
  88. *value_data = is_second_rgb_row_active;
  89. break;
  90. }
  91. default:
  92. {
  93. *value_data = false;
  94. }
  95. }
  96. }
  97. void secondrow_config_save(void)
  98. {
  99. eeconfig_update_kb_datablock(&is_second_rgb_row_active);
  100. }
  101. void via_custom_value_command_kb(uint8_t *data, uint8_t length) {
  102. // data = [ command_id, channel_id, value_id, value_data ]
  103. uint8_t *command_id = &(data[0]);
  104. uint8_t *channel_id = &(data[1]);
  105. uint8_t *value_id_and_data = &(data[2]);
  106. if ( *channel_id == id_custom_channel ) {
  107. switch ( *command_id )
  108. {
  109. case id_custom_set_value:
  110. {
  111. secondrow_config_set_value(value_id_and_data);
  112. break;
  113. }
  114. case id_custom_get_value:
  115. {
  116. secondrow_config_get_value(value_id_and_data);
  117. break;
  118. }
  119. case id_custom_save:
  120. {
  121. secondrow_config_save();
  122. break;
  123. }
  124. default:
  125. {
  126. // Unhandled message.
  127. *command_id = id_unhandled;
  128. break;
  129. }
  130. }
  131. return;
  132. }
  133. // Return the unhandled state
  134. *command_id = id_unhandled;
  135. }
  136. #endif // VIA ENABLE