From f0f9fc2601dc3421aa3f4d9747748c3bee93f703 Mon Sep 17 00:00:00 2001 From: Mike Fiore Date: Thu, 12 Nov 2015 12:20:30 -0600 Subject: add class for handling button events - signals main thread when event occurs and main thread can check event - supports SW1 press, SW2 press, and SW1 hold --- ButtonHandler/ButtonHandler.h | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 ButtonHandler/ButtonHandler.h (limited to 'ButtonHandler/ButtonHandler.h') diff --git a/ButtonHandler/ButtonHandler.h b/ButtonHandler/ButtonHandler.h new file mode 100644 index 0000000..3eb8298 --- /dev/null +++ b/ButtonHandler/ButtonHandler.h @@ -0,0 +1,36 @@ +#ifndef __BUTTONHANDLER_H__ +#define __BUTTONHANDLER_H__ + +#include "mbed.h" +#include "rtos.h" + +#define buttonSignal (uint32_t)0x01 + +typedef enum { + none = 0, + sw1_press, + sw1_hold, + sw2_press +} ButtonEvent; + +class ButtonHandler { + public: + ButtonHandler(osThreadId main); + ~ButtonHandler(); + + ButtonEvent getButtonEvent(); + + private: + void sw1_fall(); + void sw1_rise(); + void sw2_fall(); + + osThreadId _main; + InterruptIn _sw1; + InterruptIn _sw2; + Timer _sw1_timer; + time_t _sw1_time; + ButtonEvent _event; +}; + +#endif -- cgit v1.2.3