-
Notifications
You must be signed in to change notification settings - Fork 439
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c76a96c
commit 754d2ce
Showing
12 changed files
with
130 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,3 @@ void GUI_DisplayScreen(void); | |
void GUI_SelectNextDisplay(GUI_DisplayType_t Display); | ||
|
||
#endif | ||
|