From 7ed9889ef4ae52f753be9394dca44b0678c0c919 Mon Sep 17 00:00:00 2001 From: Armel FAUVEAU Date: Thu, 21 Mar 2024 03:16:34 +0100 Subject: [PATCH] Remove blink and SOS --- Makefile | 2 +- app/app.c | 6 ++- app/flashlight.c | 109 +++++++++++++++++++++++++++-------------------- app/flashlight.h | 20 +++++---- 4 files changed, 79 insertions(+), 58 deletions(-) diff --git a/Makefile b/Makefile index 412f224..efbd2b4 100644 --- a/Makefile +++ b/Makefile @@ -210,7 +210,7 @@ ifeq ($(ENABLE_FEAT_F4HWN),1) VERSION_STRING_1 ?= v0.22 AUTHOR_STRING_2 ?= F4HWN - VERSION_STRING_2 ?= v2.3 + VERSION_STRING_2 ?= v2.4 AUTHOR_STRING ?= $(AUTHOR_STRING_1)+$(AUTHOR_STRING_2) VERSION_STRING ?= $(VERSION_STRING_2) diff --git a/app/app.c b/app/app.c index c49c475..26dcac1 100644 --- a/app/app.c +++ b/app/app.c @@ -1303,8 +1303,10 @@ void APP_TimeSlice10ms(void) return; #endif -#ifdef ENABLE_FLASHLIGHT - FlashlightTimeSlice(); +#ifndef ENABLE_FEAT_F4HWN + #ifdef ENABLE_FLASHLIGHT + FlashlightTimeSlice(); + #endif #endif #ifdef ENABLE_VOX diff --git a/app/flashlight.c b/app/flashlight.c index 32c6c1a..9cb94b9 100644 --- a/app/flashlight.c +++ b/app/flashlight.c @@ -5,62 +5,79 @@ #include "flashlight.h" -enum FlashlightMode_t gFlashLightState; +#ifndef ENABLE_FEAT_F4HWN + enum FlashlightMode_t gFlashLightState; -void FlashlightTimeSlice() -{ - if (gFlashLightState == FLASHLIGHT_BLINK && (gFlashLightBlinkCounter & 15u) == 0) { - GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); - return; - } - - if (gFlashLightState == FLASHLIGHT_SOS) { - const uint16_t u = 15; - static uint8_t c; - static uint16_t next; - - if (gFlashLightBlinkCounter - next > 7 * u) { - c = 0; - next = gFlashLightBlinkCounter + 1; + void FlashlightTimeSlice() + { + if (gFlashLightState == FLASHLIGHT_BLINK && (gFlashLightBlinkCounter & 15u) == 0) { + GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); return; } - if (gFlashLightBlinkCounter == next) { - if (c==0) { - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); - } else { - GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + if (gFlashLightState == FLASHLIGHT_SOS) { + const uint16_t u = 15; + static uint8_t c; + static uint16_t next; + + if (gFlashLightBlinkCounter - next > 7 * u) { + c = 0; + next = gFlashLightBlinkCounter + 1; + return; } - if (c >= 18) { - next = gFlashLightBlinkCounter + 7 * u; - c = 0; - } else if(c==7 || c==9 || c==11) { - next = gFlashLightBlinkCounter + 3 * u; - } else { - next = gFlashLightBlinkCounter + u; + if (gFlashLightBlinkCounter == next) { + if (c==0) { + GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + } else { + GPIO_FlipBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + } + + if (c >= 18) { + next = gFlashLightBlinkCounter + 7 * u; + c = 0; + } else if(c==7 || c==9 || c==11) { + next = gFlashLightBlinkCounter + 3 * u; + } else { + next = gFlashLightBlinkCounter + u; + } + c++; } - c++; } } -} -void ACTION_FlashLight(void) -{ - switch (gFlashLightState) { - case FLASHLIGHT_OFF: - gFlashLightState++; - GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); - break; - case FLASHLIGHT_ON: - case FLASHLIGHT_BLINK: - gFlashLightState++; - break; - case FLASHLIGHT_SOS: - default: - gFlashLightState = 0; - GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + void ACTION_FlashLight(void) + { + switch (gFlashLightState) { + case FLASHLIGHT_OFF: + gFlashLightState++; + GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + break; + case FLASHLIGHT_ON: + case FLASHLIGHT_BLINK: + gFlashLightState++; + break; + case FLASHLIGHT_SOS: + default: + gFlashLightState = 0; + GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + } } -} +#else + void ACTION_FlashLight(void) + { + static bool gFlashLightState = false; + if(gFlashLightState) + { + GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + } + else + { + GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_FLASHLIGHT); + } + + gFlashLightState = (gFlashLightState) ? false : true; + } +#endif #endif diff --git a/app/flashlight.h b/app/flashlight.h index 61ada50..9c0a7c4 100644 --- a/app/flashlight.h +++ b/app/flashlight.h @@ -5,17 +5,19 @@ #include -enum FlashlightMode_t { - FLASHLIGHT_OFF = 0, - FLASHLIGHT_ON, - FLASHLIGHT_BLINK, - FLASHLIGHT_SOS -}; +#ifndef ENABLE_FEAT_F4HWN + enum FlashlightMode_t { + FLASHLIGHT_OFF = 0, + FLASHLIGHT_ON, + FLASHLIGHT_BLINK, + FLASHLIGHT_SOS + }; -extern enum FlashlightMode_t gFlashLightState; -extern volatile uint16_t gFlashLightBlinkCounter; + extern enum FlashlightMode_t gFlashLightState; + extern volatile uint16_t gFlashLightBlinkCounter; -void FlashlightTimeSlice(void); + void FlashlightTimeSlice(void); +#endif void ACTION_FlashLight(void); #endif