changeset 152:bc7795161549 FlipDisplay

Moved button evaluation out of interrupt handler
author Ideenmodellierer
date Sun, 03 Mar 2019 12:18:44 +0100
parents a98f91cca107
children 791cdfad0c8e
files Discovery/Src/base.c
diffstat 1 files changed, 123 insertions(+), 141 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/base.c	Sun Mar 03 12:16:54 2019 +0100
+++ b/Discovery/Src/base.c	Sun Mar 03 12:18:44 2019 +0100
@@ -253,7 +253,7 @@
 //#define BUFFER_SIZE         ((uint32_t)0x00177000)
 //#define WRITE_READ_ADDR     ((uint32_t)0x0000)
 #define REFRESH_COUNT       ((uint32_t)0x0569)   /**< for SDRAM refresh counter (90Mhz SD clock) */
-
+#define INVALID_BUTTON ((uint8_t) 0xFF)
 /* Private macro -------------------------------------------------------------*/
 /* Private variables ---------------------------------------------------------*/
 
@@ -262,6 +262,9 @@
 TIM_HandleTypeDef   TimBacklightHandle; /* used in stm32f4xx_it.c too */
 TIM_HandleTypeDef   TimDemoHandle; /* used in stm32f4xx_it.c too */
 
+uint8_t LastButtonPressed;
+uint32_t LastButtonPressedTick;
+
 /*
 uint32_t time_before;
 uint32_t time_between;
@@ -290,7 +293,6 @@
 uint8_t	wasFirmwareUpdateCheckBattery = 0;
 
 /* Private function prototypes -----------------------------------------------*/
-
 static void SystemClock_Config(void);
 static void Error_Handler(void);
 static void SDRAM_Initialization_Sequence(SDRAM_HandleTypeDef *hsdram, FMC_SDRAM_CommandTypeDef *Command);
@@ -302,6 +304,7 @@
 static void gotoSleep(void);
 static void deco_loop(void);
 static void resetToFirmwareUpdate(void);
+void EvaluateButton(void);
 
 /* ITM Trace-------- ---------------------------------------------------------*/
 /*
@@ -347,6 +350,7 @@
 
 
     set_globalState( StBoot0 );
+    LastButtonPressed = 0;
 
     HAL_Init();
     HAL_NVIC_SetPriorityGrouping( NVIC_PRIORITYGROUP_2 );
@@ -491,6 +495,7 @@
             ext_flash_write_settings();
         }
         deco_loop();
+        EvaluateButton();
 
 #ifdef DEBUG_RUNTIME
         translateTime(stateUsed->lifeData.timeBinaryFormat, &Stime);
@@ -792,9 +797,6 @@
 	if (!GPIO_Pin)
 		return;
 
-	uint8_t action = 0;
-	SStateList status;
-
 	if (GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten
 	{
 		GFX_change_LTDC();
@@ -814,26 +816,8 @@
 		return;
 	}
 	
-	SSettings* pSettings;
-	pSettings = settingsGetPointer();
-	if (GPIO_Pin == VSYNC_IRQ_PIN) // rechts, unten
-	{
-		GFX_change_LTDC();
-		housekeepingFrame();
-		/*
-		 #ifdef DEMOMODE
-		 static uint8_t countCall = 0;
-		 if(countCall++ < 10)
-		 return;
-		 countCall = 0;
-		 uint8_t buttonAction = demoGetCommand();
-		 if(buttonAction)
-		 GPIO_Pin = buttonAction;
-		 else
-		 #endif
-		 */
-		return;
-	}
+	LastButtonPressed = GPIO_Pin;
+	LastButtonPressedTick = HAL_GetTick();
 
 #ifdef DEMOMODE
 	uint8_t demoMachineCall = 0;
@@ -843,143 +827,141 @@
 		GPIO_Pin &= 0x7F;
 	}
 #endif
+}
 
