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.

77 lines
2.2 KiB

  1. # OS Detection
  2. This feature makes a best guess at the host OS based on OS specific behavior during USB setup. It may not always get the correct OS, and shouldn't be relied on as for critical functionality.
  3. Using it you can have OS specific key mappings or combos which work differently on different devices.
  4. It is available for keyboards which use ChibiOS, LUFA and V-USB.
  5. ## Usage
  6. In your `rules.mk` add:
  7. ```make
  8. OS_DETECTION_ENABLE = yes
  9. ```
  10. Include `"os_detection.h"` in your `keymap.c`.
  11. It declares `os_variant_t detected_host_os(void);` which you can call to get detected OS.
  12. It returns one of the following values:
  13. ```c
  14. enum {
  15. OS_UNSURE,
  16. OS_LINUX,
  17. OS_WINDOWS,
  18. OS_MACOS,
  19. OS_IOS,
  20. } os_variant_t;
  21. ```
  22. ?> Note that it takes some time after firmware is booted to detect the OS.
  23. This time is quite short, probably hundreds of milliseconds, but this data may be not ready in keyboard and layout setup functions which run very early during firmware startup.
  24. ## Debug
  25. If OS is guessed incorrectly, you may want to collect data about USB setup packets to refine the detection logic.
  26. To do so in your `rules.mk` add:
  27. ```make
  28. OS_DETECTION_DEBUG_ENABLE = yes
  29. CONSOLE_ENABLE = yes
  30. ```
  31. And also include `"os_detection.h"` in your `keymap.c`.
  32. Then you can define custom keycodes to store data about USB setup packets in EEPROM (persistent memory) and to print it later on host where you can run `qmk console`:
  33. ```c
  34. enum custom_keycodes {
  35. STORE_SETUPS = SAFE_RANGE,
  36. PRINT_SETUPS,
  37. };
  38. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  39. switch (keycode) {
  40. case STORE_SETUPS:
  41. if (record->event.pressed) {
  42. store_setups_in_eeprom();
  43. }
  44. return false;
  45. case PRINT_SETUPS:
  46. if (record->event.pressed) {
  47. print_stored_setups();
  48. }
  49. return false;
  50. }
  51. }
  52. ```
  53. Then please open an issue on Github with this information and tell what OS was not detected correctly and if you have any intermediate devices between keyboard and your computer.
  54. ## Credits
  55. Original idea is coming from [FingerprintUSBHost](https://github.com/keyboardio/FingerprintUSBHost) project.