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

@@ -75,9 +75,11 @@ The "mode" bytes are a combination of two 4 bit values. The high nibble describe
- Service-UUID: 0xF055 (128-bit equivalent: - Service-UUID: 0xF055 (128-bit equivalent:
0000f055-0000-1000-8000-00805f9b34fb) 0000f055-0000-1000-8000-00805f9b34fb)
- Characteristic: 0xF057 (128-bit equivalent:
0000f057-0000-1000-8000-00805f9b34fb)
- Write property: to receive controls and configs
- Characteristic: 0xF056 (128-bit equivalent: - Characteristic: 0xF056 (128-bit equivalent:
0000f056-0000-1000-8000-00805f9b34fb) 0000f056-0000-1000-8000-00805f9b34fb)
- Write property: to receive controls and configs
- Notify property: to return error codes - Notify property: to return error codes
- Read property: to be implemented - Read property: to be implemented
@@ -98,6 +100,7 @@ Supported functions/commands:
- flash_splash_screen - flash_splash_screen
- save_cfg - save_cfg
- load_fallback_cfg - load_fallback_cfg
- Miscellaneous configs
The client app should enable notifications for the characteristic to receive the The client app should enable notifications for the characteristic to receive the
returned error code (e.g., by using setCharacteristicNotification() on Android). returned error code (e.g., by using setCharacteristicNotification() on Android).
@@ -213,3 +216,18 @@ Function/Command code: `0x07`.
Returns: Returns:
- Success: `0x00`. - Success: `0x00`.
##### Miscellaneous configs
Function/Command code: `0x08`.
Parameters:
- Adjust splash screen speed: `[0x00, speed_ms]`. `speed_ms` (16-bit) is the delay of each frame in milliseconds and must not be lower than 10 ms.
- Adjust LED brightness: `[0x01, brightness_level]`. `brightness_level` has a value from 0 to 3.
Returns:
- Parameters out of range: `0xff`.
- `speed_ms` or `brightness_level` is out of allowed range: `0x02`.
- Success: `0x00`.

View File

@@ -19,7 +19,7 @@ badge_cfg_t badge_cfg;
/* In case of first time firmware upgrading */ /* In case of first time firmware upgrading */
void cfg_fallback() 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); memcpy(badge_cfg.ble_devname, "LED Badge Magic\0\0\0\0", 20);
/* OEM app testing: */ /* OEM app testing: */
// memcpy(badge_cfg.ble_devname, "LSLED\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20); // 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 "xbm.h"
#include "leddrv.h" #include "leddrv.h"
#define SPLASH_MIN_SPEED_T (10) // ms
#define SPLASH_MAX_WIDTH (48) // pixels #define SPLASH_MAX_WIDTH (48) // pixels
#define SPLASH_MAX_HEIGHT (44) // pixels #define SPLASH_MAX_HEIGHT (44) // pixels
#define SPLASH_MAX_SIZE (ALIGN_1BYTE(SPLASH_MAX_WIDTH) * SPLASH_MAX_HEIGHT) #define SPLASH_MAX_SIZE (ALIGN_1BYTE(SPLASH_MAX_WIDTH) * SPLASH_MAX_HEIGHT)

View File

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

View File

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

View File

@@ -7,6 +7,7 @@
#include "power.h" #include "power.h"
#include "debug.h" #include "debug.h"
#include "config.h" #include "config.h"
#include "leddrv.h"
// TODO: Some of configs can be added, just listing: // TODO: Some of configs can be added, just listing:
// - Remote brighness adjusting // - Remote brighness adjusting
@@ -127,6 +128,50 @@ uint8_t load_fallback_cfg(uint8_t *val, uint16_t len)
cfg_fallback(&badge_cfg); cfg_fallback(&badge_cfg);
return 0; 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 */ /* TODO: add a way to read configs */
const uint8_t (*cmd_lut[])(uint8_t *val, uint16_t len) = { const uint8_t (*cmd_lut[])(uint8_t *val, uint16_t len) = {
next_packet, // Unsure if we need this 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, flash_splash_screen,
save_cfg, save_cfg,
load_fallback_cfg, load_fallback_cfg,
misc,
}; };
#define CMD_LUT_LEN (sizeof(cmd_lut) / sizeof(cmd_lut[0])) #define CMD_LUT_LEN (sizeof(cmd_lut) / sizeof(cmd_lut[0]))