Skip to content

Commit

Permalink
Latest Release RM0417-0500-0.100.4-aa81756 on PATREON & GitHub - LIB …
Browse files Browse the repository at this point in the history
…UPDATES

FROM Willy-JL / MNTM
  • Loading branch information
RogueMaster committed Apr 17, 2024
1 parent 06d4994 commit 9872e13
Show file tree
Hide file tree
Showing 17 changed files with 152 additions and 59 deletions.
8 changes: 6 additions & 2 deletions lib/ble_profile/extra_profiles/hid_profile.c
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,17 @@ static void ble_profile_hid_get_config(GapConfig* config, FuriHalBleProfileParam

// Set advertise name
memset(config->adv_name, 0, sizeof(config->adv_name));
FuriString* name = furi_string_alloc_set(furi_hal_version_get_ble_local_device_name_ptr());

const char* clicker_str = "Control";
if(hid_profile_params && hid_profile_params->device_name_prefix) {
clicker_str = hid_profile_params->device_name_prefix;
}
furi_string_replace_str(name, "Flipper", clicker_str);
// We don't have Flipper in BLE name, use printf instead of replace
FuriString* name = furi_string_alloc_printf(
"%c%s %s",
furi_hal_version_get_ble_local_device_name_ptr()[0],
clicker_str,
furi_hal_version_get_ble_local_device_name_ptr() + 1);
if(furi_string_size(name) >= sizeof(config->adv_name)) {
furi_string_left(name, sizeof(config->adv_name) - 1);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ env.Append(
"#/lib/drivers",
],
SDK_HEADERS=[
File("cc1101_regs.h"),
File("rgb_backlight.h"),
File("cc1101_regs.h"),
File("st25r3916_reg.h"),
File("st25r3916.h"),
],
Expand Down
2 changes: 1 addition & 1 deletion lib/drivers/SK6805.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/* Настройки */
#define SK6805_LED_PIN &led_pin // LED connection port

#ifdef FURI_DEBUG
#if false
#define DEBUG_PIN &gpio_ext_pa7
#define DEBUG_INIT() \
furi_hal_gpio_init(DEBUG_PIN, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh)
Expand Down
78 changes: 51 additions & 27 deletions lib/drivers/rgb_backlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,48 @@ uint8_t rgb_backlight_get_rainbow_saturation(void) {
return rainbow_saturation;
}

static void rainbow_timer(void* ctx) {
void rainbow_timer(void* ctx) {
if(!rgb_state.settings_loaded) return;
furi_check(furi_mutex_acquire(rgb_state.mutex, FuriWaitForever) == FuriStatusOk);

if(!rgb_state.enabled || rgb_settings.rainbow_mode == RGBBacklightRainbowModeOff ||
!rgb_state.last_brightness) {
furi_check(furi_mutex_release(rgb_state.mutex) == FuriStatusOk);
return;
}

rgb_state.rainbow_hsv.h += rgb_settings.rainbow_speed;

RgbColor rgb;
hsv2rgb(&rgb_state.rainbow_hsv, &rgb);

switch(rgb_settings.rainbow_mode) {
case RGBBacklightRainbowModeWave: {
HsvColor hsv = rgb_state.rainbow_hsv;
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
if(i) {
hsv.h += (50 * i);
hsv2rgb(&hsv, &rgb);
}
SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b);
}
break;
}

case RGBBacklightRainbowModeSolid:
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b);
}
break;

default:
break;
}

SK6805_update();

furi_check(furi_mutex_release(rgb_state.mutex) == FuriStatusOk);
UNUSED(ctx);
rgb_backlight_update(rgb_state.last_brightness, true);
}

void rgb_backlight_reconfigure(bool enabled) {
Expand All @@ -226,16 +265,16 @@ void rgb_backlight_reconfigure(bool enabled) {
rgb_state.rainbow_timer = NULL;
}
rgb_state.rainbow_hsv.s = rgb_settings.rainbow_saturation;
rgb_backlight_update(rgb_state.last_brightness, false);
rgb_backlight_update(rgb_state.last_brightness, true);

furi_check(furi_mutex_release(rgb_state.mutex) == FuriStatusOk);
}

