bjoernQ / bleps

A toy-level BLE peripheral stack
MIT License
55 stars 18 forks source link

Add notify_cb option to `gatt!` characteristics. #39

Closed konkers closed 7 months ago

konkers commented 7 months ago

Being able to take action when a characteristic's notifications are enabled are disabled is useful when the data source needs some action to be taken to start or stop the data source like enabling interrupts or powering on a sensor.

konkers commented 7 months ago

Reworked that patch so that the notification is part of the AttData trait.

bjoernQ commented 7 months ago

This is a useful addition - unfortunately CI is failing currently

konkers commented 7 months ago

Sorry about that, CI should be fixed now.

bjoernQ commented 7 months ago

Sorry about that, CI should be fixed now.

Thanks! I will be able to give it a proper review tomorrow

bjoernQ commented 7 months ago

Mind adding a test to bleps-macros/tests/macro_test.rs? It's just a simple compile test but helpful to not break things in future. Something like this

#[test]
fn test6() {
    let mut my_read_function = |_offset: usize, data: &mut [u8]| {
        data[..5].copy_from_slice(&b"Hola!"[..]);
        5
    };
    let mut my_write_function = |_offset, data: &[u8]| {
        println!("{:?}", data);
    };
    let mut my_notify = |enabled: bool| {
        println!("enabled = {enabled}");
    };

    gatt!([service {
        uuid: "9e7312e0-2354-11eb-9f10-fbc30a62cf38",
        characteristics: [characteristic {
            uuid: "9e7312e0-2354-11eb-9f10-fbc30a62cf38",
            notify: true,
            notify_cb: my_notify,
            read: my_read_function,
            write: my_write_function,
        },],
    },]);

    println!("{:x?}", gatt_attributes);
}
konkers commented 7 months ago

Thanks for the review. Removed vestigial notify_cb_call code and added suggested test code.