Parent directory

digitizer.c

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