Skip to content

Commit 6cb2f90

Browse files
authored
add splash speed and led brightness config (#74)
1 parent 647e653 commit 6cb2f90

File tree

6 files changed

+73
-7
lines changed

6 files changed

+73
-7
lines changed

BadgeBLE.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,11 @@ The "mode" bytes are a combination of two 4 bit values. The high nibble describe
7575

7676
- Service-UUID: 0xF055 (128-bit equivalent:
7777
0000f055-0000-1000-8000-00805f9b34fb)
78+
- Characteristic: 0xF057 (128-bit equivalent:
79+
0000f057-0000-1000-8000-00805f9b34fb)
80+
- Write property: to receive controls and configs
7881
- Characteristic: 0xF056 (128-bit equivalent:
7982
0000f056-0000-1000-8000-00805f9b34fb)
80-
- Write property: to receive controls and configs
8183
- Notify property: to return error codes
8284
- Read property: to be implemented
8385

@@ -98,6 +100,7 @@ Supported functions/commands:
98100
- flash_splash_screen
99101
- save_cfg
100102
- load_fallback_cfg
103+
- Miscellaneous configs
101104

102105
The client app should enable notifications for the characteristic to receive the
103106
returned error code (e.g., by using setCharacteristicNotification() on Android).
@@ -213,3 +216,18 @@ Function/Command code: `0x07`.
213216
Returns:
214217

215218
- Success: `0x00`.
219+
220+
##### Miscellaneous configs
221+
222+
Function/Command code: `0x08`.
223+
224+
Parameters:
225+
226+
- 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.
227+
- Adjust LED brightness: `[0x01, brightness_level]`. `brightness_level` has a value from 0 to 3.
228+
229+
Returns:
230+
231+
- Parameters out of range: `0xff`.
232+
- `speed_ms` or `brightness_level` is out of allowed range: `0x02`.
233+
- Success: `0x00`.

src/config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ badge_cfg_t badge_cfg;
1919
/* In case of first time firmware upgrading */
2020
void cfg_fallback()
2121
{
22-
badge_cfg.ble_always_on = 1;
22+
badge_cfg.ble_always_on = 0;
2323
memcpy(badge_cfg.ble_devname, "LED Badge Magic\0\0\0\0", 20);
2424
/* OEM app testing: */
2525
// memcpy(badge_cfg.ble_devname, "LSLED\0\0\0\0\0\0\0\0\0\0\0\0\0\0", 20);

src/config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#include "xbm.h"
77
#include "leddrv.h"
88

9+
#define SPLASH_MIN_SPEED_T (10) // ms
10+
911
#define SPLASH_MAX_WIDTH (48) // pixels
1012
#define SPLASH_MAX_HEIGHT (44) // pixels
1113
#define SPLASH_MAX_SIZE (ALIGN_1BYTE(SPLASH_MAX_WIDTH) * SPLASH_MAX_HEIGHT)

src/leddrv.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
#define LED_COLS 44
77
#define LED_ROWS 11
88

9+
#define BRIGHTNESS_LEVELS (4)
10+
911
void led_init();
1012
void leds_releaseall();
1113
void led_write2dcol(int dcol, uint16_t col1_val, uint16_t col2_val);

src/main.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ enum MODES {
3333
MODES_COUNT,
3434
};
3535

36-
#define BRIGHTNESS_LEVELS (4)
37-
3836
#define ANI_BASE_SPEED_T (200000) // uS
3937
#define ANI_MARQUE_SPEED_T (100000) // uS
4038
#define ANI_FLASH_SPEED_T (500000) // uS
@@ -52,12 +50,12 @@ enum MODES {
5250
static tmosTaskID common_taskid = INVALID_TASK_ID ;
5351

5452
volatile uint16_t fb[LED_COLS] = {0};
55-
volatile int mode, is_play_sequentially = 1, brightness = 0;
53+
volatile int mode, is_play_sequentially = 1;
5654

5755
__HIGH_CODE
5856
static void change_brightness()
5957
{
60-
NEXT_STATE(brightness, 0, BRIGHTNESS_LEVELS);
58+
NEXT_STATE(badge_cfg.led_brightness, 0, BRIGHTNESS_LEVELS);
6159
}
6260

6361
static void mode_setup_download();
@@ -471,7 +469,7 @@ void TMR0_IRQHandler(void)
471469
i = 0;
472470
led_write2dcol(i >> 2, fb[i >> 1], fb[(i >> 1) + 1]);
473471
}
474-
else if (state > (brightness&3))
472+
else if (state > (badge_cfg.led_brightness&3))
475473
leds_releaseall();
476474

477475
TMR0_ClearITFlag(TMR0_3_IT_CYC_END);

src/ngctrl.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "power.h"
88
#include "debug.h"
99
#include "config.h"
10+
#include "leddrv.h"
1011

1112
// TODO: Some of configs can be added, just listing:
1213
// - Remote brighness adjusting
@@ -127,6 +128,50 @@ uint8_t load_fallback_cfg(uint8_t *val, uint16_t len)
127128
cfg_fallback(&badge_cfg);
128129
return 0;
129130
}
131+
132+
static uint8_t cfg_splash_speed(uint8_t *val, uint16_t len)
133+
{
134+
PRINT(__func__);
135+
PRINT("\n");
136+
137+
uint16_t ms = *((uint16_t *)val);
138+
if (ms < SPLASH_MIN_SPEED_T)
139+
return -2;
140+
141+
badge_cfg.splash_speedT = ms;
142+
return 0;
143+
}
144+
145+
static uint8_t cfg_led_brightness(uint8_t *val, uint16_t len)
146+
{
147+
PRINT(__func__);
148+
PRINT("\n");
149+
150+
uint8_t lvl = val[0];
151+
if (lvl >= BRIGHTNESS_LEVELS)
152+
return -2;
153+
154+
badge_cfg.led_brightness = lvl;
155+
return 0;
156+
}
157+
158+
uint8_t misc(uint8_t *val, uint16_t len)
159+
{
160+
PRINT(__func__);
161+
PRINT("\n");
162+
163+
const uint8_t (*misc_cmd[])(uint8_t *, uint16_t) = {
164+
cfg_splash_speed,
165+
cfg_led_brightness,
166+
};
167+
168+
uint8_t fn = val[0];
169+
if (fn >= (sizeof(misc_cmd) / sizeof(misc_cmd[0])))
170+
return -1;
171+
172+
return misc_cmd[fn](&val[1], len - 1);
173+
}
174+
130175
/* TODO: add a way to read configs */
131176
const uint8_t (*cmd_lut[])(uint8_t *val, uint16_t len) = {
132177
next_packet, // Unsure if we need this
@@ -137,6 +182,7 @@ const uint8_t (*cmd_lut[])(uint8_t *val, uint16_t len) = {
137182
flash_splash_screen,
138183
save_cfg,
139184
load_fallback_cfg,
185+
misc,
140186
};
141187

142188
#define CMD_LUT_LEN (sizeof(cmd_lut) / sizeof(cmd_lut[0]))

0 commit comments

Comments
 (0)