-
Notifications
You must be signed in to change notification settings - Fork 281
Add USB/BLE auto-switching and improved LED indicators for Preonic #1526
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
When the Preonic enters deep sleep (LOWPWR mode), FreeRTOS tasks are suspended so the SOC event handler cannot process USB power events. However, the SoftDevice's internal USB detection interrupt still fires and briefly wakes the CPU from waitForEvent(). This commit leverages that wake behavior by polling the USB power status register (USBREGSTATUS) after each waitForEvent() in the sleep loop. If USB power is detected, we set input_event_pending_ to exit sleep. This elegant solution requires only 3 lines of code and works perfectly with the existing power-efficient LOWPWR sleep mode. Also includes: - Orange LED indicator for USB power-only connections (vs red) - USB connection event cleanup in nRF52840.cpp - SoftDevice API setup for USB VBUS detection 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
USBAutoSwitcher improvements: - Add afterEachCycle handler to detect "no USB at startup" condition - Previously only handled USB power-only; now handles no USB at all - After 1-second startup delay, switches to BLE device 1 if no USB detected - Minimal performance impact: single boolean check after first second LED indicator improvements: - Changed USB connection effect from green pulse to smooth green fade-up - Uses Grow effect for 1-second fade instead of 3 pulses - Provides cleaner visual feedback for USB data connection The afterEachCycle overhead is minimal - just a boolean check that returns immediately after the startup switching is complete. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
…nic device - Move USB power-only detection logic to Preonic device's betweenCycles() This is the proper location for device-specific startup checks - Remove misplaced USB checking methods from LEDIndicators plugin LED plugins should only handle visual indications, not USB state detection - Remove debug tone code from nRF52840.cpp MCU driver Debug code doesn't belong in production MCU drivers - The Preonic device now properly checks for USB power-only state after 2s and triggers the appropriate LED indication through the event system 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Move USB power-only detection logic from device layer to MCU driver where it architecturally belongs - Implement checkUSBPowerOnlyStatus() in nRF52840 MCU driver - Call the MCU's check method from Preonic's betweenCycles() - Avoid circular dependencies by implementing in .cpp file where hooks are already available - Triggers orange LED indication when USB has power but no data connection after 2 second startup delay 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Fix selectDevice() to not start advertising when already connected This was causing incorrect LED indications when switching back to an already-connected BLE device - Only start advertising if not already connected to the requested device - Add BLE disconnect when switching to USB mode for clean transitions Ensures we don't have simultaneous USB and BLE connections 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Fix sleep timeout from 2s to 10s so LED indicators don't get cut off mid-animation - Add delay support to LED indicators to prevent USB/BLE indicators from overlapping - Clear existing indicators when USB connects/disconnects for uniform LED display - BLE indicators now wait 1.5s to let USB indicators complete first - Delayed indicators don't block their LED slot until the delay expires - USB indicators show for 1 second (green on connect, red on disconnect) This improves the visual feedback when switching between USB and Bluetooth connections, ensuring all status LEDs display clearly without interference.
When switching between BLE connection states, multiple indicators were overlapping on the same LED, causing visual confusion. Now each status change clears any existing indicator before setting a new one. - Clear advertising indicator when connection succeeds - Clear device selected indicator when advertising starts - Clear any previous indicator when setting a new one - Change USB disconnect from red to orange (less alarming) This prevents the issue where DeviceSelected, Advertising, and Connected indicators were all active simultaneously on the same LED. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Add hasActiveIndicators() helper to check if indicators are active in a given slot range. Use this to only delay BLE indicators when USB indicators are actively showing, avoiding unnecessary waits. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Add a global indicator type that controls all configured LED slots with a single indicator. This prevents issues with individual indicators getting out of sync or interfering with each other. USB connection events (connecting, connected, disconnected) now use global indicators that atomically control all 4 LEDs. Also improve BLE indicator delays to wait only as long as needed for any active global indicators to finish, rather than a fixed 1500ms. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
This commit improves the interaction between the boot greeting effect and LED indicators: 1. Fix KeyAddr usage in PreonicBootGreeting - Previously used KeyAddr(LED_INDEX) which incorrectly created KeyAddr(row=LED_INDEX, col=0) - Now uses the correct KeyAddr(0, slot) values that match indicator configuration - Maps LED indices to their corresponding indicator slots correctly 2. Simplify boot greeting rainbow effect - All 4 LEDs now show the same rainbow color (instead of butterfly pattern) - Makes it easier to identify when an LED is showing something different - Continues to respect active indicators by not overwriting them 3. Ensure LEDs turn off after boot greeting - Boot greeting now continues to turn off LEDs even after it's done - Prevents LEDs from staying on after the effect completes 4. Add hasActiveIndicatorForLED() to LEDIndicators - Allows other plugins to check if a specific LED has an active indicator - Used by PreonicBootGreeting to avoid overwriting indicator LEDs 5. Fix WS2812 driver brightness calculation - Prevent potential integer overflow in brightness calculation - Use 16-bit intermediate values for safer math 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Fixed else-if brace consistency issue on line 102 where the if block had braces but the else-if didn't. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Changed from device-specific nRF52840 friend declaration to the templated MCU Base class to avoid breaking compilation for non-nRF52 devices. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
- Removed unnecessary Base class friend declaration - Added conditional nRF52840 friend declaration only for nRF52 builds - Uses ARDUINO_NRF52_ADAFRUIT define which is standard for Adafruit nRF52 boards 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
87ae758 to
a03e56d
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds comprehensive USB/BLE connection detection and automatic switching for the Keyboardio Preonic, along with improved LED indicators that provide clear visual feedback for connection status.
Major Features
1. USB Connection Detection and Auto-Switching
2. Enhanced LED Indicators System
3. Smart Indicator Management
hasActiveIndicatorForLED()API for better coordination between plugins4. Boot Greeting Improvements
5. Bug Fixes
Technical Details
New APIs
onHostConnectionStatusChanged()hook for plugins to react to connection eventshasActiveIndicatorForLED()to check if an LED has an active indicatorFiles Changed
Testing
Backwards Compatibility
All changes are backwards compatible. The USBAutoSwitcher plugin is optional and can be disabled if manual control is preferred.
🤖 Generated with Claude Code