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.

64 lines
1.7 KiB

  1. /* Copyright 2021 Mikael Manukyan <arm.localhost@gmail.com>
  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 "utils.h"
  17. void store_rgb_state_to_eeprom(void) {
  18. uint8_t mode = rgb_matrix_get_mode();
  19. uint8_t speed = rgb_matrix_get_speed();
  20. HSV color = rgb_matrix_get_hsv();
  21. rgb_matrix_mode(mode);
  22. rgb_matrix_set_speed(speed);
  23. rgb_matrix_sethsv(color.h, color.s, color.v);
  24. }
  25. void press(KeyPressState *self) {
  26. self->_count++;
  27. dprintf("KPS: press: %d\n", self->_count);
  28. // pressed the first time
  29. if (self->_count == 1) {
  30. self->hander(true);
  31. }
  32. }
  33. void release(KeyPressState *self) {
  34. self->_count--;
  35. dprintf("KPS: release: %d\n", self->_count);
  36. // all keys are relased
  37. if (self->_count == 0) {
  38. self->hander(false);
  39. }
  40. }
  41. void reset(KeyPressState *self) {
  42. self->_count = 0;
  43. }
  44. KeyPressState *NewKeyPressState(key_press_handler handler) {
  45. KeyPressState *kps = (KeyPressState *)(malloc(sizeof(KeyPressState)));
  46. kps->_count = 0;
  47. kps->press = press;
  48. kps->release = release;
  49. kps->reset = reset;
  50. kps->hander = handler;
  51. return kps;
  52. }