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

Add notify_cb option to gatt! characteristics. #39

Merged
merged 1 commit into from
Mar 13, 2024

Conversation

konkers
Copy link
Contributor

@konkers konkers commented Mar 9, 2024

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
Copy link
Contributor Author

konkers commented Mar 9, 2024

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

@bjoernQ
Copy link
Owner

bjoernQ commented Mar 11, 2024

This is a useful addition - unfortunately CI is failing currently

@konkers
Copy link
Contributor Author

konkers commented Mar 11, 2024

Sorry about that, CI should be fixed now.

@bjoernQ
Copy link
Owner

bjoernQ commented Mar 11, 2024

Sorry about that, CI should be fixed now.

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

bleps-macros/src/lib.rs Outdated Show resolved Hide resolved
bleps-macros/src/lib.rs Outdated Show resolved Hide resolved
@bjoernQ
Copy link
Owner

bjoernQ commented Mar 12, 2024

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);
}

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
Copy link
Contributor Author

konkers commented Mar 12, 2024

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

Copy link
Owner

@bjoernQ bjoernQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM - Thanks a lot for this useful contribution

@bjoernQ bjoernQ merged commit 1e35e76 into bjoernQ:main Mar 13, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

None yet

2 participants