Skip to content

Commit

Permalink
Merge branch 'dev' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
xMasterX committed Feb 12, 2023
2 parents 49e458f + 8608ba0 commit 8f16dbb
Show file tree
Hide file tree
Showing 10 changed files with 183 additions and 80 deletions.
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
### New changes
* iButton: **Temp Fix of non working emulation on Metakom and Cyfral protocols**
* Archive and FileBrowser: **Sort files and folders alphabetically.** Added a "Internal" tab to the Browser (only in DEBUG mode), other misc changes (by @ClaraCrazy and @Willy-JL | PR #327)
* SubGHz: Custom modulation for lrs pagers and added frequency 467.75 to default list (by @jbohack | PR #328)
* SubGHz: **Small fixes in SubGHz HAL**
* Archive and FileBrowser: Fixed #332 (large folders parse issue)
* Archive and FileBrowser: Fixed navigation issues and improved performance (by @Willy-JL | PR #333)
* SubGHz -> HAL: **Fixed external CC1101 module issues** (transmission now works correctly) (fixed issue #331)
* SubGHz: Use 17 (1W) pin for subghz debug mode

#### [🎲 Download latest extra apps pack](https://download-directory.github.io/?url=https://github.com/xMasterX/unleashed-extra-pack/tree/main/apps)

Expand Down
9 changes: 7 additions & 2 deletions applications/main/archive/helpers/archive_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,14 @@ static void archive_list_load_cb(void* context, uint32_t list_load_offset) {
false);
}

static void
archive_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
static void archive_list_item_cb(
void* context,
FuriString* item_path,
uint32_t idx,
bool is_folder,
bool is_last) {
furi_assert(context);
UNUSED(idx);
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;

if(!is_last) {
Expand Down
2 changes: 1 addition & 1 deletion applications/main/archive/views/archive_browser_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ static bool archive_view_input(InputEvent* event, void* context) {
model->scroll_counter = 0;
}
},
true);
false);
archive_update_offset(browser);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const char* const radio_modules_variables_text[] = {
#define DEBUG_P_COUNT 2
const char* const debug_pin_text[DEBUG_P_COUNT] = {
"OFF",
"A7",
"17(1W)",
};

static void subghz_scene_ext_module_changed(VariableItem* item) {
Expand Down
4 changes: 2 additions & 2 deletions applications/main/subghz/subghz_i.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ void subghz_hopper_update(SubGhz* subghz) {

void subghz_speaker_on(SubGhz* subghz) {
if(subghz->txrx->debug_pin_state) {
furi_hal_subghz_set_async_mirror_pin(&gpio_ext_pa7);
furi_hal_subghz_set_async_mirror_pin(&ibutton_gpio);
}

if(subghz->txrx->speaker_state == SubGhzSpeakerStateEnable) {
Expand Down Expand Up @@ -643,7 +643,7 @@ void subghz_speaker_mute(SubGhz* subghz) {

void subghz_speaker_unmute(SubGhz* subghz) {
if(subghz->txrx->debug_pin_state) {
furi_hal_subghz_set_async_mirror_pin(&gpio_ext_pa7);
furi_hal_subghz_set_async_mirror_pin(&ibutton_gpio);
}
if(subghz->txrx->speaker_state == SubGhzSpeakerStateEnable) {
if(furi_hal_speaker_is_mine()) {
Expand Down
13 changes: 7 additions & 6 deletions applications/main/subghz/views/subghz_frequency_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@
#define MAX_HISTORY 4

static const uint32_t subghz_frequency_list[] = {
300000000, 302757000, 303875000, 304250000, 307000000, 307500000, 307800000, 309000000,
310000000, 312000000, 312100000, 313000000, 313850000, 314000000, 314350000, 314980000,
315000000, 318000000, 330000000, 345000000, 348000000, 350000000, 387000000, 390000000,
418000000, 433075000, 433220000, 433420000, 433657070, 433889000, 433920000, 434075000,
434176948, 434390000, 434420000, 434775000, 438900000, 440175000, 464000000, 467750000, 779000000,
868350000, 868400000, 868800000, 868950000, 906400000, 915000000, 925000000, 928000000};
300000000, 302757000, 303875000, 304250000, 307000000, 307500000, 307800000,
309000000, 310000000, 312000000, 312100000, 313000000, 313850000, 314000000,
314350000, 314980000, 315000000, 318000000, 330000000, 345000000, 348000000,
350000000, 387000000, 390000000, 418000000, 433075000, 433220000, 433420000,
433657070, 433889000, 433920000, 434075000, 434176948, 434390000, 434420000,
434775000, 438900000, 440175000, 464000000, 467750000, 779000000, 868350000,
868400000, 868800000, 868950000, 906400000, 915000000, 925000000, 928000000};

typedef enum {
SubGhzFrequencyAnalyzerStatusIDLE,
Expand Down
56 changes: 42 additions & 14 deletions applications/services/gui/modules/file_browser.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,23 @@ typedef enum {
} BrowserItemType;

typedef struct {
uint32_t unsorted_idx;
FuriString* path;
BrowserItemType type;
uint8_t* custom_icon_data;
FuriString* display_name;
} BrowserItem_t;

static void BrowserItem_t_init(BrowserItem_t* obj) {
obj->unsorted_idx = 0;
obj->type = BrowserItemTypeLoading;
obj->path = furi_string_alloc();
obj->display_name = furi_string_alloc();
obj->custom_icon_data = NULL;
}

static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src) {
obj->unsorted_idx = src->unsorted_idx;
obj->type = src->type;
obj->path = furi_string_alloc_set(src->path);
obj->display_name = furi_string_alloc_set(src->display_name);
Expand All @@ -60,6 +63,7 @@ static void BrowserItem_t_init_set(BrowserItem_t* obj, const BrowserItem_t* src)
}

static void BrowserItem_t_set(BrowserItem_t* obj, const BrowserItem_t* src) {
obj->unsorted_idx = src->unsorted_idx;
obj->type = src->type;
furi_string_set(obj->path, src->path);
furi_string_set(obj->display_name, src->display_name);
Expand Down Expand Up @@ -157,8 +161,12 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context);
static void
browser_folder_open_cb(void* context, uint32_t item_cnt, int32_t file_idx, bool is_root);
static void browser_list_load_cb(void* context, uint32_t list_load_offset);
static void
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last);
static void browser_list_item_cb(
void* context,
FuriString* item_path,
uint32_t idx,
bool is_folder,
bool is_last);
static void browser_long_load_cb(void* context);

static void file_browser_scroll_timer_callback(void* context) {
Expand Down Expand Up @@ -347,7 +355,7 @@ static void browser_update_offset(FileBrowser* browser) {
CLAMP(model->item_idx - 1, (int32_t)model->item_cnt - bounds, 0);
}
},
false);
true);
}

static void
Expand Down Expand Up @@ -379,7 +387,7 @@ static void
model->list_loading = true;
model->folder_loading = false;
},
true);
false);
browser_update_offset(browser);

file_browser_worker_load(browser->worker, load_offset, ITEM_LIST_LEN_MAX);
Expand Down Expand Up @@ -412,13 +420,18 @@ static void browser_list_load_cb(void* context, uint32_t list_load_offset) {
BrowserItem_t_clear(&back_item);
}

static void
browser_list_item_cb(void* context, FuriString* item_path, bool is_folder, bool is_last) {
static void browser_list_item_cb(
void* context,
FuriString* item_path,
uint32_t idx,
bool is_folder,
bool is_last) {
furi_assert(context);
FileBrowser* browser = (FileBrowser*)context;

BrowserItem_t item;
item.custom_icon_data = NULL;
item.unsorted_idx = idx;

if(!is_last) {
item.path = furi_string_alloc_set(item_path);
Expand Down Expand Up @@ -454,7 +467,7 @@ static void
items_array_push_back(model->items, item);
// TODO: calculate if element is visible
},
true);
false);
furi_string_free(item.display_name);
furi_string_free(item.path);
if(item.custom_icon_data) {
Expand All @@ -465,10 +478,28 @@ static void
browser->view,
FileBrowserModel * model,
{
items_array_sort(model->items);
if(model->item_cnt < 430) {
FuriString* selected = NULL;
if(model->item_idx > 0) {
selected = furi_string_alloc_set(
items_array_get(model->items, model->item_idx)->path);
}

items_array_sort(model->items);

if(selected != NULL) {
for(uint32_t i = 0; i < model->item_cnt; i++) {
if(!furi_string_cmp(items_array_get(model->items, i)->path, selected)) {
model->item_idx = i;
break;
}
}
}
}
model->list_loading = false;
},
true);
false);
browser_update_offset(browser);
}
}

