-
-
Notifications
You must be signed in to change notification settings - Fork 38.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Host driver (wireless) rework, phase 1. #24365
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,79 @@ | ||
// Copyright 2024 Nick Brassel (@tzarc) | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#include <stdlib.h> | ||
#include "host_driver.h" | ||
#include "host.h" | ||
#include "outputselect.h" | ||
#include "process_connection.h" | ||
|
||
static void cycle_connection(bool forwards) { | ||
int driver_types[] = {OUTPUT_USB, OUTPUT_BLUETOOTH, OUTPUT_2P4GHZ}; | ||
host_driver_t *drivers[] = {host_usb_driver(), host_bluetooth_driver(), host_2pt4Ghz_driver()}; | ||
|
||
host_driver_t *driver = host_get_driver(); | ||
int start_idx; | ||
for (int i = 0; i < ARRAY_SIZE(drivers); ++i) { | ||
if (drivers[i] == driver) { | ||
start_idx = i; | ||
} | ||
} | ||
for (int i = 1; i < ARRAY_SIZE(drivers); ++i) { | ||
int idx = (ARRAY_SIZE(drivers) + start_idx + (forwards ? i : -i)) % ARRAY_SIZE(drivers); | ||
if (drivers[idx] != NULL) { | ||
host_set_driver(drivers[idx]); | ||
set_output(driver_types[idx]); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
bool process_connection(uint16_t keycode, keyrecord_t *record) { | ||
if (record->event.pressed) { | ||
switch (keycode) { | ||
case QK_OUTPUT_NEXT: | ||
set_output(OUTPUT_AUTO); // This should cycle through the outputs going forward. Ensure `docs/keycodes.md`, `docs/features/bluetooth.md` are updated when it does. | ||
cycle_connection(true); | ||
return false; | ||
case QK_OUTPUT_USB: | ||
set_output(OUTPUT_USB); | ||
|
||
case QK_OUTPUT_PREV: | ||
cycle_connection(false); | ||
return false; | ||
case QK_OUTPUT_BLUETOOTH: | ||
set_output(OUTPUT_BLUETOOTH); | ||
|
||
case QK_OUTPUT_NONE: { | ||
host_driver_t *driver = NULL; | ||
if (host_get_driver() != driver) { | ||
host_set_driver(driver); | ||
set_output(OUTPUT_NONE); | ||
} | ||
return false; | ||
} | ||
|
||
case QK_OUTPUT_USB: { | ||
host_driver_t *driver = host_usb_driver(); | ||
if (driver && host_get_driver() != driver) { | ||
host_set_driver(driver); | ||
set_output(OUTPUT_USB); | ||
} | ||
return false; | ||
} | ||
|
||
case QK_OUTPUT_BLUETOOTH: { | ||
host_driver_t *driver = host_bluetooth_driver(); | ||
if (driver && host_get_driver() != driver) { | ||
host_set_driver(driver); | ||
set_output(OUTPUT_BLUETOOTH); | ||
} | ||
Comment on lines
+61
to
+64
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This probably would need to be refactored to a helper function, and do a bit more:
Also what would be the role of |
||
return false; | ||
} | ||
|
||
case QK_OUTPUT_2P4GHZ: { | ||
host_driver_t *driver = host_2pt4Ghz_driver(); | ||
if (driver && host_get_driver() != driver) { | ||
host_set_driver(driver); | ||
set_output(OUTPUT_2P4GHZ); | ||
} | ||
return false; | ||
} | ||
|
||
case QK_OUTPUT_PREV: | ||
case QK_OUTPUT_NONE: | ||
case QK_OUTPUT_2P4GHZ: | ||
case QK_BLUETOOTH_PROFILE_NEXT: | ||
case QK_BLUETOOTH_PROFILE_PREV: | ||
case QK_BLUETOOTH_UNPAIR: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My proposal is to move
has_init_executed
andis_connected
flags and probably others not implemented yet into a state enum. Like it is already done forusb_device_state
with callbacks for state changes. As the driver can hardly be connected without running init first.