summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorAndre Brait <andrebrait@gmail.com>2024-02-16 15:19:02 +0100
committerGitHub <noreply@github.com>2024-02-17 01:19:02 +1100
commit80f3da36e571fa702b1d3df693fd545801250eca (patch)
tree8fe09c9e53bbe8534372a87bab3d4edfd61e5fa8 /docs
parent77e88674986ee14bd1799b1ab19b4c94af083bac (diff)
[Core] Add OS detection callbacks (#21777)
Diffstat (limited to 'docs')
-rw-r--r--docs/feature_os_detection.md50
1 files changed, 49 insertions, 1 deletions
diff --git a/docs/feature_os_detection.md b/docs/feature_os_detection.md
index 907638bcfa..a50ee7ccc2 100644
--- a/docs/feature_os_detection.md
+++ b/docs/feature_os_detection.md
@@ -14,7 +14,7 @@ In your `rules.mk` add:
OS_DETECTION_ENABLE = yes
```
-Include `"os_detection.h"` in your `keymap.c`.
+It will automatically include the required headers file.
It declares `os_variant_t detected_host_os(void);` which you can call to get detected OS.
It returns one of the following values:
@@ -32,6 +32,54 @@ enum {
?> Note that it takes some time after firmware is booted to detect the OS.
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.
+## Callbacks :id=callbacks
+
+If you want to perform custom actions when the OS is detected, then you can use the `process_detected_host_os_kb` function on the keyboard level source file, or `process_detected_host_os_user` function in the user `keymap.c`.
+
+```c
+bool process_detected_host_os_kb(os_variant_t detected_os) {
+ if (!process_detected_host_os_user(detected_os)) {
+ return false;
+ }
+ switch (detected_os) {
+ case OS_MACOS:
+ case OS_IOS:
+ rgb_matrix_set_color_all(RGB_WHITE);
+ break;
+ case OS_WINDOWS:
+ rgb_matrix_set_color_all(RGB_BLUE);
+ break;
+ case OS_LINUX:
+ rgb_matrix_set_color_all(RGB_ORANGE);
+ break;
+ case OS_UNSURE:
+ rgb_matrix_set_color_all(RGB_RED);
+ break;
+ }
+
+ return true;
+}
+```
+
+## OS detection stability
+
+The OS detection is currently handled while the USB device descriptor is being assembled.
+The process is done in steps, generating a number of intermediate results until it stabilizes.
+We therefore resort to debouncing the result until it has been stable for a given amount of milliseconds.
+This amount can be configured, in case your board is not stable within the default debouncing time of 200ms.
+
+## KVM and USB switches
+
+Some KVM and USB switches may not trigger the USB controller on the keyboard to fully reset upon switching machines.
+If your keyboard does not redetect the OS in this situation, you can force the keyboard to reset when the USB initialization event is detected, forcing the USB controller to be reconfigured.
+
+## Configuration Options
+
+* `#define OS_DETECTION_DEBOUNCE 200`
+ * defined the debounce time for OS detection, in milliseconds
+* `#define OS_DETECTION_KEYBOARD_RESET`
+ * enables the keyboard reset upon a USB device reinitilization, such as switching devices on some KVMs
+
## Debug
If OS is guessed incorrectly, you may want to collect data about USB setup packets to refine the detection logic.