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.

117 lines
3.4 KiB

  1. # Digitizer :id=digitizer
  2. Digitizers allow the mouse cursor to be placed at absolute coordinates, unlike the [Pointing Device](feature_pointing_device.md) feature which applies relative displacements.
  3. This 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.
  4. ## Usage :id=usage
  5. Add the following to your `rules.mk`:
  6. ```make
  7. DIGITIZER_ENABLE = yes
  8. ```
  9. ## Positioning :id=positioning
  10. The 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.
  11. ?> Since 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.
  12. ## Examples :id=examples
  13. This example simply places the cursor in the middle of the screen:
  14. ```c
  15. digitizer_in_range_on();
  16. digitizer_set_position(0.5, 0.5);
  17. ```
  18. The "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.
  19. You can also modify the digitizer state directly, if you need to change multiple fields in a single report:
  20. ```c
  21. digitizer_state.in_range = true;
  22. digitizer_state.dirty = true;
  23. digitizer_flush();
  24. ```
  25. `digitizer_state` is a struct of type `digitizer_t`.
  26. ## API :id=api
  27. ### `struct digitizer_t` :id=api-digitizer-t
  28. Contains the state of the digitizer.
  29. #### Members :id=api-digitizer-t-members
  30. - `bool in_range`
  31. Indicates to the host that the contact is within range (ie. close to or in contact with the digitizer surface).
  32. - `bool tip`
  33. The state of the tip switch.
  34. - `bool barrel`
  35. The state of the barrel switch.
  36. - `float x`
  37. The X coordinate of the digitizer contact.
  38. - `float y`
  39. The Y coordinate of the digitizer contact.
  40. - `bool dirty`
  41. Whether the current state needs to be sent to the host.
  42. ---
  43. ### `void digitizer_flush(void)` :id=api-digitizer-flush
  44. Send the digitizer report to the host if it is marked as dirty.
  45. ---
  46. ### `void digitizer_in_range_on(void)` :api-digitizer-in-range-on
  47. Assert the "in range" indicator, and flush the report.
  48. ---
  49. ### `void digitizer_in_range_off(void)` :api-digitizer-in-range-off
  50. Deassert the "in range" indicator, and flush the report.
  51. ---
  52. ### `void digitizer_tip_switch_on(void)` :api-digitizer-tip-switch-on
  53. Assert the tip switch, and flush the report.
  54. ---
  55. ### `void digitizer_tip_switch_off(void)` :api-digitizer-tip-switch-off
  56. Deassert the tip switch, and flush the report.
  57. ---
  58. ### `void digitizer_barrel_switch_on(void)` :api-digitizer-barrel-switch-on
  59. Assert the barrel switch, and flush the report.
  60. ---
  61. ### `void digitizer_barrel_switch_off(void)` :api-digitizer-barrel-switch-off
  62. Deassert the barrel switch, and flush the report.
  63. ---
  64. ### `void digitizer_set_position(float x, float y)` :api-digitizer-set-position
  65. Set the absolute X and Y position of the digitizer contact, and flush the report.
  66. #### Arguments :id=api-digitizer-set-position-arguments
  67. - `float x`
  68. The X value of the contact position, from 0 to 1.
  69. - `float y`
  70. The Y value of the contact position, from 0 to 1.