[FL-976] Removing lambdas (#1849)
* Removing lambdas... * Wake the fk up, Gordon! We have a citadel to burn! * Here comes the Nihilanth * Lambda documentation Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
@@ -21,7 +21,9 @@ static void
|
||||
archive_switch_tab(browser, browser->last_tab_switch_dir);
|
||||
} else if(!furi_string_start_with_str(browser->path, "/app:")) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
files_array_reset(model->files);
|
||||
model->item_cnt = item_cnt;
|
||||
model->item_idx = (file_idx > 0) ? file_idx : 0;
|
||||
@@ -31,8 +33,8 @@ static void
|
||||
model->list_offset = 0;
|
||||
model->list_loading = true;
|
||||
model->folder_loading = false;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
archive_update_offset(browser);
|
||||
|
||||
file_browser_worker_load(browser->worker, load_offset, FILE_LIST_BUF_LEN);
|
||||
@@ -44,11 +46,13 @@ static void archive_list_load_cb(void* context, uint32_t list_load_offset) {
|
||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
files_array_reset(model->files);
|
||||
model->array_offset = list_load_offset;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -60,10 +64,7 @@ static void
|
||||
archive_add_file_item(browser, is_folder, furi_string_get_cstr(item_path));
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->list_loading = false;
|
||||
return true;
|
||||
});
|
||||
browser->view, ArchiveBrowserViewModel * model, { model->list_loading = false; }, true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,10 +73,7 @@ static void archive_long_load_cb(void* context) {
|
||||
ArchiveBrowserView* browser = (ArchiveBrowserView*)context;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->folder_loading = true;
|
||||
return true;
|
||||
});
|
||||
browser->view, ArchiveBrowserViewModel * model, { model->folder_loading = true; }, true);
|
||||
}
|
||||
|
||||
static void archive_file_browser_set_path(
|
||||
@@ -113,7 +111,9 @@ void archive_update_offset(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
uint16_t bounds = model->item_cnt > 3 ? 2 : model->item_cnt;
|
||||
|
||||
if((model->item_cnt > 3u) && (model->item_idx >= ((int32_t)model->item_cnt - 1))) {
|
||||
@@ -125,9 +125,8 @@ void archive_update_offset(ArchiveBrowserView* browser) {
|
||||
model->list_offset =
|
||||
CLAMP(model->item_idx - 1, (int32_t)model->item_cnt - bounds, 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
||||
@@ -140,7 +139,9 @@ void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
||||
archive_switch_tab(browser, TAB_RIGHT);
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
uint16_t idx = 0;
|
||||
while(idx < files_array_size(model->files)) {
|
||||
ArchiveFile_t* current = files_array_get(model->files, idx);
|
||||
@@ -150,8 +151,8 @@ void archive_update_focus(ArchiveBrowserView* browser, const char* target) {
|
||||
}
|
||||
++idx;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
@@ -162,10 +163,10 @@ size_t archive_file_get_array_size(ArchiveBrowserView* browser) {
|
||||
|
||||
uint16_t size = 0;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
size = files_array_size(model->files);
|
||||
return false;
|
||||
});
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{ size = files_array_size(model->files); },
|
||||
false);
|
||||
return size;
|
||||
}
|
||||
|
||||
@@ -173,11 +174,13 @@ void archive_set_item_count(ArchiveBrowserView* browser, uint32_t count) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
model->item_cnt = count;
|
||||
model->item_idx = CLAMP(model->item_idx, (int32_t)model->item_cnt - 1, 0);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
|
||||
@@ -186,7 +189,9 @@ void archive_file_array_rm_selected(ArchiveBrowserView* browser) {
|
||||
uint32_t items_cnt = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
files_array_remove_v(
|
||||
model->files,
|
||||
model->item_idx - model->array_offset,
|
||||
@@ -194,8 +199,8 @@ void archive_file_array_rm_selected(ArchiveBrowserView* browser) {
|
||||
model->item_cnt--;
|
||||
model->item_idx = CLAMP(model->item_idx, (int32_t)model->item_cnt - 1, 0);
|
||||
items_cnt = model->item_cnt;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
|
||||
if((items_cnt == 0) && (archive_is_home(browser))) {
|
||||
archive_switch_tab(browser, TAB_RIGHT);
|
||||
@@ -208,7 +213,9 @@ void archive_file_array_swap(ArchiveBrowserView* browser, int8_t dir) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
ArchiveFile_t temp;
|
||||
size_t array_size = files_array_size(model->files) - 1;
|
||||
uint8_t swap_idx = CLAMP((size_t)(model->item_idx + dir), array_size, 0u);
|
||||
@@ -226,18 +233,18 @@ void archive_file_array_swap(ArchiveBrowserView* browser, int8_t dir) {
|
||||
} else {
|
||||
files_array_swap_at(model->files, model->item_idx, swap_idx);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
void archive_file_array_rm_all(ArchiveBrowserView* browser) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_reset(model->files);
|
||||
return false;
|
||||
});
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{ files_array_reset(model->files); },
|
||||
false);
|
||||
}
|
||||
|
||||
void archive_file_array_load(ArchiveBrowserView* browser, int8_t dir) {
|
||||
@@ -246,7 +253,9 @@ void archive_file_array_load(ArchiveBrowserView* browser, int8_t dir) {
|
||||
int32_t offset_new = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
if(model->item_cnt > FILE_LIST_BUF_LEN) {
|
||||
if(dir < 0) {
|
||||
offset_new = model->item_idx - FILE_LIST_BUF_LEN / 4 * 3;
|
||||
@@ -262,8 +271,8 @@ void archive_file_array_load(ArchiveBrowserView* browser, int8_t dir) {
|
||||
offset_new = 0;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
|
||||
file_browser_worker_load(browser->worker, offset_new, FILE_LIST_BUF_LEN);
|
||||
}
|
||||
@@ -273,12 +282,14 @@ ArchiveFile_t* archive_get_current_file(ArchiveBrowserView* browser) {
|
||||
|
||||
ArchiveFile_t* selected = NULL;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
selected = files_array_size(model->files) ?
|
||||
files_array_get(model->files, model->item_idx - model->array_offset) :
|
||||
NULL;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
return selected;
|
||||
}
|
||||
|
||||
@@ -288,11 +299,13 @@ ArchiveFile_t* archive_get_file_at(ArchiveBrowserView* browser, size_t idx) {
|
||||
ArchiveFile_t* selected = NULL;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
idx = CLAMP(idx - model->array_offset, files_array_size(model->files), 0u);
|
||||
selected = files_array_size(model->files) ? files_array_get(model->files, idx) : NULL;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
return selected;
|
||||
}
|
||||
|
||||
@@ -301,10 +314,7 @@ ArchiveTabEnum archive_get_tab(ArchiveBrowserView* browser) {
|
||||
|
||||
ArchiveTabEnum tab_id = 0;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
tab_id = model->tab_idx;
|
||||
return false;
|
||||
});
|
||||
browser->view, ArchiveBrowserViewModel * model, { tab_id = model->tab_idx; }, false);
|
||||
return tab_id;
|
||||
}
|
||||
|
||||
@@ -328,10 +338,7 @@ void archive_set_tab(ArchiveBrowserView* browser, ArchiveTabEnum tab) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->tab_idx = tab;
|
||||
return false;
|
||||
});
|
||||
browser->view, ArchiveBrowserViewModel * model, { model->tab_idx = tab; }, false);
|
||||
}
|
||||
|
||||
void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
|
||||
@@ -344,11 +351,13 @@ void archive_add_app_item(ArchiveBrowserView* browser, const char* name) {
|
||||
archive_set_file_type(&item, name, false, true);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
files_array_push_back(model->files, item);
|
||||
model->item_cnt = files_array_size(model->files);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
ArchiveFile_t_clear(&item);
|
||||
}
|
||||
|
||||
@@ -379,17 +388,19 @@ void archive_add_file_item(ArchiveBrowserView* browser, bool is_folder, const ch
|
||||
}
|
||||
}
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_push_back(model->files, item);
|
||||
return false;
|
||||
});
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{ files_array_push_back(model->files, item); },
|
||||
false);
|
||||
ArchiveFile_t_clear(&item);
|
||||
}
|
||||
|
||||
void archive_show_file_menu(ArchiveBrowserView* browser, bool show) {
|
||||
furi_assert(browser);
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
if(show) {
|
||||
if(archive_is_item_in_array(model, model->item_idx)) {
|
||||
model->menu = true;
|
||||
@@ -403,19 +414,15 @@ void archive_show_file_menu(ArchiveBrowserView* browser, bool show) {
|
||||
model->menu = false;
|
||||
model->menu_idx = 0;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void archive_favorites_move_mode(ArchiveBrowserView* browser, bool active) {
|
||||
furi_assert(browser);
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
model->move_fav = active;
|
||||
return true;
|
||||
});
|
||||
browser->view, ArchiveBrowserViewModel * model, { model->move_fav = active; }, true);
|
||||
}
|
||||
|
||||
static bool archive_is_dir_exists(FuriString* path) {
|
||||
@@ -476,11 +483,13 @@ void archive_switch_tab(ArchiveBrowserView* browser, InputKey key) {
|
||||
archive_switch_tab(browser, key);
|
||||
} else {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
model->item_idx = 0;
|
||||
model->array_offset = 0;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
archive_get_items(browser, furi_string_get_cstr(browser->path));
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
@@ -493,10 +502,7 @@ void archive_enter_dir(ArchiveBrowserView* browser, FuriString* path) {
|
||||
int32_t idx_temp = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
idx_temp = model->item_idx;
|
||||
return false;
|
||||
});
|
||||
browser->view, ArchiveBrowserViewModel * model, { idx_temp = model->item_idx; }, false);
|
||||
|
||||
furi_string_set(browser->path, path);
|
||||
file_browser_worker_folder_enter(browser->worker, path, idx_temp);
|
||||
@@ -514,9 +520,6 @@ void archive_refresh_dir(ArchiveBrowserView* browser) {
|
||||
int32_t idx_temp = 0;
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
idx_temp = model->item_idx;
|
||||
return false;
|
||||
});
|
||||
browser->view, ArchiveBrowserViewModel * model, { idx_temp = model->item_idx; }, false);
|
||||
file_browser_worker_folder_refresh(browser->worker, idx_temp);
|
||||
}
|
||||
|
@@ -263,33 +263,37 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
bool in_menu;
|
||||
bool move_fav_mode;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
in_menu = model->menu;
|
||||
move_fav_mode = model->move_fav;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
|
||||
if(in_menu) {
|
||||
if(event->type == InputTypeShort) {
|
||||
if(event->key == InputKeyUp || event->key == InputKeyDown) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
if(event->key == InputKeyUp) {
|
||||
model->menu_idx = ((model->menu_idx - 1) + MENU_ITEMS) % MENU_ITEMS;
|
||||
} else if(event->key == InputKeyDown) {
|
||||
model->menu_idx = (model->menu_idx + 1) % MENU_ITEMS;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
if(event->key == InputKeyOk) {
|
||||
uint8_t idx;
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
idx = model->menu_idx;
|
||||
return false;
|
||||
});
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{ idx = model->menu_idx; },
|
||||
false);
|
||||
browser->callback(file_menu_actions[idx], browser->context);
|
||||
} else if(event->key == InputKeyBack) {
|
||||
browser->callback(ArchiveBrowserEventFileMenuClose, browser->context);
|
||||
@@ -313,7 +317,9 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
if((event->key == InputKeyUp || event->key == InputKeyDown) &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
if(event->key == InputKeyUp) {
|
||||
model->item_idx =
|
||||
((model->item_idx - 1) + model->item_cnt) % model->item_cnt;
|
||||
@@ -334,9 +340,8 @@ static bool archive_view_input(InputEvent* event, void* context) {
|
||||
browser->callback(ArchiveBrowserEventFavMoveDown, browser->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
archive_update_offset(browser);
|
||||
}
|
||||
|
||||
@@ -384,11 +389,13 @@ ArchiveBrowserView* browser_alloc() {
|
||||
browser->path = furi_string_alloc_set(archive_get_default_path(TAB_DEFAULT));
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{
|
||||
files_array_init(model->files);
|
||||
model->tab_idx = TAB_DEFAULT;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return browser;
|
||||
}
|
||||
@@ -401,10 +408,10 @@ void browser_free(ArchiveBrowserView* browser) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
browser->view, (ArchiveBrowserViewModel * model) {
|
||||
files_array_clear(model->files);
|
||||
return false;
|
||||
});
|
||||
browser->view,
|
||||
ArchiveBrowserViewModel * model,
|
||||
{ files_array_clear(model->files); },
|
||||
false);
|
||||
|
||||
furi_string_free(browser->path);
|
||||
|
||||
|
@@ -145,29 +145,33 @@ void bad_usb_set_ok_callback(BadUsb* bad_usb, BadUsbOkCallback callback, void* c
|
||||
furi_assert(bad_usb);
|
||||
furi_assert(callback);
|
||||
with_view_model(
|
||||
bad_usb->view, (BadUsbModel * model) {
|
||||
bad_usb->view,
|
||||
BadUsbModel * model,
|
||||
{
|
||||
UNUSED(model);
|
||||
bad_usb->callback = callback;
|
||||
bad_usb->context = context;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void bad_usb_set_file_name(BadUsb* bad_usb, const char* name) {
|
||||
furi_assert(name);
|
||||
with_view_model(
|
||||
bad_usb->view, (BadUsbModel * model) {
|
||||
strlcpy(model->file_name, name, MAX_NAME_LEN);
|
||||
return true;
|
||||
});
|
||||
bad_usb->view,
|
||||
BadUsbModel * model,
|
||||
{ strlcpy(model->file_name, name, MAX_NAME_LEN); },
|
||||
true);
|
||||
}
|
||||
|
||||
void bad_usb_set_state(BadUsb* bad_usb, BadUsbState* st) {
|
||||
furi_assert(st);
|
||||
with_view_model(
|
||||
bad_usb->view, (BadUsbModel * model) {
|
||||
bad_usb->view,
|
||||
BadUsbModel * model,
|
||||
{
|
||||
memcpy(&(model->state), st, sizeof(BadUsbState));
|
||||
model->anim_frame ^= 1;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
@@ -48,23 +48,27 @@ static bool gpio_test_input_callback(InputEvent* event, void* context) {
|
||||
|
||||
static bool gpio_test_process_left(GpioTest* gpio_test) {
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
gpio_test->view,
|
||||
GpioTestModel * model,
|
||||
{
|
||||
if(model->pin_idx) {
|
||||
model->pin_idx--;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool gpio_test_process_right(GpioTest* gpio_test) {
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
gpio_test->view,
|
||||
GpioTestModel * model,
|
||||
{
|
||||
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
||||
model->pin_idx++;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -72,7 +76,9 @@ static bool gpio_test_process_ok(GpioTest* gpio_test, InputEvent* event) {
|
||||
bool consumed = false;
|
||||
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
gpio_test->view,
|
||||
GpioTestModel * model,
|
||||
{
|
||||
if(event->type == InputTypePress) {
|
||||
if(model->pin_idx < GPIO_ITEM_COUNT) {
|
||||
gpio_item_set_pin(model->pin_idx, true);
|
||||
@@ -89,8 +95,8 @@ static bool gpio_test_process_ok(GpioTest* gpio_test, InputEvent* event) {
|
||||
consumed = true;
|
||||
}
|
||||
gpio_test->callback(event->type, gpio_test->context);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return consumed;
|
||||
}
|
||||
@@ -122,10 +128,12 @@ void gpio_test_set_ok_callback(GpioTest* gpio_test, GpioTestOkCallback callback,
|
||||
furi_assert(gpio_test);
|
||||
furi_assert(callback);
|
||||
with_view_model(
|
||||
gpio_test->view, (GpioTestModel * model) {
|
||||
gpio_test->view,
|
||||
GpioTestModel * model,
|
||||
{
|
||||
UNUSED(model);
|
||||
gpio_test->callback = callback;
|
||||
gpio_test->context = context;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
@@ -129,12 +129,14 @@ void gpio_usb_uart_set_callback(GpioUsbUart* usb_uart, GpioUsbUartCallback callb
|
||||
furi_assert(callback);
|
||||
|
||||
with_view_model(
|
||||
usb_uart->view, (GpioUsbUartModel * model) {
|
||||
usb_uart->view,
|
||||
GpioUsbUartModel * model,
|
||||
{
|
||||
UNUSED(model);
|
||||
usb_uart->callback = callback;
|
||||
usb_uart->context = context;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
void gpio_usb_uart_update_state(GpioUsbUart* instance, UsbUartConfig* cfg, UsbUartState* st) {
|
||||
@@ -143,7 +145,9 @@ void gpio_usb_uart_update_state(GpioUsbUart* instance, UsbUartConfig* cfg, UsbUa
|
||||
furi_assert(st);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (GpioUsbUartModel * model) {
|
||||
instance->view,
|
||||
GpioUsbUartModel * model,
|
||||
{
|
||||
model->baudrate = st->baudrate_cur;
|
||||
model->vcp_port = cfg->vcp_ch;
|
||||
model->tx_pin = (cfg->uart_ch == 0) ? (13) : (15);
|
||||
@@ -152,6 +156,6 @@ void gpio_usb_uart_update_state(GpioUsbUart* instance, UsbUartConfig* cfg, UsbUa
|
||||
model->rx_active = (model->rx_cnt != st->rx_cnt);
|
||||
model->tx_cnt = st->tx_cnt;
|
||||
model->rx_cnt = st->rx_cnt;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
@@ -56,19 +56,13 @@ static void lfrfid_view_read_draw_callback(Canvas* canvas, void* _model) {
|
||||
void lfrfid_view_read_enter(void* context) {
|
||||
LfRfidReadView* read_view = context;
|
||||
with_view_model(
|
||||
read_view->view, (LfRfidReadViewModel * model) {
|
||||
icon_animation_start(model->icon);
|
||||
return true;
|
||||
});
|
||||
read_view->view, LfRfidReadViewModel * model, { icon_animation_start(model->icon); }, true);
|
||||
}
|
||||
|
||||
void lfrfid_view_read_exit(void* context) {
|
||||
LfRfidReadView* read_view = context;
|
||||
with_view_model(
|
||||
read_view->view, (LfRfidReadViewModel * model) {
|
||||
icon_animation_stop(model->icon);
|
||||
return false;
|
||||
});
|
||||
read_view->view, LfRfidReadViewModel * model, { icon_animation_stop(model->icon); }, false);
|
||||
}
|
||||
|
||||
LfRfidReadView* lfrfid_view_read_alloc() {
|
||||
@@ -78,11 +72,13 @@ LfRfidReadView* lfrfid_view_read_alloc() {
|
||||
view_allocate_model(read_view->view, ViewModelTypeLocking, sizeof(LfRfidReadViewModel));
|
||||
|
||||
with_view_model(
|
||||
read_view->view, (LfRfidReadViewModel * model) {
|
||||
read_view->view,
|
||||
LfRfidReadViewModel * model,
|
||||
{
|
||||
model->icon = icon_animation_alloc(&A_Round_loader_8x8);
|
||||
view_tie_icon_animation(read_view->view, model->icon);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
|
||||
view_set_draw_callback(read_view->view, lfrfid_view_read_draw_callback);
|
||||
view_set_enter_callback(read_view->view, lfrfid_view_read_enter);
|
||||
@@ -93,10 +89,7 @@ LfRfidReadView* lfrfid_view_read_alloc() {
|
||||
|
||||
void lfrfid_view_read_free(LfRfidReadView* read_view) {
|
||||
with_view_model(
|
||||
read_view->view, (LfRfidReadViewModel * model) {
|
||||
icon_animation_free(model->icon);
|
||||
return false;
|
||||
});
|
||||
read_view->view, LfRfidReadViewModel * model, { icon_animation_free(model->icon); }, false);
|
||||
|
||||
view_free(read_view->view);
|
||||
free(read_view);
|
||||
@@ -108,10 +101,12 @@ View* lfrfid_view_read_get_view(LfRfidReadView* read_view) {
|
||||
|
||||
void lfrfid_view_read_set_read_mode(LfRfidReadView* read_view, LfRfidReadViewMode mode) {
|
||||
with_view_model(
|
||||
read_view->view, (LfRfidReadViewModel * model) {
|
||||
read_view->view,
|
||||
LfRfidReadViewModel * model,
|
||||
{
|
||||
icon_animation_stop(model->icon);
|
||||
icon_animation_start(model->icon);
|
||||
model->read_mode = mode;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
@@ -64,10 +64,7 @@ static bool detect_reader_input_callback(InputEvent* event, void* context) {
|
||||
|
||||
uint8_t nonces = 0;
|
||||
with_view_model(
|
||||
detect_reader->view, (DetectReaderViewModel * model) {
|
||||
nonces = model->nonces;
|
||||
return false;
|
||||
});
|
||||
detect_reader->view, DetectReaderViewModel * model, { nonces = model->nonces; }, false);
|
||||
|
||||
if(event->type == InputTypeShort) {
|
||||
if(event->key == InputKeyOk) {
|
||||
@@ -103,12 +100,14 @@ void detect_reader_reset(DetectReader* detect_reader) {
|
||||
furi_assert(detect_reader);
|
||||
|
||||
with_view_model(
|
||||
detect_reader->view, (DetectReaderViewModel * model) {
|
||||
detect_reader->view,
|
||||
DetectReaderViewModel * model,
|
||||
{
|
||||
model->nonces = 0;
|
||||
model->nonces_max = 0;
|
||||
model->state = DetectReaderStateStart;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
View* detect_reader_get_view(DetectReader* detect_reader) {
|
||||
@@ -132,27 +131,24 @@ void detect_reader_set_nonces_max(DetectReader* detect_reader, uint16_t nonces_m
|
||||
furi_assert(detect_reader);
|
||||
|
||||
with_view_model(
|
||||
detect_reader->view, (DetectReaderViewModel * model) {
|
||||
model->nonces_max = nonces_max;
|
||||
return false;
|
||||
});
|
||||
detect_reader->view,
|
||||
DetectReaderViewModel * model,
|
||||
{ model->nonces_max = nonces_max; },
|
||||
false);
|
||||
}
|
||||
|
||||
void detect_reader_set_nonces_collected(DetectReader* detect_reader, uint16_t nonces_collected) {
|
||||
furi_assert(detect_reader);
|
||||
|
||||
with_view_model(
|
||||
detect_reader->view, (DetectReaderViewModel * model) {
|
||||
model->nonces = nonces_collected;
|
||||
return false;
|
||||
});
|
||||
detect_reader->view,
|
||||
DetectReaderViewModel * model,
|
||||
{ model->nonces = nonces_collected; },
|
||||
false);
|
||||
}
|
||||
|
||||
void detect_reader_set_state(DetectReader* detect_reader, DetectReaderState state) {
|
||||
furi_assert(detect_reader);
|
||||
with_view_model(
|
||||
detect_reader->view, (DetectReaderViewModel * model) {
|
||||
model->state = state;
|
||||
return true;
|
||||
});
|
||||
detect_reader->view, DetectReaderViewModel * model, { model->state = state; }, true);
|
||||
}
|
||||
|
@@ -80,20 +80,20 @@ DictAttack* dict_attack_alloc() {
|
||||
view_set_input_callback(dict_attack->view, dict_attack_input_callback);
|
||||
view_set_context(dict_attack->view, dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->header = furi_string_alloc();
|
||||
return false;
|
||||
});
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{ model->header = furi_string_alloc(); },
|
||||
false);
|
||||
return dict_attack;
|
||||
}
|
||||
|
||||
void dict_attack_free(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
furi_string_free(model->header);
|
||||
return false;
|
||||
});
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{ furi_string_free(model->header); },
|
||||
false);
|
||||
view_free(dict_attack->view);
|
||||
free(dict_attack);
|
||||
}
|
||||
@@ -101,7 +101,9 @@ void dict_attack_free(DictAttack* dict_attack) {
|
||||
void dict_attack_reset(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{
|
||||
model->state = DictAttackStateRead;
|
||||
model->type = MfClassicType1k;
|
||||
model->sectors_total = 0;
|
||||
@@ -112,8 +114,8 @@ void dict_attack_reset(DictAttack* dict_attack) {
|
||||
model->dict_keys_total = 0;
|
||||
model->dict_keys_current = 0;
|
||||
furi_string_reset(model->header);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
View* dict_attack_get_view(DictAttack* dict_attack) {
|
||||
@@ -133,99 +135,103 @@ void dict_attack_set_header(DictAttack* dict_attack, const char* header) {
|
||||
furi_assert(header);
|
||||
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
furi_string_set(model->header, header);
|
||||
return true;
|
||||
});
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{ furi_string_set(model->header, header); },
|
||||
true);
|
||||
}
|
||||
|
||||
void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{
|
||||
model->state = DictAttackStateRead;
|
||||
model->sectors_total = mf_classic_get_total_sectors_num(type);
|
||||
model->keys_total = model->sectors_total * 2;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void dict_attack_set_card_removed(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->state = DictAttackStateCardRemoved;
|
||||
return true;
|
||||
});
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{ model->state = DictAttackStateCardRemoved; },
|
||||
true);
|
||||
}
|
||||
|
||||
void dict_attack_set_sector_read(DictAttack* dict_attack, uint8_t sec_read) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->sectors_read = sec_read;
|
||||
return true;
|
||||
});
|
||||
dict_attack->view, DictAttackViewModel * model, { model->sectors_read = sec_read; }, true);
|
||||
}
|
||||
|
||||
void dict_attack_set_keys_found(DictAttack* dict_attack, uint8_t keys_found) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->keys_found = keys_found;
|
||||
return true;
|
||||
});
|
||||
dict_attack->view, DictAttackViewModel * model, { model->keys_found = keys_found; }, true);
|
||||
}
|
||||
|
||||
void dict_attack_set_current_sector(DictAttack* dict_attack, uint8_t curr_sec) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{
|
||||
model->sector_current = curr_sec;
|
||||
model->dict_keys_current = 0;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void dict_attack_inc_current_sector(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{
|
||||
if(model->sector_current < model->sectors_total) {
|
||||
model->sector_current++;
|
||||
model->dict_keys_current = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void dict_attack_inc_keys_found(DictAttack* dict_attack) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{
|
||||
if(model->keys_found < model->keys_total) {
|
||||
model->keys_found++;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void dict_attack_set_total_dict_keys(DictAttack* dict_attack, uint16_t dict_keys_total) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
model->dict_keys_total = dict_keys_total;
|
||||
return true;
|
||||
});
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{ model->dict_keys_total = dict_keys_total; },
|
||||
true);
|
||||
}
|
||||
|
||||
void dict_attack_inc_current_dict_key(DictAttack* dict_attack, uint16_t keys_tried) {
|
||||
furi_assert(dict_attack);
|
||||
with_view_model(
|
||||
dict_attack->view, (DictAttackViewModel * model) {
|
||||
dict_attack->view,
|
||||
DictAttackViewModel * model,
|
||||
{
|
||||
if(model->dict_keys_current + keys_tried < model->dict_keys_total) {
|
||||
model->dict_keys_current += keys_tried;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
@@ -67,17 +67,17 @@ void subghz_view_receiver_set_lock(SubGhzViewReceiver* subghz_receiver, SubGhzLo
|
||||
if(lock == SubGhzLockOn) {
|
||||
subghz_receiver->lock = lock;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowLock;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowLock; },
|
||||
true);
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
} else {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowDefault; },
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,7 +95,9 @@ static void subghz_view_receiver_update_offset(SubGhzViewReceiver* subghz_receiv
|
||||
furi_assert(subghz_receiver);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
size_t history_item = model->history_item;
|
||||
uint16_t bounds = history_item > 3 ? 2 : history_item;
|
||||
|
||||
@@ -107,8 +109,8 @@ static void subghz_view_receiver_update_offset(SubGhzViewReceiver* subghz_receiv
|
||||
} else if(model->list_offset > model->idx - bounds) {
|
||||
model->list_offset = CLAMP(model->idx - 1, (int16_t)(history_item - bounds), 0);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_view_receiver_add_item_to_menu(
|
||||
@@ -117,7 +119,9 @@ void subghz_view_receiver_add_item_to_menu(
|
||||
uint8_t type) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
SubGhzReceiverMenuItem* item_menu =
|
||||
SubGhzReceiverMenuItemArray_push_raw(model->history->data);
|
||||
item_menu->item_str = furi_string_alloc_set(name);
|
||||
@@ -128,9 +132,8 @@ void subghz_view_receiver_add_item_to_menu(
|
||||
} else {
|
||||
model->history_item++;
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
}
|
||||
|
||||
@@ -141,12 +144,14 @@ void subghz_view_receiver_add_data_statusbar(
|
||||
const char* history_stat_str) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
furi_string_set(model->frequency_str, frequency_str);
|
||||
furi_string_set(model->preset_str, preset_str);
|
||||
furi_string_set(model->history_stat_str, history_stat_str);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_receiver_draw_frame(Canvas* canvas, uint16_t idx, bool scrollbar) {
|
||||
@@ -240,10 +245,10 @@ static void subghz_view_receiver_timer_callback(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewReceiver* subghz_receiver = context;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowDefault; },
|
||||
true);
|
||||
if(subghz_receiver->lock_count < UNLOCK_CNT) {
|
||||
subghz_receiver->callback(
|
||||
SubGhzCustomEventViewReceiverOffDisplay, subghz_receiver->context);
|
||||
@@ -260,10 +265,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
||||
|
||||
if(subghz_receiver->lock == SubGhzLockOn) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowToUnlockPress;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowToUnlockPress; },
|
||||
true);
|
||||
if(subghz_receiver->lock_count == 0) {
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(1000));
|
||||
}
|
||||
@@ -274,10 +279,10 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
||||
// subghz_receiver->callback(
|
||||
// SubGhzCustomEventViewReceiverUnlock, subghz_receiver->context);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
model->bar_show = SubGhzViewReceiverBarShowUnlock;
|
||||
return true;
|
||||
});
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{ model->bar_show = SubGhzViewReceiverBarShowUnlock; },
|
||||
true);
|
||||
//subghz_receiver->lock = SubGhzLockOff;
|
||||
furi_timer_start(subghz_receiver->timer, pdMS_TO_TICKS(650));
|
||||
}
|
||||
@@ -291,29 +296,35 @@ bool subghz_view_receiver_input(InputEvent* event, void* context) {
|
||||
event->key == InputKeyUp &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
if(model->idx != 0) model->idx--;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(
|
||||
event->key == InputKeyDown &&
|
||||
(event->type == InputTypeShort || event->type == InputTypeRepeat)) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
if(model->idx != model->history_item - 1) model->idx++;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
subghz_receiver->callback(SubGhzCustomEventViewReceiverConfig, subghz_receiver->context);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
if(model->history_item != 0) {
|
||||
subghz_receiver->callback(
|
||||
SubGhzCustomEventViewReceiverOK, subghz_receiver->context);
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
@@ -329,7 +340,9 @@ void subghz_view_receiver_exit(void* context) {
|
||||
furi_assert(context);
|
||||
SubGhzViewReceiver* subghz_receiver = context;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
furi_string_reset(model->frequency_str);
|
||||
furi_string_reset(model->preset_str);
|
||||
furi_string_reset(model->history_stat_str);
|
||||
@@ -342,8 +355,8 @@ void subghz_view_receiver_exit(void* context) {
|
||||
model->idx = 0;
|
||||
model->list_offset = 0;
|
||||
model->history_item = 0;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
furi_timer_stop(subghz_receiver->timer);
|
||||
}
|
||||
|
||||
@@ -364,15 +377,17 @@ SubGhzViewReceiver* subghz_view_receiver_alloc() {
|
||||
view_set_exit_callback(subghz_receiver->view, subghz_view_receiver_exit);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
model->frequency_str = furi_string_alloc();
|
||||
model->preset_str = furi_string_alloc();
|
||||
model->history_stat_str = furi_string_alloc();
|
||||
model->bar_show = SubGhzViewReceiverBarShowDefault;
|
||||
model->history = malloc(sizeof(SubGhzReceiverHistory));
|
||||
SubGhzReceiverMenuItemArray_init(model->history->data);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
subghz_receiver->timer =
|
||||
furi_timer_alloc(subghz_view_receiver_timer_callback, FuriTimerTypeOnce, subghz_receiver);
|
||||
return subghz_receiver;
|
||||
@@ -382,7 +397,9 @@ void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
|
||||
furi_assert(subghz_receiver);
|
||||
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
furi_string_free(model->frequency_str);
|
||||
furi_string_free(model->preset_str);
|
||||
furi_string_free(model->history_stat_str);
|
||||
@@ -393,8 +410,8 @@ void subghz_view_receiver_free(SubGhzViewReceiver* subghz_receiver) {
|
||||
}
|
||||
SubGhzReceiverMenuItemArray_clear(model->history->data);
|
||||
free(model->history);
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
furi_timer_free(subghz_receiver->timer);
|
||||
view_free(subghz_receiver->view);
|
||||
free(subghz_receiver);
|
||||
@@ -409,20 +426,19 @@ uint16_t subghz_view_receiver_get_idx_menu(SubGhzViewReceiver* subghz_receiver)
|
||||
furi_assert(subghz_receiver);
|
||||
uint32_t idx = 0;
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
idx = model->idx;
|
||||
return false;
|
||||
});
|
||||
subghz_receiver->view, SubGhzViewReceiverModel * model, { idx = model->idx; }, false);
|
||||
return idx;
|
||||
}
|
||||
|
||||
void subghz_view_receiver_set_idx_menu(SubGhzViewReceiver* subghz_receiver, uint16_t idx) {
|
||||
furi_assert(subghz_receiver);
|
||||
with_view_model(
|
||||
subghz_receiver->view, (SubGhzViewReceiverModel * model) {
|
||||
subghz_receiver->view,
|
||||
SubGhzViewReceiverModel * model,
|
||||
{
|
||||
model->idx = idx;
|
||||
if(model->idx > 2) model->list_offset = idx - 2;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
subghz_view_receiver_update_offset(subghz_receiver);
|
||||
}
|
||||
|
@@ -132,12 +132,14 @@ void subghz_frequency_analyzer_pair_callback(
|
||||
}
|
||||
//update history
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
instance->view,
|
||||
SubGhzFrequencyAnalyzerModel * model,
|
||||
{
|
||||
model->history_frequency[2] = model->history_frequency[1];
|
||||
model->history_frequency[1] = model->history_frequency[0];
|
||||
model->history_frequency[0] = model->frequency;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
} else if((rssi != 0.f) && (!instance->locked)) {
|
||||
if(instance->callback) {
|
||||
instance->callback(SubGhzCustomEventSceneAnalyzerLock, instance->context);
|
||||
@@ -146,12 +148,14 @@ void subghz_frequency_analyzer_pair_callback(
|
||||
|
||||
instance->locked = (rssi != 0.f);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
instance->view,
|
||||
SubGhzFrequencyAnalyzerModel * model,
|
||||
{
|
||||
model->rssi = rssi;
|
||||
model->frequency = frequency;
|
||||
model->signal = signal;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_enter(void* context) {
|
||||
@@ -169,14 +173,16 @@ void subghz_frequency_analyzer_enter(void* context) {
|
||||
subghz_frequency_analyzer_worker_start(instance->worker);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
instance->view,
|
||||
SubGhzFrequencyAnalyzerModel * model,
|
||||
{
|
||||
model->rssi = 0;
|
||||
model->frequency = 0;
|
||||
model->history_frequency[2] = 0;
|
||||
model->history_frequency[1] = 0;
|
||||
model->history_frequency[0] = 0;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_frequency_analyzer_exit(void* context) {
|
||||
@@ -190,10 +196,7 @@ void subghz_frequency_analyzer_exit(void* context) {
|
||||
subghz_frequency_analyzer_worker_free(instance->worker);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = 0;
|
||||
return true;
|
||||
});
|
||||
instance->view, SubGhzFrequencyAnalyzerModel * model, { model->rssi = 0; }, true);
|
||||
}
|
||||
|
||||
SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
||||
@@ -210,10 +213,7 @@ SubGhzFrequencyAnalyzer* subghz_frequency_analyzer_alloc() {
|
||||
view_set_exit_callback(instance->view, subghz_frequency_analyzer_exit);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzFrequencyAnalyzerModel * model) {
|
||||
model->rssi = 0;
|
||||
return true;
|
||||
});
|
||||
instance->view, SubGhzFrequencyAnalyzerModel * model, { model->rssi = 0; }, true);
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
@@ -45,11 +45,13 @@ void subghz_read_raw_add_data_statusbar(
|
||||
const char* preset_str) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
furi_string_set(model->frequency_str, frequency_str);
|
||||
furi_string_set(model->preset_str, preset_str);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi) {
|
||||
@@ -63,31 +65,35 @@ void subghz_read_raw_add_data_rssi(SubGhzReadRAW* instance, float rssi) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->rssi_history[model->ind_write++] = u_rssi;
|
||||
if(model->ind_write > SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE) {
|
||||
model->rssi_history_end = true;
|
||||
model->ind_write = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_update_sample_write(SubGhzReadRAW* instance, size_t sample) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
furi_string_printf(model->sample_write, "%d spl.", sample);
|
||||
return false;
|
||||
});
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{ furi_string_printf(model->sample_write, "%d spl.", sample); },
|
||||
false);
|
||||
}
|
||||
|
||||
void subghz_read_raw_stop_send(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusTXRepeat:
|
||||
case SubGhzReadRAWStatusLoadKeyTXRepeat:
|
||||
@@ -105,19 +111,21 @@ void subghz_read_raw_stop_send(SubGhzReadRAW* instance) {
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_read_raw_update_sin(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->ind_sin++ > 62) {
|
||||
model->ind_sin = 0;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static int8_t subghz_read_raw_tab_sin(uint8_t x) {
|
||||
@@ -286,9 +294,11 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
//further check of events is not needed, we exit
|
||||
return false;
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
uint8_t ret = false;
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
uint8_t ret = false;
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusIDLE:
|
||||
// Start TX
|
||||
@@ -314,11 +324,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return ret;
|
||||
});
|
||||
},
|
||||
ret);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeRelease) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusTXRepeat) {
|
||||
// Stop repeat TX
|
||||
model->status = SubGhzReadRAWStatusTX;
|
||||
@@ -326,11 +338,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
// Stop repeat TX
|
||||
model->status = SubGhzReadRAWStatusLoadKeyTX;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
} else if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
switch(model->status) {
|
||||
case SubGhzReadRAWStatusREC:
|
||||
//Stop REC
|
||||
@@ -357,11 +371,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
instance->callback(SubGhzCustomEventViewReadRAWBack, instance->context);
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyLeft && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusStart) {
|
||||
//Config
|
||||
instance->callback(SubGhzCustomEventViewReadRAWConfig, instance->context);
|
||||
@@ -376,11 +392,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
furi_string_reset(model->file_name);
|
||||
instance->callback(SubGhzCustomEventViewReadRAWErase, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyRight && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusIDLE) {
|
||||
//Save
|
||||
instance->callback(SubGhzCustomEventViewReadRAWSave, instance->context);
|
||||
@@ -388,11 +406,13 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
//More
|
||||
instance->callback(SubGhzCustomEventViewReadRAWMore, instance->context);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
} else if(event->key == InputKeyOk && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status == SubGhzReadRAWStatusStart) {
|
||||
//Record
|
||||
instance->callback(SubGhzCustomEventViewReadRAWREC, instance->context);
|
||||
@@ -404,8 +424,8 @@ bool subghz_read_raw_input(InputEvent* event, void* context) {
|
||||
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -419,36 +439,42 @@ void subghz_read_raw_set_status(
|
||||
switch(status) {
|
||||
case SubGhzReadRAWStatusStart:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->status = SubGhzReadRAWStatusStart;
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
furi_string_reset(model->file_name);
|
||||
furi_string_set(model->sample_write, "0 spl.");
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
break;
|
||||
case SubGhzReadRAWStatusIDLE:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
model->status = SubGhzReadRAWStatusIDLE;
|
||||
return true;
|
||||
});
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{ model->status = SubGhzReadRAWStatusIDLE; },
|
||||
true);
|
||||
break;
|
||||
case SubGhzReadRAWStatusLoadKeyTX:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
model->rssi_history_end = false;
|
||||
model->ind_write = 0;
|
||||
furi_string_set(model->file_name, file_name);
|
||||
furi_string_set(model->sample_write, "RAW");
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
break;
|
||||
case SubGhzReadRAWStatusSaveKey:
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->status = SubGhzReadRAWStatusLoadKeyIDLE;
|
||||
if(!model->ind_write) {
|
||||
furi_string_set(model->file_name, file_name);
|
||||
@@ -456,8 +482,8 @@ void subghz_read_raw_set_status(
|
||||
} else {
|
||||
furi_string_reset(model->file_name);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -476,15 +502,17 @@ void subghz_read_raw_exit(void* context) {
|
||||
SubGhzReadRAW* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
if(model->status != SubGhzReadRAWStatusIDLE &&
|
||||
model->status != SubGhzReadRAWStatusStart &&
|
||||
model->status != SubGhzReadRAWStatusLoadKeyIDLE) {
|
||||
instance->callback(SubGhzCustomEventViewReadRAWIDLE, instance->context);
|
||||
model->status = SubGhzReadRAWStatusStart;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
SubGhzReadRAW* subghz_read_raw_alloc() {
|
||||
@@ -500,14 +528,16 @@ SubGhzReadRAW* subghz_read_raw_alloc() {
|
||||
view_set_exit_callback(instance->view, subghz_read_raw_exit);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
model->frequency_str = furi_string_alloc();
|
||||
model->preset_str = furi_string_alloc();
|
||||
model->sample_write = furi_string_alloc();
|
||||
model->file_name = furi_string_alloc();
|
||||
model->rssi_history = malloc(SUBGHZ_READ_RAW_RSSI_HISTORY_SIZE * sizeof(uint8_t));
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return instance;
|
||||
}
|
||||
@@ -516,14 +546,16 @@ void subghz_read_raw_free(SubGhzReadRAW* instance) {
|
||||
furi_assert(instance);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzReadRAWModel * model) {
|
||||
instance->view,
|
||||
SubGhzReadRAWModel * model,
|
||||
{
|
||||
furi_string_free(model->frequency_str);
|
||||
furi_string_free(model->preset_str);
|
||||
furi_string_free(model->sample_write);
|
||||
furi_string_free(model->file_name);
|
||||
free(model->rssi_history);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
view_free(instance->view);
|
||||
free(instance);
|
||||
}
|
||||
|
@@ -89,7 +89,9 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
furi_hal_subghz_idle();
|
||||
|
||||
if(event->key == InputKeyLeft) {
|
||||
@@ -125,9 +127,8 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
|
||||
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -142,15 +143,17 @@ void subghz_test_carrier_enter(void* context) {
|
||||
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
model->frequency = subghz_frequencies_433_92_testing; // 433
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestCarrierModelStatusRx;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
furi_hal_subghz_rx();
|
||||
|
||||
@@ -172,13 +175,14 @@ void subghz_test_carrier_rssi_timer_callback(void* context) {
|
||||
SubGhzTestCarrier* subghz_test_carrier = context;
|
||||
|
||||
with_view_model(
|
||||
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {
|
||||
subghz_test_carrier->view,
|
||||
SubGhzTestCarrierModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestCarrierModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
SubGhzTestCarrier* subghz_test_carrier_alloc() {
|
||||
|
@@ -68,7 +68,9 @@ static void subghz_test_packet_rssi_timer_callback(void* context) {
|
||||
SubGhzTestPacket* instance = context;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
model->rssi = furi_hal_subghz_get_rssi();
|
||||
model->packets = instance->packet_rx;
|
||||
@@ -77,8 +79,8 @@ static void subghz_test_packet_rssi_timer_callback(void* context) {
|
||||
SUBGHZ_TEST_PACKET_COUNT -
|
||||
subghz_encoder_princeton_for_testing_get_repeat_left(instance->encoder);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_test_packet_draw(Canvas* canvas, SubGhzTestPacketModel* model) {
|
||||
@@ -137,7 +139,9 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubGhzTestPacketModelStatusTx) {
|
||||
@@ -179,9 +183,8 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
|
||||
instance->callback(SubGhzTestPacketEventOnlyRx, instance->context);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -194,15 +197,17 @@ void subghz_test_packet_enter(void* context) {
|
||||
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
model->frequency = subghz_frequencies_433_92_testing;
|
||||
model->real_frequency =
|
||||
furi_hal_subghz_set_frequency(subghz_frequencies_testing[model->frequency]);
|
||||
model->path = FuriHalSubGhzPathIsolate; // isolate
|
||||
model->rssi = 0.0f;
|
||||
model->status = SubGhzTestPacketModelStatusRx;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
furi_hal_subghz_start_async_rx(subghz_test_packet_rx_callback, instance);
|
||||
|
||||
@@ -217,15 +222,17 @@ void subghz_test_packet_exit(void* context) {
|
||||
|
||||
// Reinitialize IC to default state
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestPacketModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestPacketModel * model,
|
||||
{
|
||||
if(model->status == SubGhzTestPacketModelStatusRx) {
|
||||
furi_hal_subghz_stop_async_rx();
|
||||
} else if(model->status == SubGhzTestPacketModelStatusTx) {
|
||||
subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_get_tick());
|
||||
furi_hal_subghz_stop_async_tx();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
furi_hal_subghz_sleep();
|
||||
}
|
||||
|
||||
|
@@ -77,7 +77,9 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestStaticModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestStaticModel * model,
|
||||
{
|
||||
if(event->type == InputTypeShort) {
|
||||
if(event->key == InputKeyLeft) {
|
||||
if(model->frequency > 0) model->frequency--;
|
||||
@@ -128,9 +130,8 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
|
||||
}
|
||||
furi_record_close(RECORD_NOTIFICATION);
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -147,13 +148,14 @@ void subghz_test_static_enter(void* context) {
|
||||
instance->status_tx = SubGhzTestStaticStatusIDLE;
|
||||
|
||||
with_view_model(
|
||||
instance->view, (SubGhzTestStaticModel * model) {
|
||||
instance->view,
|
||||
SubGhzTestStaticModel * model,
|
||||
{
|
||||
model->frequency = subghz_frequencies_433_92_testing;
|
||||
model->real_frequency = subghz_frequencies_testing[model->frequency];
|
||||
model->button = 0;
|
||||
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
void subghz_test_static_exit(void* context) {
|
||||
|
@@ -35,13 +35,15 @@ void subghz_view_transmitter_add_data_to_show(
|
||||
uint8_t show_button) {
|
||||
furi_assert(subghz_transmitter);
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_set(model->key_str, key_str);
|
||||
furi_string_set(model->frequency_str, frequency_str);
|
||||
furi_string_set(model->preset_str, preset_str);
|
||||
model->show_button = show_button;
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
}
|
||||
|
||||
static void subghz_view_transmitter_button_right(Canvas* canvas, const char* str) {
|
||||
@@ -95,23 +97,27 @@ bool subghz_view_transmitter_input(InputEvent* event, void* context) {
|
||||
|
||||
if(event->key == InputKeyBack && event->type == InputTypeShort) {
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_reset(model->frequency_str);
|
||||
furi_string_reset(model->preset_str);
|
||||
furi_string_reset(model->key_str);
|
||||
model->show_button = 0;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
return false;
|
||||
}
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
if(model->show_button) {
|
||||
can_be_sent = true;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
|
||||
if(can_be_sent && event->key == InputKeyOk && event->type == InputTypePress) {
|
||||
subghz_transmitter->callback(
|
||||
@@ -149,12 +155,14 @@ SubGhzViewTransmitter* subghz_view_transmitter_alloc() {
|
||||
view_set_exit_callback(subghz_transmitter->view, subghz_view_transmitter_exit);
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
model->frequency_str = furi_string_alloc();
|
||||
model->preset_str = furi_string_alloc();
|
||||
model->key_str = furi_string_alloc();
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
return subghz_transmitter;
|
||||
}
|
||||
|
||||
@@ -162,12 +170,14 @@ void subghz_view_transmitter_free(SubGhzViewTransmitter* subghz_transmitter) {
|
||||
furi_assert(subghz_transmitter);
|
||||
|
||||
with_view_model(
|
||||
subghz_transmitter->view, (SubGhzViewTransmitterModel * model) {
|
||||
subghz_transmitter->view,
|
||||
SubGhzViewTransmitterModel * model,
|
||||
{
|
||||
furi_string_free(model->frequency_str);
|
||||
furi_string_free(model->preset_str);
|
||||
furi_string_free(model->key_str);
|
||||
return true;
|
||||
});
|
||||
},
|
||||
true);
|
||||
view_free(subghz_transmitter->view);
|
||||
free(subghz_transmitter);
|
||||
}
|
||||
|
@@ -85,18 +85,17 @@ void u2f_view_set_ok_callback(U2fView* u2f, U2fOkCallback callback, void* contex
|
||||
furi_assert(u2f);
|
||||
furi_assert(callback);
|
||||
with_view_model(
|
||||
u2f->view, (U2fModel * model) {
|
||||
u2f->view,
|
||||
U2fModel * model,
|
||||
{
|
||||
UNUSED(model);
|
||||
u2f->callback = callback;
|
||||
u2f->context = context;
|
||||
return false;
|
||||
});
|
||||
},
|
||||
false);
|
||||
}
|
||||
|
||||
void u2f_view_set_state(U2fView* u2f, U2fViewMsg msg) {
|
||||
with_view_model(
|
||||
u2f->view, (U2fModel * model) {
|
||||
model->display_msg = msg;
|
||||
return true;
|
||||
});
|
||||
u2f->view, U2fModel * model, { model->display_msg = msg; }, true);
|
||||
}
|
||||
|
Reference in New Issue
Block a user