Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
HMI_Button.cpp
00001 #include "HMI.h" 00002 00003 using namespace FSM_Button; 00004 bool bouncing = false; 00005 bool trigger_standby = false; 00006 bool display_on = false; 00007 volatile bool RE_detected = false; 00008 bool next_screen = false; 00009 bool renew_screen = false; 00010 00011 #define DEBOUNCE_DURATION_MS 200 00012 #define HIGH_LEVEL_DURATION 2 00013 00014 /* 00015 Rising_edge flag is on ? Idle state => Debounce 00016 - Start chronometer 00017 */ 00018 unsigned int FSM_Button::button_idle(void) 00019 { 00020 if (!RE_detected) 00021 return FSM_Button::State_Idle; 00022 timer.start(); 00023 return FSM_Button::State_Debounce; 00024 } 00025 00026 /* 00027 timer < Wait Duration ? Debounce => Debounce. 00028 - All incoming button signals are ignored during this time. 00029 timer >= Wait Duration ? Debounce => Pressed 00030 */ 00031 unsigned int FSM_Button::button_debounce(void) 00032 { 00033 if (timer.read_ms() < DEBOUNCE_DURATION_MS) 00034 return FSM_Button::State_Debounce; 00035 return FSM_Button::State_Pressed; 00036 } 00037 /* 00038 button signal on high level ? Pressed => Pressed 00039 - timer > 2~5 s ? Trigger screen standby on. 00040 button signal on low level ? Pressed => Released 00041 - Change display 00042 */ 00043 00044 unsigned int FSM_Button::button_pressed(void) 00045 { 00046 if(button) { 00047 if(timer.read() >= HIGH_LEVEL_DURATION) 00048 trigger_standby = true; 00049 return FSM_Button::State_Pressed; 00050 } 00051 //led = 0; 00052 renew_screen = true; 00053 next_screen = true; 00054 return FSM_Button::State_Released; 00055 } 00056 00057 /* 00058 Released => Wait 00059 - Restart timer. 00060 - Initialize standby trigger flag. 00061 - Initialize rising edge detection flag. 00062 */ 00063 unsigned int FSM_Button::button_released(void) 00064 { 00065 RE_detected = false; 00066 trigger_standby = false; 00067 timer.reset(); 00068 return FSM_Button::State_Wait; 00069 } 00070 /* 00071 00072 timer < Wait Duration ? Wait => Wait. 00073 - All incoming button signals are ignored during this time. 00074 timer >= Wait Duration ? Wait => Idle 00075 - Stop and reset timer. 00076 */ 00077 unsigned int FSM_Button::button_wait(void) 00078 { 00079 if (timer.read_ms() < DEBOUNCE_DURATION_MS) 00080 return FSM_Button::State_Wait; 00081 timer.stop(); 00082 timer.reset(); 00083 return FSM_Button::State_Idle; 00084 }
Generated on Wed Aug 17 2022 05:29:14 by
 1.7.2