Skip to content

Commit

Permalink
Merge pull request #867 from Dmitry422/dev
Browse files Browse the repository at this point in the history
Additional options for Input and Power service
  • Loading branch information
xMasterX authored Feb 13, 2025
2 parents 18e2d8d + d57e2c9 commit 9d9a46f
Show file tree
Hide file tree
Showing 20 changed files with 330 additions and 34 deletions.
4 changes: 3 additions & 1 deletion .ci_files/rgb.patch
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions applications/ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion applications/services/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions applications/services/input/application.fam
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ App(
stack_size=1 * 1024,
order=80,
sdk_headers=["input.h"],
provides=["input_settings"],
)
14 changes: 14 additions & 0 deletions applications/services/input/input.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#include <furi.h>
#include <cli/cli.h>
#include <furi_hal_gpio.h>
#include <furi_hal_vibro.h>

#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2)
#define INPUT_PRESS_TICKS 150
#define INPUT_LONG_PRESS_COUNTS 2
#define INPUT_THREAD_FLAG_ISR 0x00000001

#define TAG "Input"

/** Input pin state */
typedef struct {
const InputPin* pin;
Expand Down Expand Up @@ -87,6 +90,11 @@ 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 from outside
InputSettings* settings = malloc(sizeof(InputSettings));
furi_record_create(RECORD_INPUT_SETTINGS, settings);
input_settings_load(settings);

#ifdef INPUT_DEBUG
furi_hal_gpio_init_simple(&gpio_ext_pa4, GpioModeOutputPushPull);
#endif
Expand Down Expand Up @@ -149,6 +157,12 @@ int32_t input_srv(void* p) {
// Send Press/Release event
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) {
furi_hal_vibro_on(true);
furi_delay_tick(settings->vibro_touch_level);
furi_hal_vibro_on(false);
};
}
}

Expand Down
3 changes: 3 additions & 0 deletions applications/services/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
#pragma once

#include <furi_hal_resources.h>
#include "input_settings.h"
#include <storage/storage.h>

#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)

Expand Down
59 changes: 59 additions & 0 deletions applications/services/input/input_settings.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "input_settings.h"
#include "input_settings_filename.h"

#include <saved_struct.h>
#include <storage/storage.h>

#define TAG "InputSettings"

#define INPUT_SETTINGS_VER (1) // version nnumber

#define INPUT_SETTINGS_PATH INT_PATH(INPUT_SETTINGS_FILE_NAME)
#define INPUT_SETTINGS_MAGIC (0x29)

void input_settings_load(InputSettings* 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(INPUT_SETTINGS_PATH, NULL, &version, NULL)) break;

// 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
}
// 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));
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");
}
}
18 changes: 18 additions & 0 deletions applications/services/input/input_settings.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

#include <stdint.h>

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
3 changes: 3 additions & 0 deletions applications/services/input/input_settings_filename.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#pragma once

#define INPUT_SETTINGS_FILE_NAME ".input.settings"
29 changes: 25 additions & 4 deletions applications/services/power/power_service/power.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -615,7 +636,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);
Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions applications/services/power/power_service/power_i.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ struct Power {
bool app_running;
FuriPubSub* input_events_pubsub;
FuriPubSubSubscription* input_events_subscription;
bool charge_is_supressed;
};

typedef enum {
Expand Down
30 changes: 15 additions & 15 deletions applications/services/power/power_service/power_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -25,31 +25,31 @@ 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,
sizeof(PowerSettings),
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;
}

free(settings_v0);
free(settings_previous);
}

} while(false);
Expand Down
4 changes: 4 additions & 0 deletions applications/services/power/power_service/power_settings.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
#pragma once

#include <stdint.h>
#include <stdbool.h>

typedef struct {
uint32_t auto_poweroff_delay_ms;
uint8_t charge_supress_percent;
} PowerSettings;

#ifdef __cplusplus
extern "C" {
#endif

void power_settings_load(PowerSettings* settings);
void power_settings_save(const PowerSettings* settings);

#ifdef __cplusplus
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -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] = {
Expand Down
9 changes: 9 additions & 0 deletions applications/settings/input_settings_app/application.fam
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
App(
appid="input_settings",
name="Input",
apptype=FlipperAppType.SETTINGS,
entry_point="input_settings_app",
requires=["input"],
stack_size=1 * 1024,
order=100,
)
Loading

0 comments on commit 9d9a46f

Please sign in to comment.