Fix version on application.fam. Refactor code for COUNT_OF.

This commit is contained in:
Derek Jamison 2023-12-06 14:22:33 -06:00
parent 774b228856
commit 216c15dd77
2 changed files with 23 additions and 28 deletions

View File

@ -260,28 +260,24 @@ static bool led_tester_custom_event_callback(void* context, uint32_t event) {
uint32_t rgb[4] = {0}; uint32_t rgb[4] = {0};
switch(app->model->led_pattern_index) { switch(app->model->led_pattern_index) {
case 0: // RED case 0: // RED
rgb[0] = 0xFF0000; for(size_t i = 0; i < COUNT_OF(rgb); i++) {
rgb[1] = rgb[0]; rgb[i] = 0xFF0000;
rgb[2] = rgb[0]; }
rgb[3] = rgb[0];
break; break;
case 1: // GREEN case 1: // GREEN
rgb[0] = 0x00FF00; for(size_t i = 0; i < COUNT_OF(rgb); i++) {
rgb[1] = rgb[0]; rgb[i] = 0x00FF00;
rgb[2] = rgb[0]; }
rgb[3] = rgb[0];
break; break;
case 2: // BLUE case 2: // BLUE
rgb[0] = 0x0000FF; for(size_t i = 0; i < COUNT_OF(rgb); i++) {
rgb[1] = rgb[0]; rgb[i] = 0x0000FF;
rgb[2] = rgb[0]; }
rgb[3] = rgb[0];
break; break;
case 3: // WHITE case 3: // WHITE
rgb[0] = 0xFFFFFF; for(size_t i = 0; i < COUNT_OF(rgb); i++) {
rgb[1] = rgb[0]; rgb[i] = 0xFFFFFF;
rgb[2] = rgb[0]; }
rgb[3] = rgb[0];
break; break;
case 4: // RGBW case 4: // RGBW
rgb[0] = 0xFF0000; rgb[0] = 0xFF0000;
@ -312,24 +308,23 @@ static bool led_tester_custom_event_callback(void* context, uint32_t event) {
} }
// Rotate the pattern // Rotate the pattern
for(int i = 0; i < offset; i++) { for(size_t i = 0; i < offset; i++) {
uint32_t tmp = rgb[0]; uint32_t tmp = rgb[0];
rgb[0] = rgb[1]; for(size_t j = 0; j < COUNT_OF(rgb) - 1; j++) {
rgb[1] = rgb[2]; rgb[j] = rgb[j + 1];
rgb[2] = rgb[3]; }
rgb[3] = tmp; rgb[COUNT_OF(rgb) - 1] = tmp;
} }
// If deinit, turn off the LEDs // If deinit, turn off the LEDs
if(event == LedTesterEventDeinit) { if(event == LedTesterEventDeinit) {
rgb[0] = 0; for(size_t i = 0; i < COUNT_OF(rgb); i++) {
rgb[1] = 0; rgb[i] = 0;
rgb[2] = 0; }
rgb[3] = 0;
} }
// Scale the brightness // Scale the brightness
for(size_t i = 0; i < 4; i++) { for(size_t i = 0; i < COUNT_OF(rgb); i++) {
rgb[i] = (((rgb[i] >> 16) & 0xFF) * app->model->led_max_brightness / 100) << 16 | rgb[i] = (((rgb[i] >> 16) & 0xFF) * app->model->led_max_brightness / 100) << 16 |
(((rgb[i] >> 8) & 0xFF) * app->model->led_max_brightness / 100) << 8 | (((rgb[i] >> 8) & 0xFF) * app->model->led_max_brightness / 100) << 8 |
((rgb[i] & 0xFF) * app->model->led_max_brightness / 100); ((rgb[i] & 0xFF) * app->model->led_max_brightness / 100);
@ -340,7 +335,7 @@ static bool led_tester_custom_event_callback(void* context, uint32_t event) {
// Set the LEDs to the pattern // Set the LEDs to the pattern
for(size_t i = 0; i < app->model->led_count; i++) { for(size_t i = 0; i < app->model->led_count; i++) {
led_driver_set_led(app->led_driver, i, rgb[i % 4]); led_driver_set_led(app->led_driver, i, rgb[i % COUNT_OF(rgb)]);
} }
// Turn off any remaining LEDs // Turn off any remaining LEDs
for(size_t i = app->model->led_count; i < MAX_LED_COUNT; i++) { for(size_t i = app->model->led_count; i < MAX_LED_COUNT; i++) {

View File

@ -3,7 +3,7 @@ App(
name="WS2812B LED Tester App", name="WS2812B LED Tester App",
apptype=FlipperAppType.EXTERNAL, apptype=FlipperAppType.EXTERNAL,
entry_point="ws2812b_led_tester_app", entry_point="ws2812b_led_tester_app",
fap_version=(1, 6), fap_version=(1, 7),
stack_size=4 * 1024, stack_size=4 * 1024,
requires=[ requires=[
"gui", "gui",