[FL-2198], [FL-2161] NFC emulation refactoring (#968)

* rfal: add state changed callback
* furi_hal_nfc: add NFC-A emulation API
* nfc: add emulation logger, refactor scenes
* elements: fix text_box element
* gui: fix text box module
* nfc: remove unnecessary buffers
* nfc: introduce emulation callback concept
* nfc: format sources
* bt settings: fix incorrect scene switch
* bt settings: format sources
* Debug: fix x2d import for python 3
* Gui: rename method name widget_clear to widget_reset
* nfc: add nfca emulation handler
* nfc: add global custom events enum
* nfc: UID emulation Data -> Log
* furi_hal_nfc: fix incorrect timings
* u2f, badusb: widget_clear() -> widget_reset()

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
gornekich
2022-02-02 22:59:28 +03:00
committed by GitHub
parent 838df4c9ea
commit 8cfd0eab9e
46 changed files with 719 additions and 251 deletions

View File

@@ -594,7 +594,6 @@ void elements_text_box(
line[line_num].height = line_height;
line[line_num].descender = line_descender;
if(total_height_min + line_leading_min > height) {
line_num--;
break;
}
total_height_min += line_leading_min;
@@ -640,7 +639,7 @@ void elements_text_box(
uint8_t free_pixel_num = height - total_height_min;
uint8_t fill_pixel = 0;
uint8_t j = 1;
line[0].y = line[0].height;
line[0].y = y + line[0].height;
while(fill_pixel < free_pixel_num) {
line[j].y = line[j - 1].y + line[j - 1].leading_min + 1;
fill_pixel++;

View File

@@ -7,17 +7,16 @@
struct TextBox {
View* view;
void* context;
TextBoxExitCallback callback;
};
typedef struct {
const char* text;
char* text_pos;
string_t text_formatted;
size_t scroll_pos;
size_t scroll_num;
int32_t scroll_pos;
int32_t scroll_num;
TextBoxFont font;
TextBoxFocus focus;
bool formatted;
} TextBoxModel;
@@ -52,12 +51,6 @@ static void text_box_process_up(TextBox* text_box) {
});
}
static void text_box_process_back(TextBox* text_box) {
if(text_box->callback) {
text_box->callback(text_box->context);
}
}
static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
size_t i = 0;
size_t line_width = 0;
@@ -84,8 +77,18 @@ static void text_box_insert_endline(Canvas* canvas, TextBoxModel* model) {
line_num++;
model->text = string_get_cstr(model->text_formatted);
model->text_pos = (char*)model->text;
model->scroll_num = MAX(line_num - 4, 0);
model->scroll_pos = 0;
if(model->focus == TextBoxFocusEnd && line_num > 5) {
// Set text position to 5th line from the end
for(uint8_t i = 0; i < line_num - 5; i++) {
while(*model->text_pos++ != '\n') {
};
}
model->scroll_num = line_num - 4;
model->scroll_pos = line_num - 5;
} else {
model->scroll_num = MAX(line_num - 4, 0);
model->scroll_pos = 0;
}
}
static void text_box_view_draw_callback(Canvas* canvas, void* _model) {
@@ -119,9 +122,6 @@ static bool text_box_view_input_callback(InputEvent* event, void* context) {
} else if(event->key == InputKeyUp) {
text_box_process_up(text_box);
consumed = true;
} else if(event->key == InputKeyBack) {
text_box_process_back(text_box);
consumed = true;
}
}
return consumed;
@@ -172,10 +172,9 @@ void text_box_reset(TextBox* text_box) {
model->text = NULL;
string_set_str(model->text_formatted, "");
model->font = TextBoxFontText;
model->focus = TextBoxFocusStart;
return true;
});
text_box->context = NULL;
text_box->callback = NULL;
}
void text_box_set_text(TextBox* text_box, const char* text) {
@@ -185,6 +184,7 @@ void text_box_set_text(TextBox* text_box, const char* text) {
with_view_model(
text_box->view, (TextBoxModel * model) {
model->text = text;
string_reset(model->text_formatted);
string_reserve(model->text_formatted, strlen(text));
model->formatted = false;
return true;
@@ -201,12 +201,12 @@ void text_box_set_font(TextBox* text_box, TextBoxFont font) {
});
}
void text_box_set_context(TextBox* text_box, void* context) {
void text_box_set_focus(TextBox* text_box, TextBoxFocus focus) {
furi_assert(text_box);
text_box->context = context;
}
void text_box_set_exit_callback(TextBox* text_box, TextBoxExitCallback callback) {
furi_assert(text_box);
text_box->callback = callback;
with_view_model(
text_box->view, (TextBoxModel * model) {
model->focus = focus;
return true;
});
}

20
applications/gui/modules/text_box.h Normal file → Executable file
View File

@@ -13,13 +13,17 @@ extern "C" {
/** TextBox anonymous structure */
typedef struct TextBox TextBox;
typedef void (*TextBoxExitCallback)(void* context);
typedef enum {
TextBoxFontText,
TextBoxFontHex,
} TextBoxFont;
typedef enum {
TextBoxFocusStart,
TextBoxFocusEnd,
} TextBoxFocus;
/** Allocate and initialize text_box
*
* @return TextBox instance
@@ -60,19 +64,13 @@ void text_box_set_text(TextBox* text_box, const char* text);
*/
void text_box_set_font(TextBox* text_box, TextBoxFont font);
/** Set text_box context
/** Set TextBox focus
* @note Use to display from start or from end
*
* @param text_box TextBox instance
* @param context context pointer
* @param focus TextBoxFocus instance
*/
void text_box_set_context(TextBox* text_box, void* context);
/** Set exit callback
*
* @param text_box TextBox instance
* @param callback TextBoxExitCallback callback pointer
*/
void text_box_set_exit_callback(TextBox* text_box, TextBoxExitCallback callback);
void text_box_set_focus(TextBox* text_box, TextBoxFocus focus);
#ifdef __cplusplus
}

View File

@@ -68,7 +68,7 @@ Widget* widget_alloc() {
return widget;
}
void widget_clear(Widget* widget) {
void widget_reset(Widget* widget) {
furi_assert(widget);
with_view_model(
@@ -89,7 +89,7 @@ void widget_clear(Widget* widget) {
void widget_free(Widget* widget) {
furi_assert(widget);
// Free all elements
widget_clear(widget);
widget_reset(widget);
// Free elements container
with_view_model(
widget->view, (GuiWidgetModel * model) {

View File

@@ -27,11 +27,11 @@ Widget* widget_alloc();
*/
void widget_free(Widget* widget);
/** Clear Widget
/** Reset Widget
*
* @param widget Widget instance
*/
void widget_clear(Widget* widget);
void widget_reset(Widget* widget);
/** Get Widget view
*