Make Flashlight optional
This commit is contained in:
committed by
Krzysiek Egzmont
parent
c76a96c3ad
commit
754d2ce5fb
26
app/action.c
26
app/action.c
@@ -21,6 +21,9 @@
|
||||
#include "app/chFrScanner.h"
|
||||
#include "app/common.h"
|
||||
#include "app/dtmf.h"
|
||||
#ifdef ENABLE_FLASHLIGHT
|
||||
#include "app/flashlight.h"
|
||||
#endif
|
||||
#ifdef ENABLE_FMRADIO
|
||||
#include "app/fm.h"
|
||||
#endif
|
||||
@@ -39,25 +42,6 @@
|
||||
#include "ui/inputbox.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
static 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_Power(void)
|
||||
{
|
||||
if (++gTxVfo->OUTPUT_POWER > OUTPUT_POWER_HIGH)
|
||||
@@ -399,8 +383,10 @@ void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
case ACTION_OPT_NONE:
|
||||
break;
|
||||
case ACTION_OPT_FLASHLIGHT:
|
||||
#ifdef ENABLE_FLASHLIGHT
|
||||
ACTION_FlashLight();
|
||||
break;
|
||||
#endif
|
||||
break;
|
||||
case ACTION_OPT_POWER:
|
||||
ACTION_Power();
|
||||
break;
|
||||
|
@@ -19,7 +19,6 @@
|
||||
|
||||
#include "driver/keyboard.h"
|
||||
|
||||
//static void ACTION_FlashLight(void)
|
||||
void ACTION_Power(void);
|
||||
void ACTION_Monitor(void);
|
||||
void ACTION_Scan(bool bRestart);
|
||||
@@ -41,4 +40,3 @@ void ACTION_BlminTmpOff(void);
|
||||
void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
|
||||
|
||||
#endif
|
||||
|
||||
|
74
app/app.c
74
app/app.c
@@ -25,6 +25,9 @@
|
||||
#include "app/app.h"
|
||||
#include "app/chFrScanner.h"
|
||||
#include "app/dtmf.h"
|
||||
#ifdef ENABLE_FLASHLIGHT
|
||||
#include "app/flashlight.h"
|
||||
#endif
|
||||
#ifdef ENABLE_FMRADIO
|
||||
#include "app/fm.h"
|
||||
#endif
|
||||
@@ -67,7 +70,8 @@
|
||||
#include "debugging.h"
|
||||
|
||||
static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);
|
||||
static void FlashlightTimeSlice();
|
||||
|
||||
|
||||
|
||||
static void CheckForIncoming(void)
|
||||
{
|
||||
@@ -1142,10 +1146,10 @@ void APP_TimeSlice10ms(void)
|
||||
|
||||
if (gCurrentFunction == FUNCTION_TRANSMIT)
|
||||
{ // transmitting
|
||||
#ifdef ENABLE_AUDIO_BAR
|
||||
if (gSetting_mic_bar && (gFlashLightBlinkCounter % (150 / 10)) == 0) // once every 150ms
|
||||
UI_DisplayAudioBar();
|
||||
#endif
|
||||
#ifdef ENABLE_AUDIO_BAR
|
||||
if (gSetting_mic_bar && (gFlashLightBlinkCounter % (150 / 10)) == 0) // once every 150ms
|
||||
UI_DisplayAudioBar();
|
||||
#endif
|
||||
}
|
||||
|
||||
if (gUpdateDisplay)
|
||||
@@ -1159,20 +1163,22 @@ void APP_TimeSlice10ms(void)
|
||||
|
||||
// Skipping authentic device checks
|
||||
|
||||
#ifdef ENABLE_FMRADIO
|
||||
if (gFmRadioMode && gFmRadioCountdown_500ms > 0) // 1of11
|
||||
return;
|
||||
#endif
|
||||
#ifdef ENABLE_FMRADIO
|
||||
if (gFmRadioMode && gFmRadioCountdown_500ms > 0) // 1of11
|
||||
return;
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FLASHLIGHT
|
||||
FlashlightTimeSlice();
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_VOX
|
||||
if (gVoxResumeCountdown > 0)
|
||||
gVoxResumeCountdown--;
|
||||
#ifdef ENABLE_VOX
|
||||
if (gVoxResumeCountdown > 0)
|
||||
gVoxResumeCountdown--;
|
||||
|
||||
if (gVoxPauseCountdown > 0)
|
||||
gVoxPauseCountdown--;
|
||||
#endif
|
||||
if (gVoxPauseCountdown > 0)
|
||||
gVoxPauseCountdown--;
|
||||
#endif
|
||||
|
||||
if (gCurrentFunction == FUNCTION_TRANSMIT)
|
||||
{
|
||||
@@ -2036,41 +2042,3 @@ Skip:
|
||||
|
||||
gUpdateDisplay = true;
|
||||
}
|
||||
|
||||
static 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;
|
||||
return;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
66
app/flashlight.c
Normal file
66
app/flashlight.c
Normal file
@@ -0,0 +1,66 @@
|
||||
#ifdef ENABLE_FLASHLIGHT
|
||||
|
||||
#include "driver/gpio.h"
|
||||
#include "bsp/dp32g030/gpio.h"
|
||||
|
||||
#include "flashlight.h"
|
||||
|
||||
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;
|
||||
return;
|
||||
}
|
||||
|
||||
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++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
23
app/flashlight.h
Normal file
23
app/flashlight.h
Normal file
@@ -0,0 +1,23 @@
|
||||
#ifndef APP_FLASHLIGHT_H
|
||||
#define APP_FLASHLIGHT_H
|
||||
|
||||
#ifdef ENABLE_FLASHLIGHT
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
enum FlashlightMode_t {
|
||||
FLASHLIGHT_OFF = 0,
|
||||
FLASHLIGHT_ON,
|
||||
FLASHLIGHT_BLINK,
|
||||
FLASHLIGHT_SOS
|
||||
};
|
||||
|
||||
extern enum FlashlightMode_t gFlashLightState;
|
||||
extern volatile uint16_t gFlashLightBlinkCounter;
|
||||
|
||||
void FlashlightTimeSlice(void);
|
||||
void ACTION_FlashLight(void);
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
Reference in New Issue
Block a user