Expand Down Expand Up @@ -652,7 +683,7 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
model->scroll_counter = 0;
}
},
true);
false);
browser_update_offset(browser);
consumed = true;
}
Expand All @@ -667,10 +698,7 @@ static bool file_browser_view_input_callback(InputEvent* event, void* context) {
if(browser_is_item_in_array(model, model->item_idx)) {
selected_item =
items_array_get(model->items, model->item_idx - model->array_offset);
select_index = model->item_idx;
if((!model->is_root) && (select_index > 0)) {
select_index -= 1;
}
select_index = selected_item->unsorted_idx;
}
},
false);
Expand Down
129 changes: 96 additions & 33 deletions applications/services/gui/modules/file_browser_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,12 @@ static bool browser_folder_init(
return state;
}

static bool
browser_folder_load(BrowserWorker* browser, FuriString* path, uint32_t offset, uint32_t count) {
// Load files list by chunks, like it was originally, not compatible with sorting, sorting needs to be disabled to use this
static bool browser_folder_load_chunked(
BrowserWorker* browser,
FuriString* path,
uint32_t offset,
uint32_t count) {
FileInfo file_info;

Storage* storage = furi_record_open(RECORD_STORAGE);
Expand All @@ -202,39 +206,89 @@ static bool

uint32_t items_cnt = 0;

bool ret = false;
do {
if(!storage_dir_open(directory, furi_string_get_cstr(path))) {
break;
}

// items_cnt = 0;
// while(items_cnt < offset) {
// if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
// break;
// }
// if(storage_file_get_error(directory) == FSE_OK) {
// furi_string_set(name_str, name_temp);
// if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
// items_cnt++;
// }
// } else {
// break;
// }
// }
// if(items_cnt != offset) {
// break;
// }

// FLIPPER DEVS MOMENT
// this used to load the file list in chunks, and then sort it...
// so while scrolling, it loads more files and sorts them...
// chances are, the new files are higher in the sorted list...
// so the files keep shifting around while scrolling...
// now this does something intelligent and loads all in one go.
// might take a few milliseconds longer, but atleast it works :kekw:
UNUSED(offset);
UNUSED(count);
items_cnt = 0;
while(items_cnt < offset) {
if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
break;
}
if(storage_file_get_error(directory) == FSE_OK) {
furi_string_set(name_str, name_temp);
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
items_cnt++;
}
} else {
break;
}
}
if(items_cnt != offset) {
break;
}

if(browser->list_load_cb) {
browser->list_load_cb(browser->cb_ctx, offset);
}

items_cnt = 0;
while(items_cnt < count) {
if(!storage_dir_read(directory, &file_info, name_temp, FILE_NAME_LEN_MAX)) {
break;
}
if(storage_file_get_error(directory) == FSE_OK) {
furi_string_set(name_str, name_temp);
if(browser_filter_by_name(browser, name_str, (file_info.flags & FSF_DIRECTORY))) {
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
if(browser->list_item_cb) {
browser->list_item_cb(
browser->cb_ctx,
name_str,
items_cnt,
(file_info.flags & FSF_DIRECTORY),
false);
}
items_cnt++;
}
} else {
break;
}
}
if(browser->list_item_cb) {
browser->list_item_cb(browser->cb_ctx, NULL, 0, false, true);
}
} while(0);

