add splash speed and led brightness config (#74)

This commit is contained in:
Dien-Nhung Nguyen
2025-02-20 15:21:17 +07:00
committed by GitHub
parent 647e653d23
commit 6cb2f90805
6 changed files with 73 additions and 7 deletions

View File

@@ -19,7 +19,7 @@ badge_cfg_t badge_cfg;
/* In case of first time firmware upgrading */
void cfg_fallback()
{
badge_cfg.ble_always_on = 1;
badge_cfg.ble_always_on = 0;
memcpy(badge_cfg.ble_devname, "LED Badge Magic\0\0\0\0", 20);
/* OEM app testing: */
// memcpy(badge_cfg.ble_devname, "LSLED\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20);

View File

@@ -6,6 +6,8 @@
#include "xbm.h"
#include "leddrv.h"
#define SPLASH_MIN_SPEED_T (10) // ms
#define SPLASH_MAX_WIDTH (48) // pixels
#define SPLASH_MAX_HEIGHT (44) // pixels
#define SPLASH_MAX_SIZE (ALIGN_1BYTE(SPLASH_MAX_WIDTH) * SPLASH_MAX_HEIGHT)

View File

@@ -6,6 +6,8 @@
#define LED_COLS 44
#define LED_ROWS 11
#define BRIGHTNESS_LEVELS (4)
void led_init();
void leds_releaseall();
void led_write2dcol(int dcol, uint16_t col1_val, uint16_t col2_val);

View File

@@ -33,8 +33,6 @@ enum MODES {
MODES_COUNT,
};
#define BRIGHTNESS_LEVELS (4)
#define ANI_BASE_SPEED_T (200000) // uS
#define ANI_MARQUE_SPEED_T (100000) // uS
#define ANI_FLASH_SPEED_T (500000) // uS
@@ -52,12 +50,12 @@ enum MODES {
static tmosTaskID common_taskid = INVALID_TASK_ID ;
volatile uint16_t fb[LED_COLS] = {0};
volatile int mode, is_play_sequentially = 1, brightness = 0;
volatile int mode, is_play_sequentially = 1;
__HIGH_CODE
static void change_brightness()
{
NEXT_STATE(brightness, 0, BRIGHTNESS_LEVELS);
NEXT_STATE(badge_cfg.led_brightness, 0, BRIGHTNESS_LEVELS);
}
static void mode_setup_download();
@@ -471,7 +469,7 @@ void TMR0_IRQHandler(void)
i = 0;
led_write2dcol(i >> 2, fb[i >> 1], fb[(i >> 1) + 1]);
}
else if (state > (brightness&3))
else if (state > (badge_cfg.led_brightness&3))
leds_releaseall();
TMR0_ClearITFlag(TMR0_3_IT_CYC_END);

View File

@@ -7,6 +7,7 @@
#include "power.h"
#include "debug.h"
#include "config.h"
#include "leddrv.h"
// TODO: Some of configs can be added, just listing:
// - Remote brighness adjusting
@@ -127,6 +128,50 @@ uint8_t load_fallback_cfg(uint8_t *val, uint16_t len)
cfg_fallback(&badge_cfg);
return 0;
}
static uint8_t cfg_splash_speed(uint8_t *val, uint16_t len)
{
PRINT(__func__);
PRINT("\n");
uint16_t ms = *((uint16_t *)val);
if (ms < SPLASH_MIN_SPEED_T)
return -2;
badge_cfg.splash_speedT = ms;
return 0;
}
static uint8_t cfg_led_brightness(uint8_t *val, uint16_t len)
{
PRINT(__func__);
PRINT("\n");
uint8_t lvl = val[0];
if (lvl >= BRIGHTNESS_LEVELS)
return -2;
badge_cfg.led_brightness = lvl;
return 0;
}
uint8_t misc(uint8_t *val, uint16_t len)
{
PRINT(__func__);
PRINT("\n");
const uint8_t (*misc_cmd[])(uint8_t *, uint16_t) = {
cfg_splash_speed,
cfg_led_brightness,
};
uint8_t fn = val[0];
if (fn >= (sizeof(misc_cmd) / sizeof(misc_cmd[0])))
return -1;
return misc_cmd[fn](&val[1], len - 1);
}
/* TODO: add a way to read configs */
const uint8_t (*cmd_lut[])(uint8_t *val, uint16_t len) = {
next_packet, // Unsure if we need this
@@ -137,6 +182,7 @@ const uint8_t (*cmd_lut[])(uint8_t *val, uint16_t len) = {
flash_splash_screen,
save_cfg,
load_fallback_cfg,
misc,
};
#define CMD_LUT_LEN (sizeof(cmd_lut) / sizeof(cmd_lut[0]))