File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -72,9 +72,9 @@ int main(void) {
7272
7373
7474 // 2 second wait, debounced
75- if (!(GPIOA -> IDR & GPIO_IDR_ID13 )) {
75+ if (!(GPIOA -> IDR & ( 1 << PIN_13 ) )) {
7676 delayMs (DEBOUNCE_DELAY );
77- if (!(GPIOA -> IDR & GPIO_IDR_ID0 )) { // check again
77+ if (!(GPIOA -> IDR & ( 1 << PIN_13 ) )) { // check again
7878 // button pressed -> system bootloader
7979 resetToSystemBootLoader ();
8080 }
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ extern "C" {
99
1010extern bool button_pressed ;
1111
12- bool Button_IsPressed (uint32_t * duration_ms );
12+ bool Button_IsPressed ();
13+ uint32_t Button_IsPressedDuration ();
1314void Button_Tick ();
1415
1516#ifdef __cplusplus
Original file line number Diff line number Diff line change 11#include "button.h"
22
33#define DELAY_TIME_MS 10
4-
5- static uint32_t btnpress_duration = 0 ;
64bool button_pressed = false;
75
8- bool Button_IsPressed (uint32_t * duration_ms ) {
9- * duration_ms = 0 ;
10- if (HAL_GPIO_ReadPin (ENTER_BL_GPIO_Port , ENTER_BL_Pin ) == GPIO_PIN_RESET ) {
6+ bool Button_IsPressed () {
7+ return (HAL_GPIO_ReadPin (ENTER_BL_GPIO_Port , ENTER_BL_Pin ) == GPIO_PIN_RESET );
8+ }
9+
10+ uint32_t Button_IsPressedDuration () {
11+ uint32_t duration_ms = 0 ;
12+ if (Button_IsPressed ()) {
1113 // Measure duration of button press
12- while (HAL_GPIO_ReadPin ( ENTER_BL_GPIO_Port , ENTER_BL_Pin ) == GPIO_PIN_RESET ) {
14+ while (Button_IsPressed () ) {
1315 HAL_Delay (DELAY_TIME_MS );
14- * duration_ms += DELAY_TIME_MS ;
16+ duration_ms += DELAY_TIME_MS ;
1517 }
16- return true;
1718 }
18- return false ;
19+ return duration_ms ;
1920}
2021
2122void Button_Tick () {
22- if (Button_IsPressed (& btnpress_duration )) {
23- // Do something
24- }
23+ button_pressed = Button_IsPressed ();
2524}
Original file line number Diff line number Diff line change 22#include "u8g2.h"
33#include "postcodes.h"
44#include "bootloader.h"
5+ #include "button.h"
56
67#define OLED_Addr (0x3C << 1)
78#define DISPLAY_INIT_FUNC u8g2_Setup_ssd1306_i2c_64x32_1f_f
@@ -133,7 +134,6 @@ void Display_Init(void)
133134
134135 // Cleanup
135136 u8g2_ClearDisplay (& myDisplay );
136- Display_ShowCode (0x4242 , 0x71 );
137137}
138138
139139void Display_ShowCode (uint16_t code , uint8_t segment ) {
@@ -167,6 +167,8 @@ void Display_Tick(void)
167167 POST_ReadCode (),
168168 POST_ReadSegment ()
169169 );
170+ } else if (Button_IsPressed ()) {
171+ Display_Print ("BtnPress" );
170172 }
171173}
172174
You can’t perform that action at this time.
0 commit comments