furi_string_free(name_str);

storage_dir_close(directory);
storage_file_free(directory);

furi_record_close(RECORD_STORAGE);

return (items_cnt == count);
}

// Load all files at once, may cause memory overflow so need to limit that to about 400 files
static bool browser_folder_load_full(BrowserWorker* browser, FuriString* path) {
FileInfo file_info;

Storage* storage = furi_record_open(RECORD_STORAGE);
File* directory = storage_file_alloc(storage);

char name_temp[FILE_NAME_LEN_MAX];
FuriString* name_str;
name_str = furi_string_alloc();

uint32_t items_cnt = 0;

bool ret = false;
do {
if(!storage_dir_open(directory, furi_string_get_cstr(path))) {
break;
}
if(browser->list_load_cb) {
browser->list_load_cb(browser->cb_ctx, 0);
}
Expand All @@ -245,13 +299,17 @@ static bool
furi_string_printf(name_str, "%s/%s", furi_string_get_cstr(path), name_temp);
if(browser->list_item_cb) {
browser->list_item_cb(
browser->cb_ctx, name_str, (file_info.flags & FSF_DIRECTORY), false);
browser->cb_ctx,
name_str,
items_cnt,
(file_info.flags & FSF_DIRECTORY),
false);
}
items_cnt++;
}
}
if(browser->list_item_cb) {
browser->list_item_cb(browser->cb_ctx, NULL, false, true);
browser->list_item_cb(browser->cb_ctx, NULL, 0, false, true);
}
ret = true;
} while(0);
Expand Down Expand Up @@ -360,7 +418,12 @@ static int32_t browser_worker(void* context) {
if(flags & WorkerEvtLoad) {
FURI_LOG_D(
TAG, "Load offset: %lu cnt: %lu", browser->load_offset, browser->load_count);
browser_folder_load(browser, path, browser->load_offset, browser->load_count);
if(items_cnt > 430) {
browser_folder_load_chunked(
browser, path, browser->load_offset, browser->load_count);
} else {
browser_folder_load_full(browser, path);
}
}

if(flags & WorkerEvtStop) {
Expand Down
Loading

0 comments on commit 8f16dbb

Please sign in to comment.