-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
refactor: address transport switch enumeration warning #1994
refactor: address transport switch enumeration warning #1994
Conversation
case ZMK_TRANSPORT_USB: { | ||
#if IS_ENABLED(CONFIG_ZMK_USB) |
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.
Doesn't this cause this to fall through to the next label with this change? Maybe better to only define the given transport in the enum if that feature is enabled, instead?
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.
enum zmk_transport
is written to settings, so conditionally defining values could cause the meaning of a saved value to change from one build to another. Sort of a theoretical problem when we only have two transports, and disabling one means you can't switch at all, but that could become a problem if we ever added another RF protocol as a transport for example.
I'd recommend changing these to something more like
case ZMK_TRANSPORT_USB:
#if IS_ENABLED(CONFIG_ZMK_USB)
return ...
#else
return -ENOTSUP;
#endif
to avoid the fallthrough.
Alternatively, you could add a default case, but then you wouldn't get a warning if a new transport is added and someone forgot to add handling for it somewhere.
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.
Good call on the settings storage issue. I agree with the -ENOTSUP
version you proposed.
bc16b1f
to
82f76d4
Compare
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.
Looks good to me, Some existing error messages could be improved a bit if you want though.
app/src/endpoints.c
Outdated
#endif /* IS_ENABLED(CONFIG_ZMK_BLE) */ | ||
} | ||
} | ||
|
||
LOG_ERR("Unsupported endpoint transport %d", current_instance.transport); |
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.
LOG_ERR("Unsupported endpoint transport %d", current_instance.transport); | |
LOG_ERR("Unhandled endpoint transport %d", current_instance.transport); |
Now that we only fall into this case if current_instance.transport
isn't a valid enum value, or we add a new enum value and forget to add handling for it above, the error message could be improved a little.
app/src/endpoints.c
Outdated
#endif /* IS_ENABLED(CONFIG_ZMK_BLE) */ | ||
} | ||
} | ||
|
||
LOG_ERR("Unsupported endpoint transport %d", current_instance.transport); |
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.
Same as above.
82f76d4
to
f9f8d11
Compare
Can you please rebase this so we can get it merged? Updated version LGTM. |
f9f8d11
to
84b8da7
Compare
When building without USB or Bluetooth, the compiler emits a warning due to ZMK_TRANSPORT_USB or ZMK_TRANSPORT_BLE not being handled.
84b8da7
to
43c01f7
Compare
Rebased as requested, and the mouse report should be handled as well. |
When building without USB or Bluetooth, the compiler would emit a warning due to ZMK_TRANSPORT_USB or ZMK_TRANSPORT_BLE not being handled.