Jim Flynn / Mbed OS button_class_and_test
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Button.hpp"
00003 
00004 void br_callback(int dur)
00005 {
00006     printf("\r\n!! button RELEASE called, press time: %d msec\r\n", dur);
00007 }
00008 
00009 void bp_callback(void)
00010 {
00011     printf("\r\n!! button PRESS called\r\n");
00012 }
00013 
00014 int main() {
00015     int k, dur;
00016     Button* button_ptr;
00017     
00018     printf("Testing button class\r\n");
00019     printf("Test Standard polling type implementation\r\n");
00020     button_ptr = new Button(USER_BUTTON, Button::ActiveHigh);
00021     while( (k=button_ptr->chkButton_press(&dur)) == 0 )
00022         /* wait */;
00023     printf(">Button pressed %d times, last was %d msec\r\n",k,dur);
00024     delete button_ptr;
00025     
00026     printf("\nTest with Release callback\r\n");
00027     button_ptr = new Button(USER_BUTTON, Button::ActiveHigh, br_callback);
00028     while( (k=button_ptr->chkButton_press(&dur)) == 0 )
00029         /* wait */;
00030     printf(">Button pressed %d times, last was %d msec\r\n",k,dur);
00031     delete button_ptr;
00032         
00033     printf("\nTest with Press & Release callback\r\n");
00034     button_ptr = new Button(USER_BUTTON, Button::ActiveHigh, br_callback);
00035     button_ptr->setButton_press_cb(bp_callback);
00036     while( (k=button_ptr->chkButton_press(&dur)) == 0 )
00037         /* wait */;
00038     printf(">Button pressed %d times, last was %d msec\r\n",k,dur);
00039     while (1) {
00040         wait(.5);
00041     }
00042 
00043 }