Skip to content

Commit

Permalink
Make Flashlight optional
Browse files Browse the repository at this point in the history
  • Loading branch information
JuantAldea authored and egzumer committed Dec 6, 2023
1 parent c76a96c commit 754d2ce
Show file tree
Hide file tree
Showing 12 changed files with 130 additions and 87 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ENABLE_ALARM := 0
ENABLE_TX1750 := 0
ENABLE_PWRON_PASSWORD := 0
ENABLE_DTMF_CALLING := 1
ENABLE_FLASHLIGHT := 1

# ---- CUSTOM MODS ----
ENABLE_BIG_FREQ := 1
Expand Down Expand Up @@ -113,6 +114,9 @@ OBJS += app/app.o
OBJS += app/chFrScanner.o
OBJS += app/common.o
OBJS += app/dtmf.o
ifeq ($(ENABLE_FLASHLIGHT),1)
OBJS += app/flashlight.o
endif
ifeq ($(ENABLE_FMRADIO),1)
OBJS += app/fm.o
endif
Expand Down Expand Up @@ -363,6 +367,9 @@ endif
ifeq ($(ENABLE_AGC_SHOW_DATA),1)
CFLAGS += -DENABLE_AGC_SHOW_DATA
endif
ifeq ($(ENABLE_FLASHLIGHT),1)
CFLAGS += -DENABLE_FLASHLIGHT
endif

LDFLAGS =
LDFLAGS += -z noexecstack -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld -Wl,--gc-sections
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ ENABLE_ALARM := 0 TX alarms
ENABLE_TX1750 := 0 side key 1750Hz TX tone (older style repeater access)
ENABLE_PWRON_PASSWORD := 0 power-on password stuff
ENABLE_DTMF_CALLING := 1 DTMF calling fuctionality, sending calls, receiving calls, group calls, contacts list etc.
ENABLE_FLASHLIGHT := 1 enable top flashlight LED (on, blink, SOS)
ENABLE_BIG_FREQ := 1 big font frequencies (like original QS firmware)
ENABLE_SMALL_BOLD := 1 bold channel name/no. (when name + freq channel display mode)
Expand Down
26 changes: 6 additions & 20 deletions app/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions app/action.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -41,4 +40,3 @@ void ACTION_BlminTmpOff(void);
void ACTION_Handle(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld);

#endif

74 changes: 21 additions & 53 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
Expand All @@ -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)
{
Expand Down Expand Up @@ -2036,41 +2042,3 @@ static void ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)

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 changes: 66 additions & 0 deletions app/flashlight.c
Original file line number Diff line number Diff line change
@@ -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 changes: 23 additions & 0 deletions app/flashlight.h
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,8 @@ bool g_CxCSS_TAIL_Found;
#endif
bool g_SquelchLost;

enum FlashlightMode_t gFlashLightState;

volatile uint16_t gFlashLightBlinkCounter;

bool gFlagEndTransmission;
uint8_t gNextMrChannel;
ReceptionMode_t gRxReceptionMode;
Expand Down
10 changes: 2 additions & 8 deletions misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ enum {
LAST_CHANNEL
};

enum FlashlightMode_t {
FLASHLIGHT_OFF = 0,
FLASHLIGHT_ON,
FLASHLIGHT_BLINK,
FLASHLIGHT_SOS
};

enum {
VFO_CONFIGURE_NONE = 0,
VFO_CONFIGURE,
Expand Down Expand Up @@ -285,8 +278,9 @@ extern bool g_CxCSS_TAIL_Found;

// true means we are receiving signal
extern bool g_SquelchLost;
extern enum FlashlightMode_t gFlashLightState;

extern volatile uint16_t gFlashLightBlinkCounter;

extern bool gFlagEndTransmission;
extern uint8_t gNextMrChannel;
extern ReceptionMode_t gRxReceptionMode;
Expand Down
2 changes: 1 addition & 1 deletion settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void SETTINGS_InitEEPROM(void)
gEeprom.BEEP_CONTROL = Data[0] & 1;
gEeprom.KEY_M_LONG_PRESS_ACTION = ((Data[0] >> 1) < ACTION_OPT_LEN) ? (Data[0] >> 1) : ACTION_OPT_NONE;
gEeprom.KEY_1_SHORT_PRESS_ACTION = (Data[1] < ACTION_OPT_LEN) ? Data[1] : ACTION_OPT_MONITOR;
gEeprom.KEY_1_LONG_PRESS_ACTION = (Data[2] < ACTION_OPT_LEN) ? Data[2] : ACTION_OPT_FLASHLIGHT;
gEeprom.KEY_1_LONG_PRESS_ACTION = (Data[2] < ACTION_OPT_LEN) ? Data[2] : ACTION_OPT_NONE;
gEeprom.KEY_2_SHORT_PRESS_ACTION = (Data[3] < ACTION_OPT_LEN) ? Data[3] : ACTION_OPT_SCAN;
gEeprom.KEY_2_LONG_PRESS_ACTION = (Data[4] < ACTION_OPT_LEN) ? Data[4] : ACTION_OPT_NONE;
gEeprom.SCAN_RESUME_MODE = (Data[5] < 3) ? Data[5] : SCAN_RESUME_CO;
Expand Down
2 changes: 2 additions & 0 deletions ui/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,9 @@ const char gSubMenu_SCRAMBLER[][7] =
const t_sidefunction SIDEFUNCTIONS[] =
{
{"NONE", ACTION_OPT_NONE},
#ifdef ENABLE_FLASHLIGHT
{"FLASH\nLIGHT", ACTION_OPT_FLASHLIGHT},
#endif
{"POWER", ACTION_OPT_POWER},
{"MONITOR", ACTION_OPT_MONITOR},
{"SCAN", ACTION_OPT_SCAN},
Expand Down
1 change: 0 additions & 1 deletion ui/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,3 @@ void GUI_DisplayScreen(void);
void GUI_SelectNextDisplay(GUI_DisplayType_t Display);

#endif

0 comments on commit 754d2ce

Please sign in to comment.