-	time_without_button_pressed_deciseconds = 0;
+void EvaluateButton()
+{
+	uint8_t action = 0;
+	SStateList status;
+	SSettings* pSettings;
+	pSettings = settingsGetPointer();
 
 	if (GFX_logoStatus() != 0)
 		return;
 
-	if (GPIO_Pin == BUTTON_BACK_PIN) { // links
-		HAL_Delay(BUTTON_DEBOUNCE_DELAY);
-		if (HAL_GPIO_ReadPin(BUTTON_BACK_GPIO_PORT, BUTTON_BACK_PIN) == 1) {
-			action = ACTION_BUTTON_BACK;
+	if ((LastButtonPressed != INVALID_BUTTON) && (time_elapsed_ms(LastButtonPressedTick, HAL_GetTick())) > 50)
+	{
+		if (LastButtonPressed == BUTTON_BACK_PIN) { // links
+			if (HAL_GPIO_ReadPin(BUTTON_BACK_GPIO_PORT, BUTTON_BACK_PIN) == 1) {
+				action = ACTION_BUTTON_BACK;
+			}
 		}
-	}
-
-	else if (GPIO_Pin == BUTTON_ENTER_PIN) { // mitte
-		HAL_Delay(BUTTON_DEBOUNCE_DELAY);
-		if (HAL_GPIO_ReadPin(BUTTON_ENTER_GPIO_PORT, BUTTON_ENTER_PIN) == 1) {
-			action = ACTION_BUTTON_ENTER;
-		}
-	}
-
-	else if (GPIO_Pin == BUTTON_NEXT_PIN) { // rechts
-		HAL_Delay(BUTTON_DEBOUNCE_DELAY);
-		if (HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN) == 1) {
-			action = ACTION_BUTTON_NEXT;
-		}
-	}
 
-    if(GPIO_Pin == BUTTON_BACK_PIN) // links
-    {
-    	if(!pSettings->FlipDisplay)
-    	{
-    		action = ACTION_BUTTON_BACK;
-    	}
-    	else
-    	{
-    		action = ACTION_BUTTON_NEXT;
-    	}
-    }
-    else
-    {
-		if(GPIO_Pin == BUTTON_ENTER_PIN) // mitte
-			action = ACTION_BUTTON_ENTER;
-		else
-		{
-			if(GPIO_Pin == BUTTON_NEXT_PIN) // rechts
-			{
-				if(!pSettings->FlipDisplay)	action = ACTION_BUTTON_NEXT;
-				 else action = ACTION_BUTTON_BACK;
+		else if (LastButtonPressed == BUTTON_ENTER_PIN) { // mitte
+			if (HAL_GPIO_ReadPin(BUTTON_ENTER_GPIO_PORT, BUTTON_ENTER_PIN) == 1) {
+				action = ACTION_BUTTON_ENTER;
+			}
+		}
+
+		else if (LastButtonPressed == BUTTON_NEXT_PIN) { // rechts
+			if (HAL_GPIO_ReadPin(BUTTON_NEXT_GPIO_PORT, BUTTON_NEXT_PIN) == 1) {
+				action = ACTION_BUTTON_NEXT;
 			}
 		}
-    }
-	#ifdef BUTTON_CUSTOM_PIN
-		else
-		if(GPIO_Pin == BUTTON_CUSTOM_PIN) // extra
-			action = ACTION_BUTTON_CUSTOM;
-	#endif
 
-#ifdef DEMOMODE // user pressed button ?
-	if((!demoMachineCall) && demoModeActive())
-	{
-		demoSendCommand(action);
-		return;
-	}
+		if(action != 0)
+		{
+			time_without_button_pressed_deciseconds = 0;
+			if(pSettings->FlipDisplay) /* switch action resulting from pressed button */
+			{
+				if (action == ACTION_BUTTON_BACK)
+				{
+					action = ACTION_BUTTON_NEXT;
+				}
+				if (action == ACTION_BUTTON_NEXT)
+				{
+					action = ACTION_BUTTON_BACK;
+				}
+			}
+		}
+
+#ifdef BUTTON_CUSTOM_PIN
+		else
+		if(LastButtonPressed == BUTTON_CUSTOM_PIN) // extra
+				action = ACTION_BUTTON_CUSTOM;
 #endif
 
-	get_globalStateList(&status);
+	#ifdef DEMOMODE // user pressed button ?
+		if((!demoMachineCall) && demoModeActive())
+		{
+			demoSendCommand(action);
+			return;
+		}
+	#endif
 
-	if (action == ACTION_BUTTON_CUSTOM) {
-		GFX_screenshot();
-	}
+		get_globalStateList(&status);
+
+		if (action == ACTION_BUTTON_CUSTOM) {
+			GFX_screenshot();
+		}
 
-	switch (status.base) {
-	case BaseStop:
-		if (action == ACTION_BUTTON_BACK)
-			resetToFirmwareUpdate();
-		break;
-	case BaseComm:
-		if (action == ACTION_BUTTON_BACK) {
-			settingsGetPointer()->bluetoothActive = 0;
-			MX_Bluetooth_PowerOff();
-			tComm_exit();
-		}
-		break;
-	case BaseHome:
-		if (action == ACTION_BUTTON_NEXT) {
-			if (status.page == PageSurface)
-				openMenu(1);
+		switch (status.base) {
+		case BaseStop:
+			if (action == ACTION_BUTTON_BACK)
+				resetToFirmwareUpdate();
+			break;
+		case BaseComm:
+			if (action == ACTION_BUTTON_BACK) {
+				settingsGetPointer()->bluetoothActive = 0;
+				MX_Bluetooth_PowerOff();
+				tComm_exit();
+			}
+			break;
+		case BaseHome:
+			if (action == ACTION_BUTTON_NEXT) {
+				if (status.page == PageSurface)
+					openMenu(1);
+				else
+					tHomeDiveMenuControl(action);
+			} else if (action == ACTION_BUTTON_BACK) {
+				if (get_globalState() == StS)
+					openInfo(StILOGLIST);
+				else if ((status.page == PageDive)
+						&& (settingsGetPointer()->design < 7)) {
+					settingsGetPointer()->design = 7; // auto switch to 9 if necessary
+				} else if ((status.page == PageDive) && (status.line != 0)) {
+					if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT)
+						settingsGetPointer()->design = 3;
+					else if (settingsGetPointer()->extraDisplay
+							== EXTRADISPLAY_DECOGAME)
+						settingsGetPointer()->design = 4;
+
+					set_globalState(StD);
+				} else
+					tHome_change_field_button_pressed();
+			} else if (action == ACTION_BUTTON_ENTER) {
+				if ((status.page == PageDive) && (status.line == 0))
+					tHome_change_customview_button_pressed();
+				else if (status.page == PageSurface)
+					tHome_change_customview_button_pressed();
+				else
+					tHomeDiveMenuControl(action);
+			}
+			break;
+
+		case BaseMenu:
+			if (status.line == 0)
+				sendActionToMenu(action);
 			else
-				tHomeDiveMenuControl(action);
-		} else if (action == ACTION_BUTTON_BACK) {
-			if (get_globalState() == StS)
-				openInfo(StILOGLIST);
-			else if ((status.page == PageDive)
-					&& (settingsGetPointer()->design < 7)) {
-				settingsGetPointer()->design = 7; // auto switch to 9 if necessary
-			} else if ((status.page == PageDive) && (status.line != 0)) {
-				if (settingsGetPointer()->extraDisplay == EXTRADISPLAY_BIGFONT)
-					settingsGetPointer()->design = 3;
-				else if (settingsGetPointer()->extraDisplay
-						== EXTRADISPLAY_DECOGAME)
-					settingsGetPointer()->design = 4;
+				sendActionToMenuEdit(action);
+			break;
 
-				set_globalState(StD);
-			} else
-				tHome_change_field_button_pressed();
-		} else if (action == ACTION_BUTTON_ENTER) {
-			if ((status.page == PageDive) && (status.line == 0))
-				tHome_change_customview_button_pressed();
-			else if (status.page == PageSurface)
-				tHome_change_customview_button_pressed();
+		case BaseInfo:
+			if (status.page == InfoPageLogList)
+				sendActionToInfoLogList(action);
+			else if (status.page == InfoPageLogShow)
+				sendActionToInfoLogShow(action);
 			else
-				tHomeDiveMenuControl(action);
-		}
-		break;
-
-	case BaseMenu:
-		if (status.line == 0)
-			sendActionToMenu(action);
-		else
-			sendActionToMenuEdit(action);
-		break;
+				sendActionToInfo(action);
+			break;
 
-	case BaseInfo:
-		if (status.page == InfoPageLogList)
-			sendActionToInfoLogList(action);
-		else if (status.page == InfoPageLogShow)
-			sendActionToInfoLogShow(action);
-		else
-			sendActionToInfo(action);
-		break;
-
-	default:
-		break;
+		default:
+			break;
+		}
+		LastButtonPressed = INVALID_BUTTON;
 	}
 }
 
-
 void gotoSleep(void)
 {
     /* not at the moment of testing */