Skip to content
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

Fix connection to incorrect peripheral #318

Merged
merged 1 commit into from
Nov 11, 2020
Merged

Fix connection to incorrect peripheral #318

merged 1 commit into from
Nov 11, 2020

Conversation

xudongzheng
Copy link
Contributor

I believe the check should be if (bt_uuid_cmp(...)) since bt_uuid_cmp() returns "true" when the UUID is different. Allocating struct bt_uuid_128 ensures that memory is correctly allocated for the custom UUID.

@Nicell Nicell added bluetooth Bluetooth related items core Core functionality/behavior of ZMK split labels Nov 3, 2020
LOG_ERR("Unable to load UUID");
continue;
}

if (!bt_uuid_cmp(&uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_SERVICE_UUID))) {
if (bt_uuid_cmp(&uuid.uuid, BT_UUID_DECLARE_128(ZMK_SPLIT_BT_SERVICE_UUID))) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really not sure I agree with this. We want to be connecting to this discovered peripheral only if we found a UUID advertised the matches the ZMK split service UUID. That means these UUIDs need to be equal, which is why we're negating the result of bt_uuid_cmp. Help me see what I'm missing here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See here. When the two UUIDs match, it returns 0 or false. When you negate this, we now run this code whenever the two UUIDs match, which from what I'm reading is the opposite of what we want. Maybe an explicit != 0 (is not the same) would be easier to read?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh! I'm sorry, I should have read this more carefully. This fix does make sense.

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@xudongzheng Tested here locally, working great. Thanks for the fix!

@petejohanson petejohanson merged commit 51ca4fb into zmkfirmware:main Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bluetooth Bluetooth related items core Core functionality/behavior of ZMK split
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants