unleashed-firmware/applications/u2f/views/u2f_view.c
SG 274c12fc56
[FL-2274] Inventing streams and moving FFF to them (#981)
* Streams: string stream
* String stream: updated insert/delete api
* Streams: generic stream interface and string stream implementation
* Streams: helpers for insert and delete_and_insert
* FFF: now compatible with streams
* MinUnit: introduced tests with arguments
* FFF: stream access violation
* Streams: copy data between streams
* Streams: file stream
* FFF: documentation
* FFStream: documentation
* FFF: alloc as file
* MinUnit: support for nested tests
* Streams: changed delete_and_insert, now it returns success flag. Added ability dump stream inner parameters and data to cout.
* FFF: simplified file open function
* Streams: unit tests
* FFF: tests
* Streams: declare cache_size constant as define, to allow variable modified arrays
* FFF: lib moved to a separate folder
* iButton: new FFF
* RFID: new FFF
* Animations: new FFF
* IR: new FFF
* NFC: new FFF
* Flipper file format: delete lib
* U2F: new FFF
* Subghz: new FFF and streams
* Streams: read line
* Streams: split
* FuriCore: implement memset with extra asserts
* FuriCore: implement extra heap asserts without inventing memset
* Scene manager: protected access to the scene id stack with a size check
* NFC worker: dirty fix for issue where hal_nfc was busy on app start
* Furi: update allocator to erase memory on allocation. Replace furi_alloc with malloc.
* FuriCore: cleanup memmgr code.
* Furi HAL: furi_hal_init is split into critical and non-critical parts. The critical part is currently clock and console.
* Memmgr: added ability to track allocations and deallocations through console.
* FFStream: some speedup
* Streams, FF: minor fixes
* Tests: restore
* File stream: a slightly more thread-safe version of file_stream_delete_and_insert

Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
2022-02-18 22:53:46 +03:00

101 lines
3.2 KiB
C

#include "u2f_view.h"
#include <gui/elements.h>
struct U2fView {
View* view;
U2fOkCallback callback;
void* context;
};
typedef struct {
U2fViewMsg display_msg;
} U2fModel;
static void u2f_view_draw_callback(Canvas* canvas, void* _model) {
U2fModel* model = _model;
canvas_draw_icon(canvas, 8, 14, &I_Drive_112x35);
canvas_set_font(canvas, FontSecondary);
if(model->display_msg == U2fMsgNotConnected) {
canvas_draw_icon(canvas, 22, 15, &I_Connect_me_62x31);
canvas_draw_str_aligned(
canvas, 128 / 2, 3, AlignCenter, AlignTop, "Connect me to computer");
} else if(model->display_msg == U2fMsgIdle) {
canvas_draw_icon(canvas, 22, 15, &I_Connected_62x31);
canvas_draw_str_aligned(canvas, 128 / 2, 3, AlignCenter, AlignTop, "Connected!");
} else if(model->display_msg == U2fMsgRegister) {
elements_button_center(canvas, "OK");
canvas_draw_icon(canvas, 22, 15, &I_Auth_62x31);
canvas_draw_str_aligned(canvas, 128 / 2, 3, AlignCenter, AlignTop, "Press OK to register");
} else if(model->display_msg == U2fMsgAuth) {
elements_button_center(canvas, "OK");
canvas_draw_icon(canvas, 22, 15, &I_Auth_62x31);
canvas_draw_str_aligned(
canvas, 128 / 2, 3, AlignCenter, AlignTop, "Press OK to authenticate");
} else if(model->display_msg == U2fMsgSuccess) {
canvas_draw_icon(canvas, 22, 15, &I_Connected_62x31);
canvas_draw_str_aligned(
canvas, 128 / 2, 3, AlignCenter, AlignTop, "Authentication successfull!");
} else if(model->display_msg == U2fMsgError) {
canvas_draw_icon(canvas, 22, 15, &I_Error_62x31);
canvas_draw_str_aligned(canvas, 128 / 2, 3, AlignCenter, AlignTop, "Ceritficate error");
}
}
static bool u2f_view_input_callback(InputEvent* event, void* context) {
furi_assert(context);
U2fView* u2f = context;
bool consumed = false;
if(event->type == InputTypeShort) {
if(event->key == InputKeyOk) {
consumed = true;
if(u2f->callback != NULL) u2f->callback(InputTypeShort, u2f->context);
}
}
return consumed;
}
U2fView* u2f_view_alloc() {
U2fView* u2f = malloc(sizeof(U2fView));
u2f->view = view_alloc();
view_allocate_model(u2f->view, ViewModelTypeLocking, sizeof(U2fModel));
view_set_context(u2f->view, u2f);
view_set_draw_callback(u2f->view, u2f_view_draw_callback);
view_set_input_callback(u2f->view, u2f_view_input_callback);
return u2f;
}
void u2f_view_free(U2fView* u2f) {
furi_assert(u2f);
view_free(u2f->view);
free(u2f);
}
View* u2f_view_get_view(U2fView* u2f) {
furi_assert(u2f);
return u2f->view;
}
void u2f_view_set_ok_callback(U2fView* u2f, U2fOkCallback callback, void* context) {
furi_assert(u2f);
furi_assert(callback);
with_view_model(
u2f->view, (U2fModel * model) {
u2f->callback = callback;
u2f->context = context;
return false;
});
}
void u2f_view_set_state(U2fView* u2f, U2fViewMsg msg) {
with_view_model(
u2f->view, (U2fModel * model) {
model->display_msg = msg;
return true;
});
}