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

WIP: ble: add next gen profile #67

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

kienvo
Copy link
Member

@kienvo kienvo commented Jan 7, 2025

This profile allows communicating in both ways which resolves #33.

I am working on adding configurations using this profile. And it may resolve #64, #52, #60, #41, #34, #32

Summary by Sourcery

Add next generation Bluetooth profile to enable bidirectional communication and configuration.

New Features:

Tests:

  • Remove some test code related to battery status and charging.

kienvo added 2 commits January 7, 2025 23:01
App might read battery level from characteristic/service uuid: 0x2A19/0x180F
Copy link

sourcery-ai bot commented Jan 7, 2025

Reviewer's Guide by Sourcery

This pull request implements a new Bluetooth Low Energy (BLE) profile to enable bidirectional communication, addressing issue #34. It introduces a new service and characteristics for data exchange and adds support for battery level and device information services. The update also includes changes to the device's power management, animation sequences, and configuration handling.

Sequence diagram for BLE next generation profile communication

sequenceDiagram
    participant Client as BLE Client
    participant Badge as LED Badge
    participant Handler as Command Handler

    Client->>Badge: Write Command
    Badge->>Handler: ng_parse(val, len)
    Handler->>Handler: Execute command_lut[cmd]
    Handler-->>Badge: Return status
    Badge-->>Client: Notify response

    note over Badge,Handler: Supported commands:
    note over Badge,Handler: - next_packet
    note over Badge,Handler: - power_switch
    note over Badge,Handler: - streaming_setting
    note over Badge,Handler: - stream_bitmap
    note over Badge,Handler: - ble_setting
    note over Badge,Handler: - flash_splash_screen
Loading

Class diagram for the new BLE profile and configuration structure

classDiagram
    class badge_cfg_t {
        +ble_cfg_t ble
        +splash_cfg_t splash
        +led_cfg_t led
    }
    class ble_cfg_t {
        +uint8_t always_on
        +sfmem_t devname
    }
    class splash_cfg_t {
        +xbm_t bm
        +uint16_t speed_t
    }
    class led_cfg_t {
        +uint8_t brightness
        +uint16_t scan_freq
    }
    class sfmem_t {
        +uint16_t len
        +uint8_t* ptr
    }
    badge_cfg_t *-- ble_cfg_t
    badge_cfg_t *-- splash_cfg_t
    badge_cfg_t *-- led_cfg_t
    ble_cfg_t *-- sfmem_t
Loading

File-Level Changes

Change Details Files
Implemented a new BLE profile for bidirectional communication.
  • Added a new BLE service and characteristics for bidirectional data transfer.
  • Implemented handlers for write and read operations on the new characteristics.
  • Added support for notifying the client of new data.
  • Refactored existing BLE code to accommodate the new profile.
  • Updated the BLE setup to register the new service.
src/main.c
src/ble/peripheral.c
src/ble/profile.h
src/ble/profile/legacy.c
src/ble/profile/ng.c
Added battery level and device information services.
  • Registered the battery service and device information service.
  • Implemented read handlers for battery level and device information characteristics.
  • Updated the BLE setup to include the new services.
src/main.c
src/ble/profile.h
src/ble/profile/batt.c
src/ble/profile/devinfo.c
Improved power management and animation sequences.
  • Modified power-off functionality to conditionally disable based on BLE always-on setting.
  • Added functions to read battery level and charging status.
  • Updated animation sequences for BLE connection and normal operation.
  • Refactored animation code to improve clarity and efficiency.
src/main.c
src/power.c
src/power.h
Introduced configuration handling and updated USB communication.
  • Added support for reading and writing device configuration from flash memory.
  • Created a configuration structure to store device settings.
  • Implemented functions to handle configuration updates.
  • Updated USB communication to support streaming mode and bitmap transfer.
  • Added new control commands for next packet, power switch, BLE settings, and splash screen flashing.
src/main.c
src/config.c
src/config.h
src/ngctrl.c
src/ngctrl.h
Refactored and improved code structure.
  • Removed unused code and dependencies.
  • Improved code readability and maintainability.
  • Updated the Makefile to reflect the changes.
  • Modified debug output handling.
  • Updated BLE buffer size and memory allocation.
  • Removed unused debug UART definitions.
  • Removed unused print macro definition.
src/main.c
src/ble/setup.c
Makefile
src/usb/debug.h
CH5xx_ble_firmware_library/StdPeriphDriver/CH58x_sys.c
CH5xx_ble_firmware_library/StdPeriphDriver/inc/CH58x_common.h
CH5xx_ble_firmware_library/StdPeriphDriver/inc/CH583SFR.h

Assessment against linked issues

Issue Objective Addressed Explanation
#34 Get more control over BLE by implementing always-on BLE functionality
#64 Prevent displaying firmware version (M1-8) each time during content upload
#64 Ensure device stays in display mode while charging when switched to display text

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant