1
mirror of https://github.com/DarkFlippers/unleashed-firmware.git synced 2025-12-12 12:42:30 +04:00

Working on moving RGB routines from Notification to RGB service

This commit is contained in:
Dmitry422
2025-03-12 02:19:17 +07:00
parent 9e6593c09e
commit 4045628ac6
11 changed files with 324 additions and 32 deletions

View File

@@ -30,7 +30,6 @@ void input_settings_load(InputSettings* settings) {
sizeof(InputSettings),
INPUT_SETTINGS_MAGIC,
INPUT_SETTINGS_VER);
// if config previous version - load it and inicialize new settings
}
// in case of another config version we exit from useless cycle to next step
} while(false);

View File

@@ -7,5 +7,4 @@ App(
stack_size=1 * 1024,
order=99,
sdk_headers=["rgb_backlight.h"],
provides=["rgb_backlight_settings"],
)

View File

@@ -1,11 +1,152 @@
/*
RGB BackLight Service based on
RGB backlight FlipperZero driver
Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdio.h>
#include <furi.h>
#include <furi_hal.h>
#include <storage/storage.h>
#include "rgb_backlight.h"
#define STATIC_COLOR_COUNT (sizeof(colors) / sizeof(RGBBacklightStaticColor))
#define TAG "RGB_BACKLIGHT_SRV"
static const RGBBacklightStaticColor colors[] = {
{"Orange", 255, 60, 0},
{"Yellow", 255, 144, 0},
{"Spring", 167, 255, 0},
{"Lime", 0, 255, 0},
{"Aqua", 0, 255, 127},
{"Cyan", 0, 210, 210},
{"Azure", 0, 127, 255},
{"Blue", 0, 0, 255},
{"Purple", 127, 0, 255},
{"Magenta", 210, 0, 210},
{"Pink", 255, 0, 127},
{"Red", 255, 0, 0},
{"White", 254, 210, 200},
{"Custom", 0, 0, 0},
};
void rgb_backlight_set_custom_color(uint8_t red, uint8_t green, uint8_t blue, float brightness) {
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
uint8_t r = red * (brightness);
uint8_t g = green * (brightness);
uint8_t b = blue * (brightness);
SK6805_set_led_color(i, r, g, b);
}
SK6805_update();
}
static void rainbow_timer_callback(void* context) {
furi_assert(context);
RGBBacklightApp* app = context;
// if rgb_mode_rainbow_mode is rainbow do rainbow effect
if(app->settings->rainbow_mode == 1) {
switch(app->rainbow_stage) {
// from red to yellow
case 1:
app->rainbow_green += app->settings->rainbow_step;
if(app->rainbow_green >= 255) {
app->rainbow_green = 255;
app->rainbow_stage++;
}
break;
// yellow red to green
case 2:
app->rainbow_red -= app->settings->rainbow_step;
if(app->rainbow_red <= 0) {
app->rainbow_red = 0;
app->rainbow_stage++;
}
break;
// from green to light blue
case 3:
app->rainbow_blue += app->settings->rainbow_step;
if(app->rainbow_blue >= 255) {
app->rainbow_blue = 255;
app->rainbow_stage++;
}
break;
//from light blue to blue
case 4:
app->rainbow_green -= app->settings->rainbow_step;
if(app->rainbow_green <= 0) {
app->rainbow_green = 0;
app->rainbow_stage++;
}
break;
//from blue to violet
case 5:
app->rainbow_red += app->settings->rainbow_step;
if(app->rainbow_red >= 255) {
app->rainbow_red = 255;
app->rainbow_stage++;
}
break;
//from violet to red
case 6:
app->rainbow_blue -= app->settings->rainbow_step;
if(app->rainbow_blue <= 0) {
app->rainbow_blue = 0;
app->rainbow_stage = 1;
}
break;
default:
break;
}
rgb_backlight_set_custom_color(
app->rainbow_red,
app->rainbow_green,
app->rainbow_blue,
app->settings->brightness);
}
// if rgb_mode_rainbow_mode is ..... do another effect
// if(app->settings.rainbow_mode == 2) {
// }
}
void rgb_backlight_settings_apply(RGBBacklightSettings* settings) {
UNUSED (settings);
//запуск таймера если все включено
// применить сохраненые настройки цвета к дисплею статику или кастом если индекс=13
}
int32_t rgb_backlight_srv (void* p){
// Define object app (full app with settings and running variables),
// allocate memory and create record for access to app structure from outside
RGBBacklightApp* app = malloc(sizeof(RGBBacklightApp));
furi_record_create(RECORD_RGB_BACKLIGHT, app);
//define rainbow_timer and they callback
app->rainbow_timer =
furi_timer_alloc(rainbow_timer_callback, FuriTimerTypePeriodic, app);
// load or init new settings and apply it
rgb_backlight_settings_load (app->settings);
rgb_backlight_settings_apply (app->settings);
UNUSED(p);
while(1) {
FURI_LOG_I(TAG, "working");

View File

@@ -0,0 +1,44 @@
/*
RGB BackLight Service based on
RGB backlight FlipperZero driver
Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <furi.h>
#include "rgb_backlight_settings.h"
#include "SK6805.h"
typedef struct {
char* name;
uint8_t red;
uint8_t green;
uint8_t blue;
} RGBBacklightStaticColor;
typedef struct {
FuriTimer* rainbow_timer;
int16_t rainbow_red;
int16_t rainbow_green;
int16_t rainbow_blue;
uint8_t rainbow_stage;
RGBBacklightSettings* settings;
} RGBBacklightApp;
#define RECORD_RGB_BACKLIGHT "rgb_backlight"

View File

@@ -0,0 +1,95 @@
#include "rgb_backlight_settings.h"
#include <saved_struct.h>
#include <storage/storage.h>
#define TAG "RGBBackligthSettings"
#define RGB_BACKLIGHT_SETTINGS_FILE_NAME ".rgb_backlight.settings"
#define RGB_BACKLIGHT_SETTINGS_PATH INT_PATH(RGB_BACKLIGHT_SETTINGS_FILE_NAME)
#define RGB_BACKLIGHT_SETTINGS_MAGIC (0x30)
#define RGB_BACKLIGHT_SETTINGS_VER_PREV (0) // Previous version number
#define RGB_BACKLIGHT_SETTINGS_VER (1) // New version number
//pervious settings must be copyed from previous rgb_backlight_settings.h file
typedef struct {
uint8_t version;
bool rgb_mod_installed;
uint8_t display_static_color_index;
uint8_t custom_r;
uint8_t custom_g;
uint8_t custom_b;
uint32_t rainbow_mode;
uint32_t rainbow_speed_ms;
uint16_t rainbow_step;
} RGBBacklightSettingsPrevious;
void rgb_backlight_settings_load(RGBBacklightSettings* settings) {
furi_assert(settings);
bool success = false;
//a useless cycle do-while, may will be used in future with anoter condition
do {
// take version from settings file metadata, if cant then break and fill settings with 0 and save to settings file;
uint8_t version;
if(!saved_struct_get_metadata(RGB_BACKLIGHT_SETTINGS_PATH, NULL, &version, NULL)) break;
// if config actual version - load it directly
if(version == RGB_BACKLIGHT_SETTINGS_VER) {
success = saved_struct_load(
RGB_BACKLIGHT_SETTINGS_PATH,
settings,
sizeof(RGBBacklightSettings),
RGB_BACKLIGHT_SETTINGS_MAGIC,
RGB_BACKLIGHT_SETTINGS_VER);
// if config previous version - load it and inicialize new settings
} else if(version == RGB_BACKLIGHT_SETTINGS_VER_PREV) {
RGBBacklightSettingsPrevious* settings_previous = malloc(sizeof(RGBBacklightSettingsPrevious));
success = saved_struct_load(
RGB_BACKLIGHT_SETTINGS_PATH,
settings_previous,
sizeof(RGBBacklightSettingsPrevious),
RGB_BACKLIGHT_SETTINGS_MAGIC,
RGB_BACKLIGHT_SETTINGS_VER_PREV);
// new settings initialization
if(success) {
// copy loaded old settings as part of new
uint32_t size = sizeof(settings);
memcpy(settings, settings_previous, size);
// set new options to initial value
// settings.something = something;
}
free(settings_previous);
}
// in case of another config version we exit from useless cycle to next step
} while(false);
// fill settings with 0 and save to settings file;
// Orange color (index=0) will be default
if(!success) {
FURI_LOG_W(TAG, "Failed to load file, using defaults 0");
memset(settings, 0, sizeof(RGBBacklightSettings));
rgb_backlight_settings_save(settings);
}
}
void rgb_backlight_settings_save(const RGBBacklightSettings* settings) {
furi_assert(settings);
const bool success = saved_struct_save(
RGB_BACKLIGHT_SETTINGS_PATH,
settings,
sizeof(RGBBacklightSettings),
RGB_BACKLIGHT_SETTINGS_MAGIC,
RGB_BACKLIGHT_SETTINGS_VER);
if(!success) {
FURI_LOG_E(TAG, "Failed to save rgb_backlight_settings file");
}
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
typedef struct {
uint8_t version;
bool rgb_mod_installed;
uint8_t display_static_color_index;
uint8_t custom_r;
uint8_t custom_g;
uint8_t custom_b;
float brightness;
uint32_t rainbow_mode;
uint32_t rainbow_speed_ms;
uint16_t rainbow_step;
} RGBBacklightSettings;
#ifdef __cplusplus
extern "C" {
#endif
void rgb_backlight_settings_load(RGBBacklightSettings* settings);
void rgb_backlight_settings_save(const RGBBacklightSettings* settings);
#ifdef __cplusplus
}
#endif

View File

@@ -7,7 +7,6 @@ App(
"system_settings",
"clock_settings",
"input_settings",
"rgb_backlight_settings",
"about",
],
)

View File

@@ -1,9 +0,0 @@
App(
appid="rgb_backlight_settings",
name="RGB backlight",
apptype=FlipperAppType.SETTINGS,
entry_point="rgb_backlight_settings",
requires=["rgb_backlight"],
stack_size=1 * 1024,
order=110,
)

View File

@@ -1,13 +0,0 @@
#include <stdint.h>
#include <stdio.h>
#include <furi.h>
#include "rgb_backlight_settings.h"
#define TAG "RGB_BACKLIGHT_SETTINGS"
int32_t rgb_backlight_settings (void* p){
UNUSED (p);
FURI_LOG_I (TAG,"Settings");
furi_delay_ms (2000);
return 0;
}

View File

@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,83.0,,
Version,+,83.1,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/bt/bt_service/bt_keys_storage.h,,
@@ -411,6 +411,10 @@ Function,-,LL_mDelay,void,uint32_t
Function,-,Osal_MemCmp,int,"const void*, const void*, unsigned int"
Function,-,Osal_MemCpy,void*,"void*, const void*, unsigned int"
Function,-,Osal_MemSet,void*,"void*, int, unsigned int"
Function,+,SK6805_get_led_count,uint8_t,
Function,+,SK6805_init,void,
Function,+,SK6805_set_led_color,void,"uint8_t, uint8_t, uint8_t, uint8_t"
Function,+,SK6805_update,void,
Function,-,SystemCoreClockUpdate,void,
Function,-,SystemInit,void,
Function,-,_Exit,void,int
@@ -3139,6 +3143,8 @@ Function,-,remquol,long double,"long double, long double, int*"
Function,-,rename,int,"const char*, const char*"
Function,-,renameat,int,"int, const char*, int, const char*"
Function,-,rewind,void,FILE*
Function,+,rgb_backlight_settings_load,void,RGBBacklightSettings*
Function,+,rgb_backlight_settings_save,void,const RGBBacklightSettings*
Function,-,rindex,char*,"const char*, int"
Function,-,rint,double,double
Function,-,rintf,float,float
1 entry status name type params
2 Version + 83.0 83.1
3 Header + applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h
4 Header + applications/services/bt/bt_service/bt.h
5 Header + applications/services/bt/bt_service/bt_keys_storage.h
411 Function - Osal_MemCmp int const void*, const void*, unsigned int
412 Function - Osal_MemCpy void* void*, const void*, unsigned int
413 Function - Osal_MemSet void* void*, int, unsigned int
414 Function + SK6805_get_led_count uint8_t
415 Function + SK6805_init void
416 Function + SK6805_set_led_color void uint8_t, uint8_t, uint8_t, uint8_t
417 Function + SK6805_update void
418 Function - SystemCoreClockUpdate void
419 Function - SystemInit void
420 Function - _Exit void int
3143 Function - rename int const char*, const char*
3144 Function - renameat int int, const char*, int, const char*
3145 Function - rewind void FILE*
3146 Function + rgb_backlight_settings_load void RGBBacklightSettings*
3147 Function + rgb_backlight_settings_save void const RGBBacklightSettings*
3148 Function - rindex char* const char*, int
3149 Function - rint double double
3150 Function - rintf float float