From a5f62f756ae10029ead39db32d0d9bebdada9291 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Fri, 31 Jan 2025 19:25:52 +0700 Subject: [PATCH 01/10] Begin work with Input_service settings (edit,save) for vibro_touch option --- applications/services/input/input.c | 22 ++++++ applications/services/input/input.h | 8 ++ applications/services/input/input_settings.c | 77 +++++++++++++++++++ applications/services/input/input_settings.h | 18 +++++ .../services/input/input_settings_filename.h | 3 + .../power/power_service/power_settings.h | 2 + .../settings/input_settings/application.fam | 9 +++ .../input_settings/input_settings_app.c | 67 ++++++++++++++++ .../input_settings/input_settings_app.h | 23 ++++++ targets/f7/api_symbols.csv | 4 +- 10 files changed, 232 insertions(+), 1 deletion(-) create mode 100644 applications/services/input/input_settings.c create mode 100644 applications/services/input/input_settings.h create mode 100644 applications/services/input/input_settings_filename.h create mode 100644 applications/settings/input_settings/application.fam create mode 100644 applications/settings/input_settings/input_settings_app.c create mode 100644 applications/settings/input_settings/input_settings_app.h diff --git a/applications/services/input/input.c b/applications/services/input/input.c index 6cbafb795..4ba77cc34 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -6,6 +6,7 @@ #include #include #include +#include #define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2) #define INPUT_PRESS_TICKS 150 @@ -79,9 +80,23 @@ const char* input_get_type_name(InputType type) { } } +// allocate memory for input_settings structure +static InputSettings* input_settings_alloc (void) { + InputSettings* input_settings = malloc(sizeof(InputSettings)); + return input_settings; +} + +//free memory from input_settings structure +void input_settings_free (InputSettings* input_settings) { + free (input_settings); +} + int32_t input_srv(void* p) { UNUSED(p); + //define object input_settings and take memory for him + InputSettings* input_settings = input_settings_alloc(); + const FuriThreadId thread_id = furi_thread_get_current_id(); FuriPubSub* event_pubsub = furi_pubsub_alloc(); uint32_t counter = 1; @@ -149,6 +164,11 @@ int32_t input_srv(void* p) { // Send Press/Release event event.type = pin_states[i].state ? InputTypePress : InputTypeRelease; furi_pubsub_publish(event_pubsub, &event); + if (input_settings->vibro_touch_level) { + furi_hal_vibro_on(true); + furi_delay_tick (30); + furi_hal_vibro_on(false); + }; } } @@ -165,5 +185,7 @@ int32_t input_srv(void* p) { } } + // if we come here and ready exit from service (whats going on ??!!) then best practice is free memory + input_settings_free(input_settings); return 0; } diff --git a/applications/services/input/input.h b/applications/services/input/input.h index 5233b4a01..3d8d6c9ec 100644 --- a/applications/services/input/input.h +++ b/applications/services/input/input.h @@ -6,6 +6,7 @@ #pragma once #include +#include "input_settings.h" #ifdef __cplusplus extern "C" { @@ -40,6 +41,13 @@ typedef struct { InputType type; } InputEvent; +//for next step input structure globalization; +//typedef struct Input { + //InputSettings* settings; + //InputType* type; + //InputEvent* event; +//} Input; + /** Get human readable input key name * @param key - InputKey * @return string diff --git a/applications/services/input/input_settings.c b/applications/services/input/input_settings.c new file mode 100644 index 000000000..fc738c004 --- /dev/null +++ b/applications/services/input/input_settings.c @@ -0,0 +1,77 @@ +#include "input_settings.h" +#include "input_settings_filename.h" + +#include +#include + +#define TAG "InputSettings" + +#define INPUT_SETTINGS_VER_0 (0) // OLD version number +#define INPUT_SETTINGS_VER (1) // NEW actual version nnumber + +#define INPUT_SETTINGS_PATH INT_PATH(INPUT_SETTINGS_FILE_NAME) +#define INPUT_SETTINGS_MAGIC (0x19) + +typedef struct { + //inital set - empty +} InputSettingsV0; + +void input_settings_load(InputSettings* settings) { + furi_assert(settings); + + bool success = false; + + do { + uint8_t version; + if(!saved_struct_get_metadata(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break; + + if(version == INPUT_SETTINGS_VER) { // if config actual version - load it directly + success = saved_struct_load( + INPUT_SETTINGS_PATH, + settings, + sizeof(InputSettings), + INPUT_SETTINGS_MAGIC, + INPUT_SETTINGS_VER); + + } else if( + version == + INPUT_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value + InputSettingsV0* settings_v0 = malloc(sizeof(InputSettingsV0)); + + success = saved_struct_load( + INPUT_SETTINGS_PATH, + settings_v0, + sizeof(InputSettingsV0), + INPUT_SETTINGS_MAGIC, + INPUT_SETTINGS_VER_0); + + if(success) { + settings->vibro_touch_level = 0; + } + + free(settings_v0); + } + + } while(false); + + if(!success) { + FURI_LOG_W(TAG, "Failed to load file, using defaults"); + memset(settings, 0, sizeof(InputSettings)); + input_settings_save(settings); + } +} + +void input_settings_save(const InputSettings* settings) { + furi_assert(settings); + + const bool success = saved_struct_save( + INPUT_SETTINGS_PATH, + settings, + sizeof(InputSettings), + INPUT_SETTINGS_MAGIC, + INPUT_SETTINGS_VER); + + if(!success) { + FURI_LOG_E(TAG, "Failed to save file"); + } +} diff --git a/applications/services/input/input_settings.h b/applications/services/input/input_settings.h new file mode 100644 index 000000000..376e8e226 --- /dev/null +++ b/applications/services/input/input_settings.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +typedef struct { + uint8_t vibro_touch_level; +} InputSettings; + +#ifdef __cplusplus +extern "C" { +#endif + +void input_settings_load(InputSettings* settings); +void input_settings_save(const InputSettings* settings); + +#ifdef __cplusplus +} +#endif diff --git a/applications/services/input/input_settings_filename.h b/applications/services/input/input_settings_filename.h new file mode 100644 index 000000000..025ed6ad5 --- /dev/null +++ b/applications/services/input/input_settings_filename.h @@ -0,0 +1,3 @@ +#pragma once + +#define INPUT_SETTINGS_FILE_NAME ".input.settings" diff --git a/applications/services/power/power_service/power_settings.h b/applications/services/power/power_service/power_settings.h index 65d8e079e..b1cc71001 100644 --- a/applications/services/power/power_service/power_settings.h +++ b/applications/services/power/power_service/power_settings.h @@ -9,8 +9,10 @@ typedef struct { #ifdef __cplusplus extern "C" { #endif + void power_settings_load(PowerSettings* settings); void power_settings_save(const PowerSettings* settings); + #ifdef __cplusplus } #endif diff --git a/applications/settings/input_settings/application.fam b/applications/settings/input_settings/application.fam new file mode 100644 index 000000000..f137c2512 --- /dev/null +++ b/applications/settings/input_settings/application.fam @@ -0,0 +1,9 @@ +App( + appid="input_settings", + name="Input", + apptype=FlipperAppType,SETTINGS, + entry_point="input_settings_app", + requires=["gui"], + stack_size= 1 * 1024, + order=100, +) diff --git a/applications/settings/input_settings/input_settings_app.c b/applications/settings/input_settings/input_settings_app.c new file mode 100644 index 000000000..943bbc02f --- /dev/null +++ b/applications/settings/input_settings/input_settings_app.c @@ -0,0 +1,67 @@ +#include +#include "input_settings_app.h" + +#define VIBRO_TOUCH_LEVEL_COUNT 10 +// vibro touch human readable levels +const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = { + "OFF", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", +}; +// vibro touch levels tick valies delay +const uint32_t vibro_touch_level_value[VIBRO_TOUCH_LEVEL_COUNT] = + {0,13,16,19,21,24,27,30,33,36}; + +input_settings_start_vibro_touch_level_changed (){ + +} + +InputSettingsApp* input_settings_alloc (void) { + InputSettingsApp* app = malloc(sizeof(InputSettingsApp)); + + app->gui = furi_record_open (RECORD_GUI); + app->view_dispatcher = view_dispatcher_alloc (); + + VariableItem* item; + app->var_item_list = variable_item_list_alloc(); + + item = variable_item_list_add( + variable_item_list, + "Vibro touch level", + VIBRO_TOUCH_LEVEL_COUNT, + input_settings_start_vibro_touch_level_changed, + app); + + value_index = value_index_uint32( + app->settings.vibro_touch_level, vibro_touch_level_value, VIBRO_TOUCH_LEVEL_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]); + + +return app; +} + + +// Enter point +int32_t input_settings_app (void* p) { + UNUSED (p); + + //take memory + InputSettingsApp* app = input_settings_alloc (); + + //start view_dispatcher + view_dispatcher_run(app->view_dispatcher); + + //free memory + Input_settings_free (app); + + //exit with 0 code + return 0; +}; \ No newline at end of file diff --git a/applications/settings/input_settings/input_settings_app.h b/applications/settings/input_settings/input_settings_app.h new file mode 100644 index 000000000..7ba29b511 --- /dev/null +++ b/applications/settings/input_settings/input_settings_app.h @@ -0,0 +1,23 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include "input/input_settings.h" + +// app stucture +typedef struct { +InputSettings* settings; +Input* input; +Gui* gui; +ViewDispatcher* view_dispatcher; +VariableItemList* variable_item_list; +} InputSettingsApp; + +// list of menu views for view dispatcher +typedef enum { + InputSettingsViewVariableItemList, +} InputSettingsView; \ No newline at end of file diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index b649f1f99..420d7e678 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,79.3,, +Version,+,79.4,, 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,, @@ -2112,6 +2112,8 @@ Function,+,infrared_worker_tx_stop,void,InfraredWorker* Function,-,initstate,char*,"unsigned, char*, size_t" Function,+,input_get_key_name,const char*,InputKey Function,+,input_get_type_name,const char*,InputType +Function,+,input_settings_load,void,InputSettings* +Function,+,input_settings_save,void,const InputSettings* Function,-,iprintf,int,"const char*, ..." Function,-,isalnum,int,int Function,-,isalnum_l,int,"int, locale_t" From eef2441af9d06bd093ec36a824f39efbaec73957 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sun, 2 Feb 2025 14:57:41 +0700 Subject: [PATCH 02/10] InputSettings complete. Added VibroTouchLevel --- applications/ReadMe.md | 1 + applications/services/input/application.fam | 1 + applications/services/input/input.c | 75 +++++++++++-- applications/services/input/input.h | 10 +- applications/services/input/input_settings.c | 18 ++- .../services/power/power_service/power.c | 2 +- .../input_settings/input_settings_app.c | 67 ------------ .../application.fam | 6 +- .../input_settings_app/input_settings_app.c | 103 ++++++++++++++++++ .../input_settings_app.h | 12 +- 10 files changed, 197 insertions(+), 98 deletions(-) delete mode 100644 applications/settings/input_settings/input_settings_app.c rename applications/settings/{input_settings => input_settings_app}/application.fam (55%) create mode 100644 applications/settings/input_settings_app/input_settings_app.c rename applications/settings/{input_settings => input_settings_app}/input_settings_app.h (65%) diff --git a/applications/ReadMe.md b/applications/ReadMe.md index a3567df71..02469f252 100644 --- a/applications/ReadMe.md +++ b/applications/ReadMe.md @@ -67,6 +67,7 @@ Small applications providing configuration for basic firmware and its services. - `power_settings_app` - Basic power options - `storage_settings` - Storage settings app - `system` - System settings +- `input_settings_app` - Basic input options ## system diff --git a/applications/services/input/application.fam b/applications/services/input/application.fam index d344fc350..af6a91339 100644 --- a/applications/services/input/application.fam +++ b/applications/services/input/application.fam @@ -7,4 +7,5 @@ App( stack_size=1 * 1024, order=80, sdk_headers=["input.h"], + provides=["input_settings"], ) diff --git a/applications/services/input/input.c b/applications/services/input/input.c index 4ba77cc34..a5635912f 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -13,6 +13,8 @@ #define INPUT_LONG_PRESS_COUNTS 2 #define INPUT_THREAD_FLAG_ISR 0x00000001 +#define TAG "Input" + /** Input pin state */ typedef struct { const InputPin* pin; @@ -80,27 +82,76 @@ const char* input_get_type_name(InputType type) { } } + +// static void input_storage_callback(const void* message, void* context) { +// furi_assert(context); +// InputSettings* settings = context; +// const StorageEvent* event = message; +// UNUSED (settings); +// if(event->type == StorageEventTypeCardMount) { +// // furi_hal_vibro_on(true); +// // furi_delay_tick (100); +// // furi_hal_vibro_on(false); +// // furi_delay_tick (100); +// // furi_hal_vibro_on(true); +// // furi_delay_tick (100); +// // furi_hal_vibro_on(false); +// // furi_delay_tick (100); +// // furi_hal_vibro_on(true); +// // furi_delay_tick (100); +// // furi_hal_vibro_on(false); +// //input_settings_load(settings); +// } +// } + +// // load inital settings from file for power service +// static void input_init_settings(InputSettings* settings) { +// Storage* storage = furi_record_open(RECORD_STORAGE); +// furi_pubsub_subscribe(storage_get_pubsub(storage), input_storage_callback, settings); + +// if(storage_sd_status(storage) != FSE_OK) { +// FURI_LOG_D(TAG, "SD Card not ready, skipping settings"); +// //set default value +// settings->vibro_touch_level=0; +// //furi_record_close(RECORD_STORAGE); +// return; +// } + + // furi_hal_vibro_on(true); + // furi_delay_tick (100); + // furi_hal_vibro_on(false); + // furi_delay_tick (100); + // furi_hal_vibro_on(true); + // furi_delay_tick (100); + // furi_hal_vibro_on(false); + +// input_settings_load(settings); +// furi_record_close(RECORD_STORAGE); +// } + // allocate memory for input_settings structure static InputSettings* input_settings_alloc (void) { - InputSettings* input_settings = malloc(sizeof(InputSettings)); - return input_settings; + InputSettings* settings = malloc(sizeof(InputSettings)); + return settings; } //free memory from input_settings structure -void input_settings_free (InputSettings* input_settings) { - free (input_settings); +void input_settings_free (InputSettings* settings) { + free (settings); } int32_t input_srv(void* p) { UNUSED(p); - //define object input_settings and take memory for him - InputSettings* input_settings = input_settings_alloc(); - const FuriThreadId thread_id = furi_thread_get_current_id(); FuriPubSub* event_pubsub = furi_pubsub_alloc(); - uint32_t counter = 1; + uint32_t counter = 1; furi_record_create(RECORD_INPUT_EVENTS, event_pubsub); + + //define object input_settings, take memory load (or init) settings and create record for access to settings structure outside + InputSettings* settings = input_settings_alloc(); + furi_record_create(RECORD_INPUT_SETTINGS, settings); + input_settings_load(settings); #ifdef INPUT_DEBUG furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull); @@ -164,9 +215,10 @@ int32_t input_srv(void* p) { // Send Press/Release event event.type = pin_states[i].state ? InputTypePress : InputTypeRelease; furi_pubsub_publish(event_pubsub, &event); - if (input_settings->vibro_touch_level) { + // do vibro if user setup vibro touch level in Settings-Input. + if (settings->vibro_touch_level) { furi_hal_vibro_on(true); - furi_delay_tick (30); + furi_delay_tick (settings->vibro_touch_level); furi_hal_vibro_on(false); }; } @@ -185,7 +237,6 @@ int32_t input_srv(void* p) { } } - // if we come here and ready exit from service (whats going on ??!!) then best practice is free memory - input_settings_free(input_settings); + return 0; } diff --git a/applications/services/input/input.h b/applications/services/input/input.h index 3d8d6c9ec..650a95b51 100644 --- a/applications/services/input/input.h +++ b/applications/services/input/input.h @@ -7,12 +7,15 @@ #include #include "input_settings.h" +#include + #ifdef __cplusplus extern "C" { #endif #define RECORD_INPUT_EVENTS "input_events" +#define RECORD_INPUT_SETTINGS "input_settings" #define INPUT_SEQUENCE_SOURCE_HARDWARE (0u) #define INPUT_SEQUENCE_SOURCE_SOFTWARE (1u) @@ -41,13 +44,6 @@ typedef struct { InputType type; } InputEvent; -//for next step input structure globalization; -//typedef struct Input { - //InputSettings* settings; - //InputType* type; - //InputEvent* event; -//} Input; - /** Get human readable input key name * @param key - InputKey * @return string diff --git a/applications/services/input/input_settings.c b/applications/services/input/input_settings.c index fc738c004..34c01077d 100644 --- a/applications/services/input/input_settings.c +++ b/applications/services/input/input_settings.c @@ -21,18 +21,21 @@ void input_settings_load(InputSettings* 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(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break; - - if(version == INPUT_SETTINGS_VER) { // if config actual version - load it directly + + // if config actual version - load it directly + if(version == INPUT_SETTINGS_VER) { success = saved_struct_load( INPUT_SETTINGS_PATH, settings, sizeof(InputSettings), INPUT_SETTINGS_MAGIC, INPUT_SETTINGS_VER); - + // if config previous version - load it and inicialize new settings } else if( version == INPUT_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value @@ -51,9 +54,10 @@ void input_settings_load(InputSettings* settings) { free(settings_v0); } - + // 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; if(!success) { FURI_LOG_W(TAG, "Failed to load file, using defaults"); memset(settings, 0, sizeof(InputSettings)); @@ -71,6 +75,12 @@ void input_settings_save(const InputSettings* settings) { INPUT_SETTINGS_MAGIC, INPUT_SETTINGS_VER); + // debug log + // FURI_LOG_D(TAG,"SAVE"); + // char buffer[12] = {}; + // snprintf(buffer, sizeof(buffer), "%d",settings->vibro_touch_level); + // FURI_LOG_D(TAG,buffer); + if(!success) { FURI_LOG_E(TAG, "Failed to save file"); } diff --git a/applications/services/power/power_service/power.c b/applications/services/power/power_service/power.c index 511c64c78..252be5027 100644 --- a/applications/services/power/power_service/power.c +++ b/applications/services/power/power_service/power.c @@ -615,7 +615,7 @@ static Power* power_alloc(void) { free(settings); // auto_poweroff - //---define subscription to loader events message (info about started apps) and defina callback for this + //---define subscription to loader events message (info about started apps) and define callback for this Loader* loader = furi_record_open(RECORD_LOADER); furi_pubsub_subscribe(loader_get_pubsub(loader), power_loader_callback, power); power->input_events_pubsub = furi_record_open(RECORD_INPUT_EVENTS); diff --git a/applications/settings/input_settings/input_settings_app.c b/applications/settings/input_settings/input_settings_app.c deleted file mode 100644 index 943bbc02f..000000000 --- a/applications/settings/input_settings/input_settings_app.c +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include "input_settings_app.h" - -#define VIBRO_TOUCH_LEVEL_COUNT 10 -// vibro touch human readable levels -const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = { - "OFF", - "1", - "2", - "3", - "4", - "5", - "6", - "7", - "8", - "9", -}; -// vibro touch levels tick valies delay -const uint32_t vibro_touch_level_value[VIBRO_TOUCH_LEVEL_COUNT] = - {0,13,16,19,21,24,27,30,33,36}; - -input_settings_start_vibro_touch_level_changed (){ - -} - -InputSettingsApp* input_settings_alloc (void) { - InputSettingsApp* app = malloc(sizeof(InputSettingsApp)); - - app->gui = furi_record_open (RECORD_GUI); - app->view_dispatcher = view_dispatcher_alloc (); - - VariableItem* item; - app->var_item_list = variable_item_list_alloc(); - - item = variable_item_list_add( - variable_item_list, - "Vibro touch level", - VIBRO_TOUCH_LEVEL_COUNT, - input_settings_start_vibro_touch_level_changed, - app); - - value_index = value_index_uint32( - app->settings.vibro_touch_level, vibro_touch_level_value, VIBRO_TOUCH_LEVEL_COUNT); - variable_item_set_current_value_index(item, value_index); - variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]); - - -return app; -} - - -// Enter point -int32_t input_settings_app (void* p) { - UNUSED (p); - - //take memory - InputSettingsApp* app = input_settings_alloc (); - - //start view_dispatcher - view_dispatcher_run(app->view_dispatcher); - - //free memory - Input_settings_free (app); - - //exit with 0 code - return 0; -}; \ No newline at end of file diff --git a/applications/settings/input_settings/application.fam b/applications/settings/input_settings_app/application.fam similarity index 55% rename from applications/settings/input_settings/application.fam rename to applications/settings/input_settings_app/application.fam index f137c2512..14be52fc4 100644 --- a/applications/settings/input_settings/application.fam +++ b/applications/settings/input_settings_app/application.fam @@ -1,9 +1,9 @@ App( appid="input_settings", name="Input", - apptype=FlipperAppType,SETTINGS, + apptype=FlipperAppType.SETTINGS, entry_point="input_settings_app", - requires=["gui"], - stack_size= 1 * 1024, + requires=["input"], + stack_size=1 * 1024, order=100, ) diff --git a/applications/settings/input_settings_app/input_settings_app.c b/applications/settings/input_settings_app/input_settings_app.c new file mode 100644 index 000000000..452f7ac52 --- /dev/null +++ b/applications/settings/input_settings_app/input_settings_app.c @@ -0,0 +1,103 @@ +#include +#include "input_settings_app.h" + +#define TAG "InputSettingsApp" + +#define VIBRO_TOUCH_LEVEL_COUNT 10 +// vibro touch human readable levels +const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = { + "OFF","1","2","3","4","5","6","7","8","9",}; +// vibro touch levels tick valies delay +const uint32_t vibro_touch_level_value[VIBRO_TOUCH_LEVEL_COUNT] = + {0,13,16,19,21,24,27,30,33,36}; + +static void input_settings_vibro_touch_level_changed (VariableItem* item) { + uint8_t index = variable_item_get_current_value_index(item); + variable_item_set_current_value_text(item, vibro_touch_level_text[index]); + + //change settings to selected + InputSettingsApp* app = variable_item_get_context(item); + app->settings->vibro_touch_level = vibro_touch_level_value[index]; + + // use RECORD for acces to input service instance and set settings + InputSettings* service_settings = furi_record_open (RECORD_INPUT_SETTINGS); + service_settings->vibro_touch_level = vibro_touch_level_value[index]; + furi_record_close (RECORD_INPUT_SETTINGS); + +} + +static uint32_t input_settings_app_exit(void* context) { + UNUSED(context); + return VIEW_NONE; +} + +InputSettingsApp* input_settings_app_alloc (void) { + InputSettingsApp* app = malloc(sizeof(InputSettingsApp)); + //app->inputservice = furi_record_open(RECORD_INPUT_EVENTS); + + app->gui = furi_record_open (RECORD_GUI); + + app->settings = malloc(sizeof(InputSettings)); + input_settings_load (app->settings); + + app->variable_item_list = variable_item_list_alloc(); + View* view = variable_item_list_get_view(app->variable_item_list); + view_set_previous_callback(view, input_settings_app_exit); + + VariableItem* item; + uint8_t value_index; + + item = variable_item_list_add( + app->variable_item_list,"VibroTouchLevel",VIBRO_TOUCH_LEVEL_COUNT,input_settings_vibro_touch_level_changed,app); + + value_index = value_index_uint32( + app->settings->vibro_touch_level, vibro_touch_level_value, VIBRO_TOUCH_LEVEL_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]); + + // create and setup view and view dispatcher + app->view_dispatcher = view_dispatcher_alloc (); + view_dispatcher_set_event_callback_context(app->view_dispatcher, app); + view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); + view_dispatcher_add_view(app->view_dispatcher,InputSettingsViewVariableItemList,view); + view_dispatcher_switch_to_view(app->view_dispatcher, InputSettingsViewVariableItemList); + +return app; +} + +void input_settings_app_free (InputSettingsApp* app){ + furi_assert(app); + + // Variable item list + view_dispatcher_remove_view(app->view_dispatcher, InputSettingsViewVariableItemList); + variable_item_list_free(app->variable_item_list); + + // View dispatcher + view_dispatcher_free(app->view_dispatcher); + + // Records + furi_record_close(RECORD_GUI); + //furi_record_close(RECORD_INPUT_EVENTS); + free (app->settings); + free(app); +} + +// Enter point +int32_t input_settings_app (void* p) { + UNUSED (p); + InputSettingsApp* app = input_settings_app_alloc (); + + view_dispatcher_run(app->view_dispatcher); + + // // debug code + // FURI_LOG_D(TAG,"Vibro Touch level before save"); + // char buffer[12] = {}; + // snprintf(buffer, sizeof(buffer), "%d",app->settings->vibro_touch_level); + // FURI_LOG_D(TAG,buffer); + + //save current settings; + input_settings_save(app->settings); + + input_settings_app_free (app); + return 0; +}; \ No newline at end of file diff --git a/applications/settings/input_settings/input_settings_app.h b/applications/settings/input_settings_app/input_settings_app.h similarity index 65% rename from applications/settings/input_settings/input_settings_app.h rename to applications/settings/input_settings_app/input_settings_app.h index 7ba29b511..c65597ea6 100644 --- a/applications/settings/input_settings/input_settings_app.h +++ b/applications/settings/input_settings_app/input_settings_app.h @@ -6,15 +6,19 @@ #include #include #include -#include "input/input_settings.h" +#include +#include +#include +#include -// app stucture + +// input_settings_app stucture typedef struct { -InputSettings* settings; -Input* input; +//InputService* inputservice; //link to input_sevice with they setings and events Gui* gui; ViewDispatcher* view_dispatcher; VariableItemList* variable_item_list; +InputSettings* settings; } InputSettingsApp; // list of menu views for view dispatcher From a5c241139d61bc49db4ef75b2116accc9cd53ae2 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sun, 2 Feb 2025 15:13:55 +0700 Subject: [PATCH 03/10] Source code C\C++ formating --- applications/services/input/input.c | 32 +++++----- applications/services/input/input.h | 1 - applications/services/input/input_settings.c | 16 ++--- .../input_settings_app/input_settings_app.c | 63 +++++++++++-------- .../input_settings_app/input_settings_app.h | 13 ++-- 5 files changed, 67 insertions(+), 58 deletions(-) diff --git a/applications/services/input/input.c b/applications/services/input/input.c index a5635912f..5e2fdb9d5 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -82,7 +82,6 @@ const char* input_get_type_name(InputType type) { } } - // static void input_storage_callback(const void* message, void* context) { // furi_assert(context); // InputSettings* settings = context; @@ -116,28 +115,28 @@ const char* input_get_type_name(InputType type) { // //furi_record_close(RECORD_STORAGE); // return; // } - - // furi_hal_vibro_on(true); - // furi_delay_tick (100); - // furi_hal_vibro_on(false); - // furi_delay_tick (100); - // furi_hal_vibro_on(true); - // furi_delay_tick (100); - // furi_hal_vibro_on(false); + +// furi_hal_vibro_on(true); +// furi_delay_tick (100); +// furi_hal_vibro_on(false); +// furi_delay_tick (100); +// furi_hal_vibro_on(true); +// furi_delay_tick (100); +// furi_hal_vibro_on(false); // input_settings_load(settings); // furi_record_close(RECORD_STORAGE); // } // allocate memory for input_settings structure -static InputSettings* input_settings_alloc (void) { +static InputSettings* input_settings_alloc(void) { InputSettings* settings = malloc(sizeof(InputSettings)); return settings; } //free memory from input_settings structure -void input_settings_free (InputSettings* settings) { - free (settings); +void input_settings_free(InputSettings* settings) { + free(settings); } int32_t input_srv(void* p) { @@ -145,9 +144,9 @@ int32_t input_srv(void* p) { const FuriThreadId thread_id = furi_thread_get_current_id(); FuriPubSub* event_pubsub = furi_pubsub_alloc(); - uint32_t counter = 1; + uint32_t counter = 1; furi_record_create(RECORD_INPUT_EVENTS, event_pubsub); - + //define object input_settings, take memory load (or init) settings and create record for access to settings structure outside InputSettings* settings = input_settings_alloc(); furi_record_create(RECORD_INPUT_SETTINGS, settings); @@ -216,9 +215,9 @@ int32_t input_srv(void* p) { event.type = pin_states[i].state ? InputTypePress : InputTypeRelease; furi_pubsub_publish(event_pubsub, &event); // do vibro if user setup vibro touch level in Settings-Input. - if (settings->vibro_touch_level) { + if(settings->vibro_touch_level) { furi_hal_vibro_on(true); - furi_delay_tick (settings->vibro_touch_level); + furi_delay_tick(settings->vibro_touch_level); furi_hal_vibro_on(false); }; } @@ -237,6 +236,5 @@ int32_t input_srv(void* p) { } } - return 0; } diff --git a/applications/services/input/input.h b/applications/services/input/input.h index 650a95b51..92dbfeb68 100644 --- a/applications/services/input/input.h +++ b/applications/services/input/input.h @@ -9,7 +9,6 @@ #include "input_settings.h" #include - #ifdef __cplusplus extern "C" { #endif diff --git a/applications/services/input/input_settings.c b/applications/services/input/input_settings.c index 34c01077d..2868e5974 100644 --- a/applications/services/input/input_settings.c +++ b/applications/services/input/input_settings.c @@ -26,16 +26,16 @@ void input_settings_load(InputSettings* settings) { // 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(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break; - + // if config actual version - load it directly - if(version == INPUT_SETTINGS_VER) { + if(version == INPUT_SETTINGS_VER) { success = saved_struct_load( INPUT_SETTINGS_PATH, settings, sizeof(InputSettings), INPUT_SETTINGS_MAGIC, INPUT_SETTINGS_VER); - // if config previous version - load it and inicialize new settings + // if config previous version - load it and inicialize new settings } else if( version == INPUT_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value @@ -75,11 +75,11 @@ void input_settings_save(const InputSettings* settings) { INPUT_SETTINGS_MAGIC, INPUT_SETTINGS_VER); - // debug log - // FURI_LOG_D(TAG,"SAVE"); - // char buffer[12] = {}; - // snprintf(buffer, sizeof(buffer), "%d",settings->vibro_touch_level); - // FURI_LOG_D(TAG,buffer); + // debug log + // FURI_LOG_D(TAG,"SAVE"); + // char buffer[12] = {}; + // snprintf(buffer, sizeof(buffer), "%d",settings->vibro_touch_level); + // FURI_LOG_D(TAG,buffer); if(!success) { FURI_LOG_E(TAG, "Failed to save file"); diff --git a/applications/settings/input_settings_app/input_settings_app.c b/applications/settings/input_settings_app/input_settings_app.c index 452f7ac52..0f25900c1 100644 --- a/applications/settings/input_settings_app/input_settings_app.c +++ b/applications/settings/input_settings_app/input_settings_app.c @@ -6,24 +6,33 @@ #define VIBRO_TOUCH_LEVEL_COUNT 10 // vibro touch human readable levels const char* const vibro_touch_level_text[VIBRO_TOUCH_LEVEL_COUNT] = { - "OFF","1","2","3","4","5","6","7","8","9",}; + "OFF", + "1", + "2", + "3", + "4", + "5", + "6", + "7", + "8", + "9", +}; // vibro touch levels tick valies delay const uint32_t vibro_touch_level_value[VIBRO_TOUCH_LEVEL_COUNT] = - {0,13,16,19,21,24,27,30,33,36}; + {0, 13, 16, 19, 21, 24, 27, 30, 33, 36}; -static void input_settings_vibro_touch_level_changed (VariableItem* item) { +static void input_settings_vibro_touch_level_changed(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, vibro_touch_level_text[index]); - + //change settings to selected InputSettingsApp* app = variable_item_get_context(item); app->settings->vibro_touch_level = vibro_touch_level_value[index]; // use RECORD for acces to input service instance and set settings - InputSettings* service_settings = furi_record_open (RECORD_INPUT_SETTINGS); + InputSettings* service_settings = furi_record_open(RECORD_INPUT_SETTINGS); service_settings->vibro_touch_level = vibro_touch_level_value[index]; - furi_record_close (RECORD_INPUT_SETTINGS); - + furi_record_close(RECORD_INPUT_SETTINGS); } static uint32_t input_settings_app_exit(void* context) { @@ -31,15 +40,15 @@ static uint32_t input_settings_app_exit(void* context) { return VIEW_NONE; } -InputSettingsApp* input_settings_app_alloc (void) { +InputSettingsApp* input_settings_app_alloc(void) { InputSettingsApp* app = malloc(sizeof(InputSettingsApp)); //app->inputservice = furi_record_open(RECORD_INPUT_EVENTS); - - app->gui = furi_record_open (RECORD_GUI); + + app->gui = furi_record_open(RECORD_GUI); app->settings = malloc(sizeof(InputSettings)); - input_settings_load (app->settings); - + input_settings_load(app->settings); + app->variable_item_list = variable_item_list_alloc(); View* view = variable_item_list_get_view(app->variable_item_list); view_set_previous_callback(view, input_settings_app_exit); @@ -48,7 +57,11 @@ InputSettingsApp* input_settings_app_alloc (void) { uint8_t value_index; item = variable_item_list_add( - app->variable_item_list,"VibroTouchLevel",VIBRO_TOUCH_LEVEL_COUNT,input_settings_vibro_touch_level_changed,app); + app->variable_item_list, + "VibroTouchLevel", + VIBRO_TOUCH_LEVEL_COUNT, + input_settings_vibro_touch_level_changed, + app); value_index = value_index_uint32( app->settings->vibro_touch_level, vibro_touch_level_value, VIBRO_TOUCH_LEVEL_COUNT); @@ -56,16 +69,16 @@ InputSettingsApp* input_settings_app_alloc (void) { variable_item_set_current_value_text(item, vibro_touch_level_text[value_index]); // create and setup view and view dispatcher - app->view_dispatcher = view_dispatcher_alloc (); + app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_set_event_callback_context(app->view_dispatcher, app); view_dispatcher_attach_to_gui(app->view_dispatcher, app->gui, ViewDispatcherTypeFullscreen); - view_dispatcher_add_view(app->view_dispatcher,InputSettingsViewVariableItemList,view); + view_dispatcher_add_view(app->view_dispatcher, InputSettingsViewVariableItemList, view); view_dispatcher_switch_to_view(app->view_dispatcher, InputSettingsViewVariableItemList); -return app; + return app; } -void input_settings_app_free (InputSettingsApp* app){ +void input_settings_app_free(InputSettingsApp* app) { furi_assert(app); // Variable item list @@ -74,18 +87,18 @@ void input_settings_app_free (InputSettingsApp* app){ // View dispatcher view_dispatcher_free(app->view_dispatcher); - + // Records furi_record_close(RECORD_GUI); //furi_record_close(RECORD_INPUT_EVENTS); - free (app->settings); + free(app->settings); free(app); } -// Enter point -int32_t input_settings_app (void* p) { - UNUSED (p); - InputSettingsApp* app = input_settings_app_alloc (); +// Enter point +int32_t input_settings_app(void* p) { + UNUSED(p); + InputSettingsApp* app = input_settings_app_alloc(); view_dispatcher_run(app->view_dispatcher); @@ -98,6 +111,6 @@ int32_t input_settings_app (void* p) { //save current settings; input_settings_save(app->settings); - input_settings_app_free (app); + input_settings_app_free(app); return 0; -}; \ No newline at end of file +} diff --git a/applications/settings/input_settings_app/input_settings_app.h b/applications/settings/input_settings_app/input_settings_app.h index c65597ea6..e7accc772 100644 --- a/applications/settings/input_settings_app/input_settings_app.h +++ b/applications/settings/input_settings_app/input_settings_app.h @@ -11,17 +11,16 @@ #include #include - // input_settings_app stucture typedef struct { -//InputService* inputservice; //link to input_sevice with they setings and events -Gui* gui; -ViewDispatcher* view_dispatcher; -VariableItemList* variable_item_list; -InputSettings* settings; + //InputService* inputservice; //link to input_sevice with they setings and events + Gui* gui; + ViewDispatcher* view_dispatcher; + VariableItemList* variable_item_list; + InputSettings* settings; } InputSettingsApp; // list of menu views for view dispatcher typedef enum { InputSettingsViewVariableItemList, -} InputSettingsView; \ No newline at end of file +} InputSettingsView; From 8c31d8a682b4fc1652a63464371eac6bbbc1d92f Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Sun, 2 Feb 2025 21:41:30 +0700 Subject: [PATCH 04/10] Source code cosmetic changes --- applications/services/input/input.c | 48 +------------------ .../input_settings_app/input_settings_app.c | 1 - .../input_settings_app/input_settings_app.h | 1 - 3 files changed, 1 insertion(+), 49 deletions(-) diff --git a/applications/services/input/input.c b/applications/services/input/input.c index 5e2fdb9d5..2b697d6ce 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -82,52 +82,6 @@ const char* input_get_type_name(InputType type) { } } -// static void input_storage_callback(const void* message, void* context) { -// furi_assert(context); -// InputSettings* settings = context; -// const StorageEvent* event = message; -// UNUSED (settings); -// if(event->type == StorageEventTypeCardMount) { -// // furi_hal_vibro_on(true); -// // furi_delay_tick (100); -// // furi_hal_vibro_on(false); -// // furi_delay_tick (100); -// // furi_hal_vibro_on(true); -// // furi_delay_tick (100); -// // furi_hal_vibro_on(false); -// // furi_delay_tick (100); -// // furi_hal_vibro_on(true); -// // furi_delay_tick (100); -// // furi_hal_vibro_on(false); -// //input_settings_load(settings); -// } -// } - -// // load inital settings from file for power service -// static void input_init_settings(InputSettings* settings) { -// Storage* storage = furi_record_open(RECORD_STORAGE); -// furi_pubsub_subscribe(storage_get_pubsub(storage), input_storage_callback, settings); - -// if(storage_sd_status(storage) != FSE_OK) { -// FURI_LOG_D(TAG, "SD Card not ready, skipping settings"); -// //set default value -// settings->vibro_touch_level=0; -// //furi_record_close(RECORD_STORAGE); -// return; -// } - -// furi_hal_vibro_on(true); -// furi_delay_tick (100); -// furi_hal_vibro_on(false); -// furi_delay_tick (100); -// furi_hal_vibro_on(true); -// furi_delay_tick (100); -// furi_hal_vibro_on(false); - -// input_settings_load(settings); -// furi_record_close(RECORD_STORAGE); -// } - // allocate memory for input_settings structure static InputSettings* input_settings_alloc(void) { InputSettings* settings = malloc(sizeof(InputSettings)); @@ -147,7 +101,7 @@ int32_t input_srv(void* p) { uint32_t counter = 1; furi_record_create(RECORD_INPUT_EVENTS, event_pubsub); - //define object input_settings, take memory load (or init) settings and create record for access to settings structure outside + //define object input_settings, take memory load (or init) settings and create record for access to settings structure from outside InputSettings* settings = input_settings_alloc(); furi_record_create(RECORD_INPUT_SETTINGS, settings); input_settings_load(settings); diff --git a/applications/settings/input_settings_app/input_settings_app.c b/applications/settings/input_settings_app/input_settings_app.c index 0f25900c1..2902625ae 100644 --- a/applications/settings/input_settings_app/input_settings_app.c +++ b/applications/settings/input_settings_app/input_settings_app.c @@ -90,7 +90,6 @@ void input_settings_app_free(InputSettingsApp* app) { // Records furi_record_close(RECORD_GUI); - //furi_record_close(RECORD_INPUT_EVENTS); free(app->settings); free(app); } diff --git a/applications/settings/input_settings_app/input_settings_app.h b/applications/settings/input_settings_app/input_settings_app.h index e7accc772..c96ca49e9 100644 --- a/applications/settings/input_settings_app/input_settings_app.h +++ b/applications/settings/input_settings_app/input_settings_app.h @@ -13,7 +13,6 @@ // input_settings_app stucture typedef struct { - //InputService* inputservice; //link to input_sevice with they setings and events Gui* gui; ViewDispatcher* view_dispatcher; VariableItemList* variable_item_list; From cce8a7c4130f9c39a352cb346c1153c82df6e73e Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Mon, 3 Feb 2025 19:18:53 +0700 Subject: [PATCH 05/10] Begin work with SafeCharging (charging supress) --- .../power/power_service/power_settings.c | 31 ++++++------- .../power/power_service/power_settings.h | 3 ++ .../scenes/power_settings_scene_start.c | 45 ++++++++++++++----- 3 files changed, 54 insertions(+), 25 deletions(-) diff --git a/applications/services/power/power_service/power_settings.c b/applications/services/power/power_service/power_settings.c index 139323a7a..93657823d 100644 --- a/applications/services/power/power_service/power_settings.c +++ b/applications/services/power/power_service/power_settings.c @@ -6,15 +6,15 @@ #define TAG "PowerSettings" -#define POWER_SETTINGS_VER_0 (0) // OLD version number -#define POWER_SETTINGS_VER (1) // NEW actual version nnumber +#define POWER_SETTINGS_VER_1 (1) // Previous version number +#define POWER_SETTINGS_VER (2) // New version number #define POWER_SETTINGS_PATH INT_PATH(POWER_SETTINGS_FILE_NAME) #define POWER_SETTINGS_MAGIC (0x18) typedef struct { - //inital set - empty -} PowerSettingsV0; + uint32_t auto_poweroff_delay_ms; +} PowerSettingsPrevious; void power_settings_load(PowerSettings* settings) { furi_assert(settings); @@ -25,7 +25,8 @@ void power_settings_load(PowerSettings* settings) { uint8_t version; if(!saved_struct_get_metadata(POWER_SETTINGS_PATH, NULL, &version, NULL)) break; - if(version == POWER_SETTINGS_VER) { // if config actual version - load it directly + // if config actual version - load it directly + if(version == POWER_SETTINGS_VER) { success = saved_struct_load( POWER_SETTINGS_PATH, settings, @@ -33,23 +34,23 @@ void power_settings_load(PowerSettings* settings) { POWER_SETTINGS_MAGIC, POWER_SETTINGS_VER); - } else if( - version == - POWER_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value - PowerSettingsV0* settings_v0 = malloc(sizeof(PowerSettingsV0)); + // if config previous version - load it and manual set new settings to inital value + } else if(version == POWER_SETTINGS_VER_1) { + PowerSettingsPrevious* settings_previous = malloc(sizeof(PowerSettingsPrevious)); success = saved_struct_load( POWER_SETTINGS_PATH, - settings_v0, - sizeof(PowerSettingsV0), + settings_previous, + sizeof(PowerSettingsPrevious), POWER_SETTINGS_MAGIC, - POWER_SETTINGS_VER_0); - + POWER_SETTINGS_VER_1); + // new settings initialization if(success) { - settings->auto_poweroff_delay_ms = 0; + settings->charge_supress_percent = 0; + settings->charge_is_supressed = false; } - free(settings_v0); + free(settings_previous); } } while(false); diff --git a/applications/services/power/power_service/power_settings.h b/applications/services/power/power_service/power_settings.h index b1cc71001..c07199cf8 100644 --- a/applications/services/power/power_service/power_settings.h +++ b/applications/services/power/power_service/power_settings.h @@ -1,9 +1,12 @@ #pragma once #include +#include typedef struct { uint32_t auto_poweroff_delay_ms; + uint8_t charge_supress_percent; + bool charge_is_supressed; } PowerSettings; #ifdef __cplusplus diff --git a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c index 3fc3a8a30..0d23d3915 100644 --- a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c +++ b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c @@ -15,6 +15,20 @@ const char* const auto_poweroff_delay_text[AUTO_POWEROFF_DELAY_COUNT] = const uint32_t auto_poweroff_delay_value[AUTO_POWEROFF_DELAY_COUNT] = {0, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000}; +#define CHARGE_SUPRESS_PERCENT_COUNT 2 +const char* const charge_supress_percent_text[CHARGE_SUPRESS_PERCENT_COUNT] = {"OFF", "80%"}; + +const uint32_t charge_supress_percent_value[CHARGE_SUPRESS_PERCENT_COUNT] = {0, 80}; + +// change variable_item_list visible text and charge_supress_percent_settings when user change item in variable_item_list +static void power_settings_scene_start_charge_supress_percent_changed(VariableItem* item) { + PowerSettingsApp* app = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, charge_supress_percent_text[index]); + app->settings.charge_supress_percent = charge_supress_percent_value[index]; +} + // change variable_item_list visible text and app_poweroff_delay_time_settings when user change item in variable_item_list static void power_settings_scene_start_auto_poweroff_delay_changed(VariableItem* item) { PowerSettingsApp* app = variable_item_get_context(item); @@ -24,9 +38,8 @@ static void power_settings_scene_start_auto_poweroff_delay_changed(VariableItem* app->settings.auto_poweroff_delay_ms = auto_poweroff_delay_value[index]; } -static void power_settings_scene_start_submenu_callback( - void* context, - uint32_t index) { //show selected menu screen +static void power_settings_scene_start_submenu_callback(void* context, uint32_t index) { + //show selected menu screen by index furi_assert(context); PowerSettingsApp* app = context; view_dispatcher_send_custom_event(app->view_dispatcher, index); @@ -42,11 +55,12 @@ void power_settings_scene_start_on_enter(void* context) { VariableItem* item; uint8_t value_index; + item = variable_item_list_add( variable_item_list, "Auto PowerOff", AUTO_POWEROFF_DELAY_COUNT, - power_settings_scene_start_auto_poweroff_delay_changed, //function for change visible item list value and app settings + power_settings_scene_start_auto_poweroff_delay_changed, app); value_index = value_index_uint32( @@ -56,14 +70,25 @@ void power_settings_scene_start_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, auto_poweroff_delay_text[value_index]); + item = variable_item_list_add( + variable_item_list, + "Safe charging", + CHARGE_SUPRESS_PERCENT_COUNT, + power_settings_scene_start_charge_supress_percent_changed, + app); + + value_index = value_index_uint32( + app->settings.charge_supress_percent, + charge_supress_percent_value, + CHARGE_SUPRESS_PERCENT_COUNT); + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, charge_supress_percent_text[value_index]); + variable_item_list_set_selected_item( variable_item_list, scene_manager_get_scene_state(app->scene_manager, PowerSettingsAppSceneStart)); - variable_item_list_set_enter_callback( //callback to show next mennu screen - variable_item_list, - power_settings_scene_start_submenu_callback, - app); - + variable_item_list_set_enter_callback( + variable_item_list, power_settings_scene_start_submenu_callback, app); view_dispatcher_switch_to_view(app->view_dispatcher, PowerSettingsAppViewVariableItemList); } @@ -88,5 +113,5 @@ bool power_settings_scene_start_on_event(void* context, SceneManagerEvent event) void power_settings_scene_start_on_exit(void* context) { PowerSettingsApp* app = context; variable_item_list_reset(app->variable_item_list); - power_settings_save(&app->settings); //actual need save every time when use ? + power_settings_save(&app->settings); } From 724c4ca445860bb3b000fd8a55439e2c67ed6e9a Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 4 Feb 2025 00:42:52 +0700 Subject: [PATCH 06/10] SafeCharging (charging supress) finished. --- .../services/power/power_service/power.c | 27 ++++++++++++++++--- .../services/power/power_service/power_i.h | 1 + .../power/power_service/power_settings.h | 1 - .../scenes/power_settings_scene_start.c | 9 ++++--- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/applications/services/power/power_service/power.c b/applications/services/power/power_service/power.c index 252be5027..c6e1147d7 100644 --- a/applications/services/power/power_service/power.c +++ b/applications/services/power/power_service/power.c @@ -442,7 +442,7 @@ static void power_auto_poweroff_timer_callback(void* context) { Power* power = context; //Dont poweroff device if charger connected - if (furi_hal_power_is_charging()) { + if(furi_hal_power_is_charging()) { FURI_LOG_D(TAG, "We dont auto_power_off until battery is charging"); power_start_auto_poweroff_timer(power); } else { @@ -548,6 +548,24 @@ static void power_message_callback(FuriEventLoopObject* object, void* context) { } } +static void power_charge_supress(Power* power) { + // if charge_supress_percent selected (not OFF) and current charge level equal or higher than selected level + // then we start supression if we not supress it before. + if(power->settings.charge_supress_percent && + power->info.charge >= power->settings.charge_supress_percent) { + if(!power->charge_is_supressed) { + power->charge_is_supressed = true; + furi_hal_power_suppress_charge_enter(); + } + // disable supression if charge_supress_percent OFF but charge still supressed + } else { + if(power->charge_is_supressed) { + power->charge_is_supressed = false; + furi_hal_power_suppress_charge_exit(); + } + } +} + static void power_tick_callback(void* context) { furi_assert(context); Power* power = context; @@ -560,6 +578,8 @@ static void power_tick_callback(void* context) { power_check_charging_state(power); // Check and notify about battery level change power_check_battery_level_change(power); + // charge supress arm/disarm + power_charge_supress(power); // Update battery view port if(need_refresh) { view_port_update(power->battery_view_port); @@ -585,7 +605,7 @@ static void power_storage_callback(const void* message, void* context) { } } -// load inital settings from file for power service +// loading and initializing power service settings static void power_init_settings(Power* power) { Storage* storage = furi_record_open(RECORD_STORAGE); furi_pubsub_subscribe(storage_get_pubsub(storage), power_storage_callback, power); @@ -598,6 +618,7 @@ static void power_init_settings(Power* power) { power_settings_load(&power->settings); power_settings_apply(power); furi_record_close(RECORD_STORAGE); + power->charge_is_supressed = false; } static Power* power_alloc(void) { @@ -661,7 +682,7 @@ int32_t power_srv(void* p) { Power* power = power_alloc(); - // load inital settings for power service + // power service settings initialization power_init_settings(power); power_update_info(power); diff --git a/applications/services/power/power_service/power_i.h b/applications/services/power/power_service/power_i.h index 40b4a1ef4..09f8e7816 100644 --- a/applications/services/power/power_service/power_i.h +++ b/applications/services/power/power_service/power_i.h @@ -41,6 +41,7 @@ struct Power { bool app_running; FuriPubSub* input_events_pubsub; FuriPubSubSubscription* input_events_subscription; + bool charge_is_supressed; }; typedef enum { diff --git a/applications/services/power/power_service/power_settings.h b/applications/services/power/power_service/power_settings.h index c07199cf8..63f24e097 100644 --- a/applications/services/power/power_service/power_settings.h +++ b/applications/services/power/power_service/power_settings.h @@ -6,7 +6,6 @@ typedef struct { uint32_t auto_poweroff_delay_ms; uint8_t charge_supress_percent; - bool charge_is_supressed; } PowerSettings; #ifdef __cplusplus diff --git a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c index 0d23d3915..2b8bd773f 100644 --- a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c +++ b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c @@ -15,10 +15,11 @@ const char* const auto_poweroff_delay_text[AUTO_POWEROFF_DELAY_COUNT] = const uint32_t auto_poweroff_delay_value[AUTO_POWEROFF_DELAY_COUNT] = {0, 300000, 600000, 900000, 1800000, 2700000, 3600000, 5400000}; -#define CHARGE_SUPRESS_PERCENT_COUNT 2 -const char* const charge_supress_percent_text[CHARGE_SUPRESS_PERCENT_COUNT] = {"OFF", "80%"}; +#define CHARGE_SUPRESS_PERCENT_COUNT 6 +const char* const charge_supress_percent_text[CHARGE_SUPRESS_PERCENT_COUNT] = + {"OFF", "90%", "85%", "80%", "75%", "70%"}; -const uint32_t charge_supress_percent_value[CHARGE_SUPRESS_PERCENT_COUNT] = {0, 80}; +const uint32_t charge_supress_percent_value[CHARGE_SUPRESS_PERCENT_COUNT] = {0, 90, 85, 80, 75, 70}; // change variable_item_list visible text and charge_supress_percent_settings when user change item in variable_item_list static void power_settings_scene_start_charge_supress_percent_changed(VariableItem* item) { @@ -72,7 +73,7 @@ void power_settings_scene_start_on_enter(void* context) { item = variable_item_list_add( variable_item_list, - "Safe charging", + "Safe Charging", CHARGE_SUPRESS_PERCENT_COUNT, power_settings_scene_start_charge_supress_percent_changed, app); From 3029f0d6d6bf69f61640e4fee70c7a38de8cf1b5 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Tue, 4 Feb 2025 00:53:28 +0700 Subject: [PATCH 07/10] Litle bit mistakes cleanup. --- applications/services/power/power_service/power_settings.c | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/services/power/power_service/power_settings.c b/applications/services/power/power_service/power_settings.c index 93657823d..d12754784 100644 --- a/applications/services/power/power_service/power_settings.c +++ b/applications/services/power/power_service/power_settings.c @@ -47,7 +47,6 @@ void power_settings_load(PowerSettings* settings) { // new settings initialization if(success) { settings->charge_supress_percent = 0; - settings->charge_is_supressed = false; } free(settings_previous); From 92b58bc99f2ddd2036547310e4d81b3c7eb78129 Mon Sep 17 00:00:00 2001 From: Dmitry422 Date: Wed, 5 Feb 2025 16:31:26 +0700 Subject: [PATCH 08/10] Litle bit cahnges in RGB led driver for compatibility with VibroTouch. Shell files for buil firmware. --- .ci_files/rgb.patch | 4 +++- extra.sh | 9 +++++++++ rgb.sh | 5 +++++ 3 files changed, 17 insertions(+), 1 deletion(-) create mode 100755 extra.sh create mode 100755 rgb.sh diff --git a/.ci_files/rgb.patch b/.ci_files/rgb.patch index 51a305aec..81783325f 100644 --- a/.ci_files/rgb.patch +++ b/.ci_files/rgb.patch @@ -466,7 +466,7 @@ new file mode 100644 index 0000000..b89f82a --- /dev/null +++ b/lib/drivers/SK6805.c -@@ -0,0 +1,101 @@ +@@ -0,0 +1,103 @@ +/* + SK6805 FlipperZero driver + Copyright (C) 2022-2023 Victor Nikitchuk (https://github.com/quen0n) @@ -527,6 +527,7 @@ index 0000000..b89f82a +void SK6805_update(void) { + SK6805_init(); + FURI_CRITICAL_ENTER(); ++ furi_delay_us(150); + uint32_t end; + /* Последовательная отправка цветов светодиодов */ + for(uint8_t lednumber = 0; lednumber < SK6805_LED_COUNT; lednumber++) { @@ -566,6 +567,7 @@ index 0000000..b89f82a + } + } + } ++ furi_delay_us(150); + FURI_CRITICAL_EXIT(); +} diff --git a/lib/drivers/SK6805.h b/lib/drivers/SK6805.h diff --git a/extra.sh b/extra.sh new file mode 100755 index 000000000..923c2bc47 --- /dev/null +++ b/extra.sh @@ -0,0 +1,9 @@ +wget https://github.com/xMasterX/all-the-plugins/releases/latest/download/all-the-apps-extra.tgz +tar zxf all-the-apps-extra.tgz +mkdir -p applications/main/clock_app/resources/apps +cp -R extra_pack_build/artifacts-extra/* applications/main/clock_app/resources/apps/ +rm -rf extra_pack_build +rm -f build/f7-firmware-C/toolbox/version.* +./fbt COMPACT=1 DEBUG=0 updater_package +mkdir artifacts-extra-apps +mv dist/f7-C/* artifacts-extra-apps/ diff --git a/rgb.sh b/rgb.sh new file mode 100755 index 000000000..31f9144a4 --- /dev/null +++ b/rgb.sh @@ -0,0 +1,5 @@ +git apply .ci_files/rgb.patch +rm -f build/f7-firmware-C/toolbox/version.* +./fbt COMPACT=1 DEBUG=0 updater_package +mkdir artifacts-rgb-patch +mv dist/f7-C/* artifacts-rgb-patch/ From e22669da96ffed7dd35911ce2a2a24d37225d917 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 13 Feb 2025 03:56:04 +0300 Subject: [PATCH 09/10] fixes and corrections --- CHANGELOG.md | 2 +- applications/services/input/input.c | 13 +------- applications/services/input/input_settings.c | 32 ++----------------- .../input_settings_app/input_settings_app.c | 10 +----- .../scenes/power_settings_scene_start.c | 2 +- extra.sh | 9 ------ rgb.sh | 5 --- 7 files changed, 6 insertions(+), 67 deletions(-) delete mode 100755 extra.sh delete mode 100755 rgb.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b4d73eb9..81bdd909e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,5 @@ ## Main changes -- Current API: 79.3 +- Current API: 79.4 * OFW: LFRFID - **EM4305 support** * Apps: **Check out more Apps updates and fixes by following** [this link](https://github.com/xMasterX/all-the-plugins/commits/dev) ## Other changes diff --git a/applications/services/input/input.c b/applications/services/input/input.c index 2b697d6ce..41759a1dd 100644 --- a/applications/services/input/input.c +++ b/applications/services/input/input.c @@ -82,17 +82,6 @@ const char* input_get_type_name(InputType type) { } } -// allocate memory for input_settings structure -static InputSettings* input_settings_alloc(void) { - InputSettings* settings = malloc(sizeof(InputSettings)); - return settings; -} - -//free memory from input_settings structure -void input_settings_free(InputSettings* settings) { - free(settings); -} - int32_t input_srv(void* p) { UNUSED(p); @@ -102,7 +91,7 @@ int32_t input_srv(void* p) { furi_record_create(RECORD_INPUT_EVENTS, event_pubsub); //define object input_settings, take memory load (or init) settings and create record for access to settings structure from outside - InputSettings* settings = input_settings_alloc(); + InputSettings* settings = malloc(sizeof(InputSettings)); furi_record_create(RECORD_INPUT_SETTINGS, settings); input_settings_load(settings); diff --git a/applications/services/input/input_settings.c b/applications/services/input/input_settings.c index 2868e5974..cd3de6d50 100644 --- a/applications/services/input/input_settings.c +++ b/applications/services/input/input_settings.c @@ -6,15 +6,10 @@ #define TAG "InputSettings" -#define INPUT_SETTINGS_VER_0 (0) // OLD version number -#define INPUT_SETTINGS_VER (1) // NEW actual version nnumber +#define INPUT_SETTINGS_VER (1) // version nnumber #define INPUT_SETTINGS_PATH INT_PATH(INPUT_SETTINGS_FILE_NAME) -#define INPUT_SETTINGS_MAGIC (0x19) - -typedef struct { - //inital set - empty -} InputSettingsV0; +#define INPUT_SETTINGS_MAGIC (0x29) void input_settings_load(InputSettings* settings) { furi_assert(settings); @@ -36,23 +31,6 @@ void input_settings_load(InputSettings* settings) { INPUT_SETTINGS_MAGIC, INPUT_SETTINGS_VER); // if config previous version - load it and inicialize new settings - } else if( - version == - INPUT_SETTINGS_VER_0) { // if config previous version - load it and manual set new settings to inital value - InputSettingsV0* settings_v0 = malloc(sizeof(InputSettingsV0)); - - success = saved_struct_load( - INPUT_SETTINGS_PATH, - settings_v0, - sizeof(InputSettingsV0), - INPUT_SETTINGS_MAGIC, - INPUT_SETTINGS_VER_0); - - if(success) { - settings->vibro_touch_level = 0; - } - - free(settings_v0); } // in case of another config version we exit from useless cycle to next step } while(false); @@ -75,12 +53,6 @@ void input_settings_save(const InputSettings* settings) { INPUT_SETTINGS_MAGIC, INPUT_SETTINGS_VER); - // debug log - // FURI_LOG_D(TAG,"SAVE"); - // char buffer[12] = {}; - // snprintf(buffer, sizeof(buffer), "%d",settings->vibro_touch_level); - // FURI_LOG_D(TAG,buffer); - if(!success) { FURI_LOG_E(TAG, "Failed to save file"); } diff --git a/applications/settings/input_settings_app/input_settings_app.c b/applications/settings/input_settings_app/input_settings_app.c index 2902625ae..4f3e101da 100644 --- a/applications/settings/input_settings_app/input_settings_app.c +++ b/applications/settings/input_settings_app/input_settings_app.c @@ -42,8 +42,6 @@ static uint32_t input_settings_app_exit(void* context) { InputSettingsApp* input_settings_app_alloc(void) { InputSettingsApp* app = malloc(sizeof(InputSettingsApp)); - //app->inputservice = furi_record_open(RECORD_INPUT_EVENTS); - app->gui = furi_record_open(RECORD_GUI); app->settings = malloc(sizeof(InputSettings)); @@ -58,7 +56,7 @@ InputSettingsApp* input_settings_app_alloc(void) { item = variable_item_list_add( app->variable_item_list, - "VibroTouchLevel", + "Buttons Vibro", VIBRO_TOUCH_LEVEL_COUNT, input_settings_vibro_touch_level_changed, app); @@ -101,12 +99,6 @@ int32_t input_settings_app(void* p) { view_dispatcher_run(app->view_dispatcher); - // // debug code - // FURI_LOG_D(TAG,"Vibro Touch level before save"); - // char buffer[12] = {}; - // snprintf(buffer, sizeof(buffer), "%d",app->settings->vibro_touch_level); - // FURI_LOG_D(TAG,buffer); - //save current settings; input_settings_save(app->settings); diff --git a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c index 2b8bd773f..42c53ed02 100644 --- a/applications/settings/power_settings_app/scenes/power_settings_scene_start.c +++ b/applications/settings/power_settings_app/scenes/power_settings_scene_start.c @@ -73,7 +73,7 @@ void power_settings_scene_start_on_enter(void* context) { item = variable_item_list_add( variable_item_list, - "Safe Charging", + "Limit Charge", CHARGE_SUPRESS_PERCENT_COUNT, power_settings_scene_start_charge_supress_percent_changed, app); diff --git a/extra.sh b/extra.sh deleted file mode 100755 index 923c2bc47..000000000 --- a/extra.sh +++ /dev/null @@ -1,9 +0,0 @@ -wget https://github.com/xMasterX/all-the-plugins/releases/latest/download/all-the-apps-extra.tgz -tar zxf all-the-apps-extra.tgz -mkdir -p applications/main/clock_app/resources/apps -cp -R extra_pack_build/artifacts-extra/* applications/main/clock_app/resources/apps/ -rm -rf extra_pack_build -rm -f build/f7-firmware-C/toolbox/version.* -./fbt COMPACT=1 DEBUG=0 updater_package -mkdir artifacts-extra-apps -mv dist/f7-C/* artifacts-extra-apps/ diff --git a/rgb.sh b/rgb.sh deleted file mode 100755 index 31f9144a4..000000000 --- a/rgb.sh +++ /dev/null @@ -1,5 +0,0 @@ -git apply .ci_files/rgb.patch -rm -f build/f7-firmware-C/toolbox/version.* -./fbt COMPACT=1 DEBUG=0 updater_package -mkdir artifacts-rgb-patch -mv dist/f7-C/* artifacts-rgb-patch/ From d57e2c9ef7ca81d2087dc906bcac483f71c4823a Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Thu, 13 Feb 2025 03:56:22 +0300 Subject: [PATCH 10/10] fmt --- applications/services/desktop/desktop.c | 2 +- .../desktop_settings/scenes/desktop_settings_scene_start.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/applications/services/desktop/desktop.c b/applications/services/desktop/desktop.c index 843dbebb0..3eda85539 100644 --- a/applications/services/desktop/desktop.c +++ b/applications/services/desktop/desktop.c @@ -149,7 +149,7 @@ static bool desktop_custom_event_callback(void* context, uint32_t event) { if((desktop->settings.usb_inhibit_auto_lock) && (furi_hal_usb_is_locked())) { return (0); } - + desktop_lock(desktop); } } else if(event == DesktopGlobalSaveSettings) { diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c index 9b992c80c..dfcac3eed 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_start.c @@ -52,7 +52,7 @@ const char* const usb_inhibit_auto_lock_delay_text[USB_INHIBIT_AUTO_LOCK_DELAY_C "ON", }; -const uint32_t usb_inhibit_auto_lock_delay_value[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {0,1}; +const uint32_t usb_inhibit_auto_lock_delay_value[USB_INHIBIT_AUTO_LOCK_DELAY_COUNT] = {0, 1}; #define CLOCK_ENABLE_COUNT 2 const char* const clock_enable_text[CLOCK_ENABLE_COUNT] = {