keyboard stuff
1# Digitizer {#digitizer}
2
3Digitizers allow the mouse cursor to be placed at absolute coordinates, unlike the [Pointing Device](pointing_device) feature which applies relative displacements.
4
5This feature implements a stylus device with a tip switch and barrel switch (generally equivalent to the primary and secondary mouse buttons respectively). Tip pressure is not currently implemented.
6
7## Usage {#usage}
8
9Add the following to your `rules.mk`:
10
11```make
12DIGITIZER_ENABLE = yes
13```
14
15## Positioning {#positioning}
16
17The X and Y coordinates are normalized, meaning their value must be set between 0 and 1. For the X component, the value `0` is the leftmost position, whereas the value `1` is the rightmost position. Similarly for the Y component, `0` is at the top and `1` at the bottom.
18
19::: tip
20Since there is no display attached, the OS will likely map these coordinates to the virtual desktop. This may be important to know if you have multiple monitors.
21:::
22
23## Examples {#examples}
24
25This example simply places the cursor in the middle of the screen:
26
27```c
28digitizer_in_range_on();
29digitizer_set_position(0.5, 0.5);
30```
31
32The "in range" indicator is required to be on for the change in coordinates to be taken. It can then be turned off again to signal the end of the digitizer interaction, but it is not strictly required.
33
34You can also modify the digitizer state directly, if you need to change multiple fields in a single report:
35
36```c
37digitizer_state.in_range = true;
38digitizer_state.dirty = true;
39digitizer_flush();
40```
41
42`digitizer_state` is a struct of type `digitizer_t`.
43
44
45## API {#api}
46
47### `struct digitizer_t` {#api-digitizer-t}
48
49Contains the state of the digitizer.
50
51#### Members {#api-digitizer-t-members}
52
53 - `bool in_range`
54 Indicates to the host that the contact is within range (ie. close to or in contact with the digitizer surface).
55 - `bool tip`
56 The state of the tip switch.
57 - `bool barrel`
58 The state of the barrel switch.
59 - `float x`
60 The X coordinate of the digitizer contact.
61 - `float y`
62 The Y coordinate of the digitizer contact.
63 - `bool dirty`
64 Whether the current state needs to be sent to the host.
65
66---
67
68### `void digitizer_flush(void)` {#api-digitizer-flush}
69
70Send the digitizer report to the host if it is marked as dirty.
71
72---
73
74### `void digitizer_in_range_on(void)` {#api-digitizer-in-range-on}
75
76Assert the "in range" indicator, and flush the report.
77
78---
79
80### `void digitizer_in_range_off(void)` {#api-digitizer-in-range-off}
81
82Deassert the "in range" indicator, and flush the report.
83
84---
85
86### `void digitizer_tip_switch_on(void)` {#api-digitizer-tip-switch-on}
87
88Assert the tip switch, and flush the report.
89
90---
91
92### `void digitizer_tip_switch_off(void)` {#api-digitizer-tip-switch-off}
93
94Deassert the tip switch, and flush the report.
95
96---
97
98### `void digitizer_barrel_switch_on(void)` {#api-digitizer-barrel-switch-on}
99
100Assert the barrel switch, and flush the report.
101
102---
103
104### `void digitizer_barrel_switch_off(void)` {#api-digitizer-barrel-switch-off}
105
106Deassert the barrel switch, and flush the report.
107
108---
109
110### `void digitizer_set_position(float x, float y)` {#api-digitizer-set-position}
111
112Set the absolute X and Y position of the digitizer contact, and flush the report.
113
114#### Arguments {#api-digitizer-set-position-arguments}
115
116 - `float x`
117 The X value of the contact position, from 0 to 1.
118 - `float y`
119 The Y value of the contact position, from 0 to 1.