Fix flipper zero
This commit is contained in:
@@ -171,7 +171,8 @@ static uint8_t parse_items(const char* str, char items[][MAX_LINE_LENGTH], uint8
|
||||
|
||||
// Parse PAGE message
|
||||
// Format: PAGE:<idx>/<total>|<type>|<title>|<lines>|<actions>|<selected>
|
||||
static bool parse_page(const char* line, PageContent* page) {
|
||||
// Returns true if page changed (different page_index or page_type)
|
||||
static bool parse_page(const char* line, PageContent* page, bool* page_changed) {
|
||||
if(strncmp(line, "PAGE:", 5) != 0) {
|
||||
return false;
|
||||
}
|
||||
@@ -179,6 +180,11 @@ static bool parse_page(const char* line, PageContent* page) {
|
||||
const char* p = line + 5;
|
||||
char* end;
|
||||
|
||||
// Save old values to detect page change
|
||||
uint8_t old_page_index = page->page_index;
|
||||
PageType old_page_type = page->page_type;
|
||||
bool was_valid = page->data_valid;
|
||||
|
||||
// Parse page index and total
|
||||
page->page_index = (uint8_t)strtoul(p, &end, 10);
|
||||
if(*end != '/') return false;
|
||||
@@ -192,17 +198,27 @@ static bool parse_page(const char* line, PageContent* page) {
|
||||
const char* type_end = strchr(p, '|');
|
||||
if(!type_end) return false;
|
||||
|
||||
PageType new_page_type;
|
||||
if(strncmp(p, "info", type_end - p) == 0) {
|
||||
page->page_type = PageTypeInfo;
|
||||
new_page_type = PageTypeInfo;
|
||||
} else if(strncmp(p, "menu", type_end - p) == 0) {
|
||||
page->page_type = PageTypeMenu;
|
||||
new_page_type = PageTypeMenu;
|
||||
} else if(strncmp(p, "confirm", type_end - p) == 0) {
|
||||
page->page_type = PageTypeConfirm;
|
||||
new_page_type = PageTypeConfirm;
|
||||
} else {
|
||||
page->page_type = PageTypeInfo;
|
||||
new_page_type = PageTypeInfo;
|
||||
}
|
||||
page->page_type = new_page_type;
|
||||
p = type_end + 1;
|
||||
|
||||
// Detect if page changed (index OR type changed)
|
||||
bool is_page_change = !was_valid ||
|
||||
(page->page_index != old_page_index) ||
|
||||
(new_page_type != old_page_type);
|
||||
if(page_changed) {
|
||||
*page_changed = is_page_change;
|
||||
}
|
||||
|
||||
// Parse title
|
||||
const char* title_end = strchr(p, '|');
|
||||
if(!title_end) return false;
|
||||
@@ -243,8 +259,18 @@ static bool parse_page(const char* line, PageContent* page) {
|
||||
page->action_count = parse_items(actions_buf, page->actions, MAX_ACTIONS);
|
||||
p = actions_end + 1;
|
||||
|
||||
// Parse selected index
|
||||
page->selected_index = (uint8_t)strtoul(p, NULL, 10);
|
||||
// Parse selected index from server
|
||||
uint8_t server_selected = (uint8_t)strtoul(p, NULL, 10);
|
||||
|
||||
// IMPORTANT: Only update selected_index on page change
|
||||
// For menu/confirm pages, preserve local selection during updates
|
||||
if(is_page_change) {
|
||||
page->selected_index = server_selected;
|
||||
} else if(page->page_type == PageTypeInfo) {
|
||||
// Info pages don't have selection, always use server value
|
||||
page->selected_index = server_selected;
|
||||
}
|
||||
// For menu/confirm on same page: keep old_selected (local user choice)
|
||||
|
||||
page->data_valid = true;
|
||||
page->last_update_tick = furi_get_tick();
|
||||
@@ -322,7 +348,11 @@ static void process_line(CanMonitorApp* app, const char* line) {
|
||||
} else if(app->conn_state == StateConnected) {
|
||||
// Parse PAGE or RESULT
|
||||
if(line[0] == 'P') {
|
||||
parse_page(line, &app->page);
|
||||
bool page_changed = false;
|
||||
parse_page(line, &app->page, &page_changed);
|
||||
if(page_changed) {
|
||||
FURI_LOG_I(TAG, "Page changed to %d", app->page.page_index);
|
||||
}
|
||||
} else if(line[0] == 'R') {
|
||||
parse_result(line, &app->result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user