void rgb_backlight_update(uint8_t brightness, bool tick) {
void rgb_backlight_update(uint8_t brightness, bool forced) {
if(!rgb_state.settings_loaded) return;
furi_check(furi_mutex_acquire(rgb_state.mutex, FuriWaitForever) == FuriStatusOk);

if(!rgb_state.enabled) {
if(!rgb_state.enabled || (brightness == rgb_state.last_brightness && !forced)) {
furi_check(furi_mutex_release(rgb_state.mutex) == FuriStatusOk);
return;
}
Expand All @@ -255,29 +294,14 @@ void rgb_backlight_update(uint8_t brightness, bool tick) {

case RGBBacklightRainbowModeWave:
case RGBBacklightRainbowModeSolid: {
if(tick && brightness) {
rgb_state.rainbow_hsv.h += rgb_settings.rainbow_speed;
} else {
rgb_state.rainbow_hsv.v = brightness;
}

RgbColor rgb;
hsv2rgb(&rgb_state.rainbow_hsv, &rgb);

if(rgb_settings.rainbow_mode == RGBBacklightRainbowModeWave) {
HsvColor hsv = rgb_state.rainbow_hsv;
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
if(i) {
hsv.h += (50 * i);
hsv2rgb(&hsv, &rgb);
}
SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b);
}
} else {
if(!brightness) {
furi_timer_stop(rgb_state.rainbow_timer);
for(uint8_t i = 0; i < SK6805_get_led_count(); i++) {
SK6805_set_led_color(i, rgb.r, rgb.g, rgb.b);
SK6805_set_led_color(i, 0, 0, 0);
}
}
} else if(!rgb_state.last_brightness)
furi_timer_start(rgb_state.rainbow_timer, rgb_settings.rainbow_interval);
rgb_state.rainbow_hsv.v = brightness;
break;
}

Expand All @@ -290,4 +314,4 @@ void rgb_backlight_update(uint8_t brightness, bool tick) {
SK6805_update();

furi_check(furi_mutex_release(rgb_state.mutex) == FuriStatusOk);
}
}
6 changes: 3 additions & 3 deletions lib/drivers/rgb_backlight.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,10 @@ void rgb_backlight_reconfigure(bool enabled);
* @brief Apply current RGB lighting settings
*
* @param brightness Backlight intensity (0-255)
* @param tick Whether this update was a tick (for rainbow)
* @param forced force a update even brightness doesnt changed
*/
void rgb_backlight_update(uint8_t brightness, bool tick);
void rgb_backlight_update(uint8_t brightness, bool forced);

#ifdef __cplusplus
}
#endif
#endif
2 changes: 1 addition & 1 deletion lib/fatfs/ff.c
Original file line number Diff line number Diff line change
Expand Up @@ -5371,7 +5371,7 @@ FRESULT f_mkfs (
/* Pre-determine the FAT type */
do {
if (_FS_EXFAT && (opt & FM_EXFAT)) { /* exFAT possible? */
if ((opt & FM_ANY) == FM_EXFAT || sz_vol >= 0x4000000 || au > 128) { /* exFAT only, vol >= 64Ms or au > 128s ? */
if ((opt & FM_ANY) == FM_EXFAT || sz_vol >= 0x2000000 || au > 128) { /* exFAT only, vol >= 32Ms or au > 128s ? */
fmt = FS_EXFAT; break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/flipper_application/flipper_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -387,4 +387,4 @@ bool flipper_application_load_name_and_icon(
}

return load_success;
}
}
4 changes: 3 additions & 1 deletion lib/flipper_application/plugins/plugin_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

#define TAG "PluginManager"

#define MAX_NAME_LEN 254

ARRAY_DEF(FlipperApplicationList, FlipperApplication*, M_PTR_OPLIST)
#define M_OPL_FlipperApplicationList_t() ARRAY_OPLIST(FlipperApplicationList, M_PTR_OPLIST)

Expand Down Expand Up @@ -108,7 +110,7 @@ PluginManagerError plugin_manager_load_single(PluginManager* manager, const char
PluginManagerError plugin_manager_load_all(PluginManager* manager, const char* path) {
furi_check(manager);
File* directory = storage_file_alloc(manager->storage);
char file_name_buffer[256];
char file_name_buffer[MAX_NAME_LEN];
FuriString* file_name = furi_string_alloc();
do {
if(!storage_dir_open(directory, path)) {
Expand Down
10 changes: 5 additions & 5 deletions lib/lfs_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

#include <furi.h>

#ifdef FURI_NDEBUG
#define LFS_NO_ASSERT
#define LFS_ASSERT(x)
#else
// #ifdef FURI_NDEBUG
// #define LFS_NO_ASSERT
// #define LFS_ASSERT(x)
// #else
#define LFS_ASSERT furi_assert
#endif
// #endif

#define LFS_TAG "Lfs"

Expand Down
2 changes: 1 addition & 1 deletion lib/toolbox/colors.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ int rgb565cmp(const Rgb565Color* a, const Rgb565Color* b);

#ifdef __cplusplus
}
#endif
#endif
46 changes: 37 additions & 9 deletions lib/toolbox/dir_walk.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "dir_walk.h"
#include <m-list.h>

#define MAX_NAME_LEN 254

LIST_DEF(DirIndexList, uint32_t);

struct DirWalk {
Expand All @@ -11,6 +13,8 @@ struct DirWalk {
bool recursive;
DirWalkFilterCb filter_cb;
void* filter_context;
const char** recurse_filter;
size_t recurse_filter_count;
};

DirWalk* dir_walk_alloc(Storage* storage) {
Expand All @@ -22,6 +26,8 @@ DirWalk* dir_walk_alloc(Storage* storage) {
DirIndexList_init(dir_walk->index_list);
dir_walk->recursive = true;
dir_walk->filter_cb = NULL;
dir_walk->recurse_filter = NULL;
dir_walk->recurse_filter_count = 0;
return dir_walk;
}

Expand All @@ -45,6 +51,11 @@ void dir_walk_set_filter_cb(DirWalk* dir_walk, DirWalkFilterCb cb, void* context
dir_walk->filter_context = context;
}

void dir_walk_set_recurse_filter(DirWalk* dir_walk, const char** array, size_t count) {
dir_walk->recurse_filter = array;
dir_walk->recurse_filter_count = count;
}

bool dir_walk_open(DirWalk* dir_walk, const char* path) {
furi_check(dir_walk);
furi_string_set(dir_walk->path, path);
Expand All @@ -63,12 +74,12 @@ static bool dir_walk_filter(DirWalk* dir_walk, const char* name, FileInfo* filei
static DirWalkResult
dir_walk_iter(DirWalk* dir_walk, FuriString* return_path, FileInfo* fileinfo) {
DirWalkResult result = DirWalkError;
char* name = malloc(256); // FIXME: remove magic number
char* name = malloc(MAX_NAME_LEN);
FileInfo info;
bool end = false;

while(!end) {
storage_dir_read(dir_walk->file, &info, name, 255);
storage_dir_read(dir_walk->file, &info, name, MAX_NAME_LEN);

if(storage_file_get_error(dir_walk->file) == FSE_OK) {
result = DirWalkOK;
Expand All @@ -91,13 +102,30 @@ static DirWalkResult
}

if(file_info_is_dir(&info) && dir_walk->recursive) {
// step into
DirIndexList_push_back(dir_walk->index_list, dir_walk->current_index);
dir_walk->current_index = 0;
storage_dir_close(dir_walk->file);

furi_string_cat_printf(dir_walk->path, "/%s", name);
storage_dir_open(dir_walk->file, furi_string_get_cstr(dir_walk->path));

bool filter = false;
for(size_t i = 0; i < dir_walk->recurse_filter_count; i++) {
if(furi_string_equal_str(dir_walk->path, dir_walk->recurse_filter[i])) {
filter = true;
break;
}
}

if(filter) {
// reset path
size_t last_char = furi_string_search_rchar(dir_walk->path, '/');
if(last_char != FURI_STRING_FAILURE) {
furi_string_left(dir_walk->path, last_char);
}

} else {
// step into
DirIndexList_push_back(dir_walk->index_list, dir_walk->current_index);
dir_walk->current_index = 0;
storage_dir_close(dir_walk->file);
storage_dir_open(dir_walk->file, furi_string_get_cstr(dir_walk->path));
}
}
} else if(storage_file_get_error(dir_walk->file) == FSE_NOT_EXIST) {
if(DirIndexList_size(dir_walk->index_list) == 0) {
Expand Down Expand Up @@ -126,7 +154,7 @@ static DirWalkResult
break;
}

if(!storage_dir_read(dir_walk->file, &info, name, 255)) {
if(!storage_dir_read(dir_walk->file, &info, name, MAX_NAME_LEN)) {
result = DirWalkError;
end = true;
break;
Expand Down
10 changes: 9 additions & 1 deletion lib/toolbox/dir_walk.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,14 @@ void dir_walk_set_recursive(DirWalk* dir_walk, bool recursive);
*/
void dir_walk_set_filter_cb(DirWalk* dir_walk, DirWalkFilterCb cb, void* context);

/**
* Set recurse filtered paths
* @param dir_walk
* @param array
* @param count
*/
void dir_walk_set_recurse_filter(DirWalk* dir_walk, const char** array, size_t count);

/**
* Open directory
* @param dir_walk
Expand Down Expand Up @@ -76,4 +84,4 @@ void dir_walk_close(DirWalk* dir_walk);

#ifdef __cplusplus
}
#endif
#endif
12 changes: 12 additions & 0 deletions lib/toolbox/path.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@ void path_extract_filename(FuriString* path, FuriString* name, bool trim_ext) {
}
}

void path_extract_ext_str(FuriString* path, FuriString* ext) {
size_t dot = furi_string_search_rchar(path, '.');
size_t filename_start = furi_string_search_rchar(path, '/');

if(dot != FURI_STRING_FAILURE && filename_start != FURI_STRING_FAILURE &&
filename_start < dot) {
furi_string_set_n(ext, path, dot, furi_string_size(path) - dot);
} else {
furi_string_reset(ext);
}
}

void path_extract_extension(FuriString* path, char* ext, size_t ext_len_max) {
furi_check(path);
furi_check(ext);
Expand Down
8 changes: 8 additions & 0 deletions lib/toolbox/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ void path_extract_filename_no_ext(const char* path, FuriString* filename);
*/
void path_extract_filename(FuriString* path, FuriString* filename, bool trim_ext);

/**
* @brief Extract file extension string from path.
*
* @param path path string
* @param ext output extension furi string
*/
void path_extract_ext_str(FuriString* path, FuriString* ext);

/**
* @brief Extract file extension from path.
*
Expand Down
Loading

0 comments on commit 9872e13

Please sign in to comment.