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.

76 lines
2.0 KiB

  1. /* Copyright 2021
  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 "digitizer.h"
  17. digitizer_t digitizer_state = {
  18. .in_range = false,
  19. .tip = false,
  20. .barrel = false,
  21. .x = 0,
  22. .y = 0,
  23. .dirty = false,
  24. };
  25. void digitizer_flush(void) {
  26. if (digitizer_state.dirty) {
  27. host_digitizer_send(&digitizer_state);
  28. digitizer_state.dirty = false;
  29. }
  30. }
  31. void digitizer_in_range_on(void) {
  32. digitizer_state.in_range = true;
  33. digitizer_state.dirty = true;
  34. digitizer_flush();
  35. }
  36. void digitizer_in_range_off(void) {
  37. digitizer_state.in_range = false;
  38. digitizer_state.dirty = true;
  39. digitizer_flush();
  40. }
  41. void digitizer_tip_switch_on(void) {
  42. digitizer_state.tip = true;
  43. digitizer_state.dirty = true;
  44. digitizer_flush();
  45. }
  46. void digitizer_tip_switch_off(void) {
  47. digitizer_state.tip = false;
  48. digitizer_state.dirty = true;
  49. digitizer_flush();
  50. }
  51. void digitizer_barrel_switch_on(void) {
  52. digitizer_state.barrel = true;
  53. digitizer_state.dirty = true;
  54. digitizer_flush();
  55. }
  56. void digitizer_barrel_switch_off(void) {
  57. digitizer_state.barrel = false;
  58. digitizer_state.dirty = true;
  59. digitizer_flush();
  60. }
  61. void digitizer_set_position(float x, float y) {
  62. digitizer_state.x = x;
  63. digitizer_state.y = y;
  64. digitizer_state.dirty = true;
  65. digitizer_flush();
  66. }