-
Notifications
You must be signed in to change notification settings - Fork 56
Improved button support #289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,18 +66,22 @@ struct MbedClientDevice device = { | |
MbedClient mbed_client(device); | ||
|
||
|
||
// In case of K64F board , there is button resource available | ||
// to change resource value and unregister | ||
#ifdef TARGET_K64F | ||
// If board has a button_1, use it to update the counter. | ||
#ifdef BUTTON1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems that the BUTTON1 and BUTTON2 identifiers are actually enum values (see PinNames.h:208 for TARGET_K64F) , so the preprocessor has no knowledge of them. Maybe they should be behind a macro where we could collect other standard definitions like the buttons? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One solution - perhaps we can add the button resource run-time, IF the button is available AND always add a timer resource? Or alternatively - do the buttons.h -header that defines the #ifdefds per board. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Some boards seem to define buttons that do not exist, see: https://github.com/ARMmbed/mbed-os/blob/master/targets/TARGET_STM/TARGET_STM32F3/TARGET_STM32F303x8/TARGET_NUCLEO_F303K8/PinNames.h#L106 The same enum contains a "not connected" value too. If we could rely on some enum value indicating that a button is not available (like the example), we could check that at runtime. But then there's still the issue of missing enum names that cause compile errors. |
||
// Set up Hardware interrupt button. | ||
InterruptIn obs_button(SW2); | ||
InterruptIn unreg_button(SW3); | ||
#else | ||
InterruptIn obs_button(BUTTON1); | ||
#else // BUTTON1 | ||
//In non K64F boards , set up a timer to simulate updating resource, | ||
// there is no functionality to unregister. | ||
Ticker timer; | ||
#endif | ||
|
||
// If the board has a 2nd button - hook the unregistration to that. | ||
#ifdef BUTTON2 | ||
InterruptIn unreg_button(BUTTON2); | ||
#endif // BUTTON2 | ||
|
||
|
||
/* | ||
* Arguments for running "blink" in it's own thread. | ||
*/ | ||
|
@@ -242,11 +246,11 @@ class ButtonResource { | |
|
||
// up counter | ||
counter++; | ||
#ifdef TARGET_K64F | ||
#ifdef BUTTON1 | ||
printf("handle_button_click, new value of counter is %d\n", counter); | ||
#else | ||
printf("simulate button_click, new value of counter is %d\n", counter); | ||
#endif | ||
#endif // BUTTON1 | ||
// serialize the value of counter as a string, and tell connector | ||
char buffer[20]; | ||
int size = sprintf(buffer,"%d",counter); | ||
|
@@ -373,18 +377,20 @@ Add MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_TEST_NULL_ENTROPY in mbed_app | |
LedResource led_resource; | ||
BigPayloadResource big_payload_resource; | ||
|
||
#ifdef TARGET_K64F | ||
// On press of SW3 button on K64F board, example application | ||
#ifdef BUTTON2 | ||
// On press 2nd button (boards that have it), example application | ||
// will call unregister API towards mbed Device Connector | ||
//unreg_button.fall(&mbed_client,&MbedClient::test_unregister); | ||
unreg_button.fall(&unregister); | ||
#endif // BUTTON2 | ||
|
||
// Observation Button (SW2) press will send update of endpoint resource values to connector | ||
#ifdef BUTTON1 | ||
// 1st button - observation button press will send update of endpoint resource values to connector | ||
obs_button.fall(&button_clicked); | ||
#else | ||
// Send update of endpoint resource values to connector every 15 seconds periodically | ||
timer.attach(&button_clicked, 15.0); | ||
#endif | ||
#endif // BUTTON1 | ||
|
||
// Create endpoint interface to manage register and unregister | ||
mbed_client.create_interface(MBED_SERVER_ADDRESS, network); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like the idea of having to dive into the hidden places of the source code to identify a button, that's not a great UX! However, I I know it's a pain to identify buttons, as boards vendors use different names.
@senthilr have you come across this situation with other examples apps?
I'd suggest pointing at the platform pages to find out where buttons are located:
https://developer.mbed.org/platforms
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one will not work straight out of the box, because the buttons were ENUMs... We need to figure out an alternative solution.