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

Better structuring of example code? #262

Closed
lure23 opened this issue Jan 23, 2025 · 1 comment
Closed

Better structuring of example code? #262

lure23 opened this issue Jan 23, 2025 · 1 comment

Comments

@lure23
Copy link
Contributor

lure23 commented Jan 23, 2025

I got my own (ESP32-C6 only) code up here, but struggled quite extensively in detaching the logic from each other. I wanted to:

  • detach the "measuring" (data input) from BLE notifications
  • detach each service from the BLE server

I'll walk you through the current design construction, and then ask advice on the remaining (only one) "hot spot". :)

Files

examples/
└── y-emb
    ├── boot_btn_ble.rs      # BLE details for the button (service and characteristic)
    ├── boot_btn_task.rs    # feeds a Signal from the BOOT button on the devkit
    ├── config.in                   # some constants
    ├── main.rs                     # entry point; hw initialization
    └── server_ble.rs          # most of the BLE stuff 

Remaining trouble pun

The construction on this line is a hack.

   any_notify( boot_btn_feed, &server.bb.state, &server, &conn )
  • boot_btn_feed is actually an async poll for the next true/false value, ready to be placed for BLE notification
  • &server.bb.state is needed, because I didn't find a way to make code within the service/characteristic file (boot_btn_ble.rs) to reach its own .state characteristic. Need to study the macro expansions to understand how everything works...
  • access to serverand conn are needed, for placing a notification

The existing TrouBLE examples don't suffer of this, mostly because they don't even try to detach the Server and Services/Characteristics from each other.

@lure23
Copy link
Contributor Author

lure23 commented Jan 24, 2025

Was able to reach it!

The service now has .notify_task() method

..that gets called within the Server here

@lure23 lure23 closed this as completed Jan 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant