Jim Flynn
/
button_class_and_test
Implementation of a button class and test program
main.cpp@1:c668e9604e63, 2018-09-07 (annotated)
- Committer:
- JMF
- Date:
- Fri Sep 07 20:54:25 2018 +0000
- Revision:
- 1:c668e9604e63
- Parent:
- 0:377a50b631cf
Added a destructor to the class.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JMF | 0:377a50b631cf | 1 | #include "mbed.h" |
JMF | 0:377a50b631cf | 2 | #include "Button.hpp" |
JMF | 0:377a50b631cf | 3 | |
JMF | 0:377a50b631cf | 4 | void br_callback(int dur) |
JMF | 0:377a50b631cf | 5 | { |
JMF | 0:377a50b631cf | 6 | printf("\r\n!! button RELEASE called, press time: %d msec\r\n", dur); |
JMF | 0:377a50b631cf | 7 | } |
JMF | 0:377a50b631cf | 8 | |
JMF | 0:377a50b631cf | 9 | void bp_callback(void) |
JMF | 0:377a50b631cf | 10 | { |
JMF | 0:377a50b631cf | 11 | printf("\r\n!! button PRESS called\r\n"); |
JMF | 0:377a50b631cf | 12 | } |
JMF | 0:377a50b631cf | 13 | |
JMF | 0:377a50b631cf | 14 | int main() { |
JMF | 0:377a50b631cf | 15 | int k, dur; |
JMF | 0:377a50b631cf | 16 | Button* button_ptr; |
JMF | 0:377a50b631cf | 17 | |
JMF | 0:377a50b631cf | 18 | printf("Testing button class\r\n"); |
JMF | 0:377a50b631cf | 19 | printf("Test Standard polling type implementation\r\n"); |
JMF | 0:377a50b631cf | 20 | button_ptr = new Button(USER_BUTTON, Button::ActiveHigh); |
JMF | 0:377a50b631cf | 21 | while( (k=button_ptr->chkButton_press(&dur)) == 0 ) |
JMF | 0:377a50b631cf | 22 | /* wait */; |
JMF | 0:377a50b631cf | 23 | printf(">Button pressed %d times, last was %d msec\r\n",k,dur); |
JMF | 0:377a50b631cf | 24 | delete button_ptr; |
JMF | 0:377a50b631cf | 25 | |
JMF | 0:377a50b631cf | 26 | printf("\nTest with Release callback\r\n"); |
JMF | 0:377a50b631cf | 27 | button_ptr = new Button(USER_BUTTON, Button::ActiveHigh, br_callback); |
JMF | 0:377a50b631cf | 28 | while( (k=button_ptr->chkButton_press(&dur)) == 0 ) |
JMF | 0:377a50b631cf | 29 | /* wait */; |
JMF | 0:377a50b631cf | 30 | printf(">Button pressed %d times, last was %d msec\r\n",k,dur); |
JMF | 0:377a50b631cf | 31 | delete button_ptr; |
JMF | 0:377a50b631cf | 32 | |
JMF | 0:377a50b631cf | 33 | printf("\nTest with Press & Release callback\r\n"); |
JMF | 0:377a50b631cf | 34 | button_ptr = new Button(USER_BUTTON, Button::ActiveHigh, br_callback); |
JMF | 0:377a50b631cf | 35 | button_ptr->setButton_press_cb(bp_callback); |
JMF | 0:377a50b631cf | 36 | while( (k=button_ptr->chkButton_press(&dur)) == 0 ) |
JMF | 0:377a50b631cf | 37 | /* wait */; |
JMF | 0:377a50b631cf | 38 | printf(">Button pressed %d times, last was %d msec\r\n",k,dur); |
JMF | 0:377a50b631cf | 39 | while (1) { |
JMF | 0:377a50b631cf | 40 | wait(.5); |
JMF | 0:377a50b631cf | 41 | } |
JMF | 0:377a50b631cf | 42 | |
JMF | 0:377a50b631cf | 43 | } |