Implementation of Button State Characteristic

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at//www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
7 posts / 0 new
Last post
Diego Garcia
Offline
Last seen:1 year 10 months ago
Joined:2019-04-15 16:11
Implementation of Button State Characteristic

Hello there.

I'm working on a project which main characteristic is the state change detection of a push button, quite simple.
I need to read the state of the button and send this value to the phone, so I 'll can know if the button has been pressed, which is exactly what the Button State Characteristic does.

Dialog Training Materials show how to implement a custom service with the Control Point and LED State characteristics, so I was wondering if there's a tutorial which do the same, but with the Button State characteristic.

Thanks in advance

Device:
rajucoolsuraj
Offline
Last seen:7 months 1 week ago
Joined:2018-12-12 16:09
Hello Diego Garcia,

Hello Diego Garcia,

There is a particular example implementation among the BLE 7 pillar examples. It is "BLE_SLEEPMODE".

It would be simpler to advertise the button state than over an established BLE connection.

考虑的例子——“BLE_BAREBONE”。这里的广告vertisement data is updated every few seconds by updating a counter. The Button state can be an interrupt that updates the advertising packet with button state in the button interrupt callback and advertising data is re-transmitted.

Regards

Raju

PM_Dialog
Offline
Last seen:21 hours 34 min ago
Staff
Joined:2018-02-08 11:03
Hi Diego Garcia,

Hi Diego Garcia,

As rajucoolsuraj mentioned, you should check the ble_app_sleepmode example of the SDK. This example is located under 5.0.4\projects\target_apps\ble_examples SDK folder path. For more information, you could also read theUM-B-050 : DA1458x Software Developers Guide (SDK5)user manual form our support website.

Thanks, PM_Dialog

Diego Garcia
Offline
Last seen:1 year 10 months ago
Joined:2019-04-15 16:11
Thanks for response, I've

Thanks for response, I've already checked the Pillar 5 example, but I'm afraid that documentation is not as explicit as I may wish.
So, what would be the steps to implement the button functionality?, I'm not asking for the code, just for the broad steps, thanks in advance

PM_Dialog
Offline
Last seen:21 hours 34 min ago
Staff
Joined:2018-02-08 11:03
Hi Diego Garcia,

Hi Diego Garcia,

If you are using any of sleep modes, you should use the wake-up controller in order to detect the GPIO interrupt and the reason is because in sleep mode all the peripheral block are shut down. Please check the ble_app_sleepmode example of the SDK. Go through the code and you will find the app_button_enable() function. In this function you could set the wake-up interrupt, identify the polarity and register the callback function that will be executed upon on the interrupt detection. So, you should define a callback function in order to read the state of the button and save it into a variable. Then, have a look at ADC 1 characteristic which send data though notification to a peer device over a BLE connection. You should take case how long will you have the button pressed, because the notification will be sent in the next connection interval. Be aware that the device will go into sleep between the advertising or connection intervals. If you would not like to have sleep mode in your project, you could use the APSs in gpio.h library in order to detect the interrupt and read the state of the button.

Thanks, PM_Dialog

Diego Garcia
Offline
Last seen:1 year 10 months ago
Joined:2019-04-15 16:11
Thank you a lot!, This makes

Thank you a lot!, This makes it clearer.
In my project, I would like to use the minimum amount of hardware possible (the simpler, the better) so it would be possible to use the same button for both events? one click to wake up the chip and a second one to trigger the alert. Or do I need to use a different GPIO?
In this case, what would be the steps to achieve it?

PM_Dialog
Offline
Last seen:21 hours 34 min ago
Staff
Joined:2018-02-08 11:03
Hi Diego Garcia,

Hi Diego Garcia,

Yes, you could use just one button in your implementation. Probably you should use a flag sored into retention RA, indicating either to wake up or send an alert to a peer device. But this up to you and your code implementation. Be aware that of you are using any of sleep modes, the device will go into sleep between advertising or connection intervals.

Thanks, PM_Dialog