Skip to content

Commit

Permalink
fix: Major bugs fixe
Browse files Browse the repository at this point in the history
  • Loading branch information
QtRoS committed Oct 1, 2023
1 parent 1fba658 commit 1060f59
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
1 change: 0 additions & 1 deletion hex_viewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ typedef struct {
// TODO Clean
typedef struct {
HexViewerModel* model;
//FuriMutex** mutex; // TODO Don't need?

Gui* gui;
Storage* storage;
Expand Down
17 changes: 1 addition & 16 deletions scenes/hex_viewer_scene_startscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ void hex_viewer_scene_startscreen_on_enter(void* context) {
bool hex_viewer_scene_startscreen_on_event(void* context, SceneManagerEvent event) {
HexViewer* app = context;
bool consumed = false;
uint32_t last_byte_on_screen;

if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
Expand All @@ -32,27 +31,13 @@ bool hex_viewer_scene_startscreen_on_event(void* context, SceneManagerEvent even
consumed = true;
break;
case HexViewerCustomEventStartscreenUp:
//furi_check(furi_mutex_acquire(hex_viewer->mutex, FuriWaitForever) == FuriStatusOk);
if(app->model->file_offset > 0) {
app->model->file_offset -= HEX_VIEWER_BYTES_PER_LINE;
if(!hex_viewer_read_file(app)) break; // TODO Do smth
}
consumed = true;
//furi_mutex_release(hex_viewer->mutex);
break;
case HexViewerCustomEventStartscreenDown:
//furi_check(furi_mutex_acquire(hex_viewer->mutex, FuriWaitForever) == FuriStatusOk);
last_byte_on_screen = app->model->file_offset + app->model->file_read_bytes;

if(app->model->file_size > last_byte_on_screen) {
app->model->file_offset += HEX_VIEWER_BYTES_PER_LINE;
if(!hex_viewer_read_file(app)) break; // TODO Do smth
}
consumed = true;
//furi_mutex_release(hex_viewer->mutex);
break;
case HexViewerCustomEventStartscreenOk:
if(!app->model->file_size) // TODO
if(!app->model->file_size)
scene_manager_next_scene(app->scene_manager, HexViewerSceneScene_4);
else
scene_manager_next_scene(app->scene_manager, HexViewerSceneMenu);
Expand Down
32 changes: 23 additions & 9 deletions views/hex_viewer_startscreen.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef struct {
uint32_t file_read_bytes;
uint32_t file_size;
bool mode;
uint32_t dbg;
} HexViewerStartscreenModel;

void hex_viewer_startscreen_set_callback(
Expand Down Expand Up @@ -95,6 +96,10 @@ void hex_viewer_startscreen_draw(Canvas* canvas, HexViewerStartscreenModel* mode
canvas_set_font(canvas, FontKeyboard);
canvas_draw_str(canvas, LEFT_OFFSET + 41, TOP_OFFSET + i * ROW_HEIGHT, temp_buf);
}

// Poor man's debug
// snprintf(temp_buf, 32, "D %02lX", model->dbg);
// elements_button_right(canvas, temp_buf);
}
}

Expand All @@ -104,6 +109,7 @@ static void hex_viewer_startscreen_model_init(HexViewerStartscreenModel* const m
model->file_read_bytes = 0;
model->file_size = 0;
model->mode = false;
model->dbg = 0;
}

static void
Expand All @@ -118,6 +124,7 @@ static void
bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
furi_assert(context);
HexViewerStartscreen* instance = context;
HexViewer* app = instance->context; // TO so good, but works
// TODO InputTypeShort?
if(event->type == InputTypeRelease || event->type == InputTypeRepeat) {
switch(event->key) {
Expand All @@ -135,20 +142,17 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
with_view_model(
instance->view,
HexViewerStartscreenModel * model,
{
//instance->callback(HexViewerCustomEventStartscreenLeft, instance->context);
//update_local_model_from_app(instance->context, model);
model->mode = !model->mode;
},
{ model->mode = !model->mode; },
true);
break;
case InputKeyRight:
with_view_model(
instance->view,
HexViewerStartscreenModel * model,
{
instance->callback(HexViewerCustomEventStartscreenRight, instance->context);
update_local_model_from_app(instance->context, model);
// instance->callback(HexViewerCustomEventStartscreenRight, instance->context);
// update_local_model_from_app(instance->context, model);
// model->dbg = 0;
},
true);
break;
Expand All @@ -157,7 +161,11 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
instance->view,
HexViewerStartscreenModel * model,
{
instance->callback(HexViewerCustomEventStartscreenUp, instance->context);
if(app->model->file_offset > 0) {
app->model->file_offset -= HEX_VIEWER_BYTES_PER_LINE;
if(!hex_viewer_read_file(app)) break; // TODO Do smth
}

update_local_model_from_app(instance->context, model);
},
true);
Expand All @@ -167,7 +175,13 @@ bool hex_viewer_startscreen_input(InputEvent* event, void* context) {
instance->view,
HexViewerStartscreenModel * model,
{
instance->callback(HexViewerCustomEventStartscreenDown, instance->context);
uint32_t last_byte_on_screen =
app->model->file_offset + app->model->file_read_bytes;
if(app->model->file_size > last_byte_on_screen) {
app->model->file_offset += HEX_VIEWER_BYTES_PER_LINE;
if(!hex_viewer_read_file(app)) break; // TODO Do smth
}

update_local_model_from_app(instance->context, model);
},
true);
Expand Down

0 comments on commit 1060f59

Please sign in to comment.