Skip to content
This repository was archived by the owner on Apr 24, 2019. It is now read-only.

Commit 7e5df8e

Browse files
author
Janne Kiiskilä
committed
Improved button support
Modify the main.cpp to understand the new "abstract" buttons in mbed OS. Prevoius buttons were applicable only to K64F, but since mbed OS has BUTTON1 and BUTTON2, you can check for those in a board independent manner.
1 parent 4655548 commit 7e5df8e

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

main.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -66,18 +66,22 @@ struct MbedClientDevice device = {
6666
MbedClient mbed_client(device);
6767

6868

69-
// In case of K64F board , there is button resource available
70-
// to change resource value and unregister
71-
#ifdef TARGET_K64F
69+
// If board has a button_1, use it to update the counter.
70+
#ifdef BUTTON1
7271
// Set up Hardware interrupt button.
73-
InterruptIn obs_button(SW2);
74-
InterruptIn unreg_button(SW3);
75-
#else
72+
InterruptIn obs_button(BUTTON1);
73+
#else // BUTTON1
7674
//In non K64F boards , set up a timer to simulate updating resource,
7775
// there is no functionality to unregister.
7876
Ticker timer;
7977
#endif
8078

79+
// If the board has a 2nd button - hook the unregistration to that.
80+
#ifdef BUTTON2
81+
InterruptIn unreg_button(BUTTON2);
82+
#endif // BUTTON2
83+
84+
8185
/*
8286
* Arguments for running "blink" in it's own thread.
8387
*/
@@ -242,11 +246,11 @@ class ButtonResource {
242246

243247
// up counter
244248
counter++;
245-
#ifdef TARGET_K64F
249+
#ifdef BUTTON1
246250
printf("handle_button_click, new value of counter is %d\n", counter);
247251
#else
248252
printf("simulate button_click, new value of counter is %d\n", counter);
249-
#endif
253+
#endif // BUTTON1
250254
// serialize the value of counter as a string, and tell connector
251255
char buffer[20];
252256
int size = sprintf(buffer,"%d",counter);
@@ -373,18 +377,20 @@ Add MBEDTLS_NO_DEFAULT_ENTROPY_SOURCES and MBEDTLS_TEST_NULL_ENTROPY in mbed_app
373377
LedResource led_resource;
374378
BigPayloadResource big_payload_resource;
375379
376-
#ifdef TARGET_K64F
377-
// On press of SW3 button on K64F board, example application
380+
#ifdef BUTTON2
381+
// On press 2nd button (boards that have it), example application
378382
// will call unregister API towards mbed Device Connector
379383
//unreg_button.fall(&mbed_client,&MbedClient::test_unregister);
380384
unreg_button.fall(&unregister);
385+
#endif // BUTTON2
381386
382-
// Observation Button (SW2) press will send update of endpoint resource values to connector
387+
#ifdef BUTTON1
388+
// 1st button - observation button press will send update of endpoint resource values to connector
383389
obs_button.fall(&button_clicked);
384390
#else
385391
// Send update of endpoint resource values to connector every 15 seconds periodically
386392
timer.attach(&button_clicked, 15.0);
387-
#endif
393+
#endif // BUTTON1
388394
389395
// Create endpoint interface to manage register and unregister
390396
mbed_client.create_interface(MBED_SERVER_ADDRESS, network);

0 commit comments

Comments
 (0)