PGO6_VoteController (Astrid Vanneste)
Fork of PGO6_VoteController_template by
debounce_button.h@5:ba94770ce1c7, 2018-10-08 (annotated)
- Committer:
- AstridVanneste
- Date:
- Mon Oct 08 15:39:22 2018 +0000
- Revision:
- 5:ba94770ce1c7
- Parent:
- 3:376ac6744373
mqtt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
jensdehoog | 0:fd29cd85e75e | 1 | #include "mbed.h" |
jensdehoog | 0:fd29cd85e75e | 2 | |
jensdehoog | 0:fd29cd85e75e | 3 | /** |
jensdehoog | 0:fd29cd85e75e | 4 | Due to the imperfect design of the buttons, a press on the button is registered multple times. |
jensdehoog | 0:fd29cd85e75e | 5 | The debouncer module makes sure that these false positives of the button are going to be ignored. |
jensdehoog | 0:fd29cd85e75e | 6 | |
jensdehoog | 0:fd29cd85e75e | 7 | Also, this module provides a multiclick service which allows the user to press the button multiple times |
jensdehoog | 0:fd29cd85e75e | 8 | within a certain time frame. Therefore, multiple actions can be mapped to a single button. |
jensdehoog | 0:fd29cd85e75e | 9 | |
jensdehoog | 0:fd29cd85e75e | 10 | */ |
jensdehoog | 0:fd29cd85e75e | 11 | |
AstridVanneste | 3:376ac6744373 | 12 | extern volatile bool button1_pressed; // Used in the main loop |
AstridVanneste | 3:376ac6744373 | 13 | extern volatile bool button1_enabled; // Used for debouncing |
AstridVanneste | 3:376ac6744373 | 14 | extern volatile int multiclick_state; // Counts how many clicks occured in the time slot, used in main loop |
AstridVanneste | 3:376ac6744373 | 15 | extern volatile bool button1_busy; // Informs the mainloop that the user is clicking the button => busy multiclick |
AstridVanneste | 3:376ac6744373 | 16 | extern volatile int internal_click_count; // Counts how many clicks occured in the time slot |
jensdehoog | 0:fd29cd85e75e | 17 | |
AstridVanneste | 5:ba94770ce1c7 | 18 | extern Timeout debounce_time; |
AstridVanneste | 5:ba94770ce1c7 | 19 | extern Timeout multiclick_time; |
AstridVanneste | 5:ba94770ce1c7 | 20 | |
AstridVanneste | 3:376ac6744373 | 21 | void button1_multiclick_reset_cb(void); // Resets the amount of clicks, but stores this value for the usage in the main loop |
AstridVanneste | 3:376ac6744373 | 22 | void button1_enabled_cb(void); // Enables the button again after a timeout, used for debouncing the button |
AstridVanneste | 3:376ac6744373 | 23 | void button1_onpressed_cb(void); // Callback which is called when the user presses the button |
AstridVanneste | 3:376ac6744373 | 24 | void init_debouncer(); |