Skip to content

Commit

Permalink
Very basic subview system introduced.
Browse files Browse the repository at this point in the history
  • Loading branch information
antirez committed Jan 15, 2023
1 parent 1e4bbfa commit 2de5c2a
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 3 deletions.
6 changes: 6 additions & 0 deletions app.c
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ static void app_switch_view(ProtoViewApp *app, SwitchViewDirection dir) {
if ((old == ViewFrequencySettings && new != ViewModulationSettings) ||
(old == ViewModulationSettings && new != ViewFrequencySettings))
view_exit_settings(app);

/* Set the current subview of the view we just left to zero, that is
* the main subview of the view. When re re-enter it we want to see
* the main thing. */
app->current_subview[old] = 0;
}

/* Allocate the application state and initialize a number of stuff.
Expand All @@ -118,6 +123,7 @@ ProtoViewApp* protoview_app_alloc() {
gui_add_view_port(app->gui, app->view_port, GuiLayerFullscreen);
app->event_queue = furi_message_queue_alloc(8, sizeof(InputEvent));
app->current_view = ViewRawPulses;
for (int j = 0; j < ViewLast; j++) app->current_subview[j] = 0;
app->direct_sampling_enabled = false;

// Signal found and visualization defaults
Expand Down
5 changes: 4 additions & 1 deletion app.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ struct ProtoViewApp {
Gui *gui;
ViewPort *view_port; /* We just use a raw viewport and we render
everything into the low level canvas. */
ProtoViewCurrentView current_view; /* Active view ID. */
ProtoViewCurrentView current_view; /* Active left-right view ID. */
int current_subview[ViewLast]; /* Active up-down subview ID. */
FuriMessageQueue *event_queue; /* Keypress events go here. */

/* Radio related. */
Expand Down Expand Up @@ -182,6 +183,8 @@ void view_exit_direct_sampling(ProtoViewApp *app);
void view_exit_settings(ProtoViewApp *app);

/* ui.c */
void show_available_subviews(Canvas *canvas, ProtoViewApp *app, int last_subview);
bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview);
void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color);

/* crc.c */
Expand Down
32 changes: 32 additions & 0 deletions ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,38 @@

#include "app.h"

/* Called by view rendering callback that has subviews, to show small triangles
* facing down/up if there are other subviews the user can access with up
* and down. */
void show_available_subviews(Canvas *canvas, ProtoViewApp *app,
int last_subview)
{
int subview = app->current_subview[app->current_view];
if (subview != 0)
canvas_draw_triangle(canvas,120,5,8,5,CanvasDirectionBottomToTop);
if (subview != last_subview-1)
canvas_draw_triangle(canvas,120,59,8,5,CanvasDirectionTopToBottom);
}

/* Handle up/down keys when we are in a subview. If the function catched
* such keypress, it returns true, so that the actual view input callback
* knows it can just return ASAP without doing anything. */
bool process_subview_updown(ProtoViewApp *app, InputEvent input, int last_subview) {
int subview = app->current_subview[app->current_view];
if (input.type == InputTypePress) {
if (input.key == InputKeyUp) {
if (subview != 0)
app->current_subview[app->current_view]--;
return true;
} else if (input.key == InputKeyDown) {
if (subview != last_subview-1)
app->current_subview[app->current_view]++;
return true;
}
}
return false;
}

void canvas_draw_str_with_border(Canvas* canvas, uint8_t x, uint8_t y, const char* str, Color text_color, Color border_color)
{
struct {
Expand Down
26 changes: 24 additions & 2 deletions view_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,14 @@

#include "app.h"

/* Renders the view with the detected message information. */
void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
enum {
SubViewInfoMain,
SubViewInfoSave,
SubViewInfoLast, /* Just a sentinel. */
};

/* Render the view with the detected message information. */
static void render_subview_main(Canvas *const canvas, ProtoViewApp *app) {
if (app->signal_decoded == false) {
canvas_set_font(canvas, FontSecondary);
canvas_draw_str(canvas, 30,36,"No signal decoded");
Expand All @@ -31,8 +37,24 @@ void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
canvas_draw_str(canvas, 0, y, app->signal_info.info4); y += lineheight;
}

/* Render view with save option. */
static void render_subview_save(Canvas *const canvas, ProtoViewApp *app) {
UNUSED(canvas);
UNUSED(app);
}

/* Render the selected subview of this view. */
void render_view_info(Canvas *const canvas, ProtoViewApp *app) {
show_available_subviews(canvas,app,SubViewInfoLast);
switch(app->current_subview[app->current_view]) {
case SubViewInfoMain: render_subview_main(canvas,app); break;
case SubViewInfoSave: render_subview_save(canvas,app); break;
}
}

/* Handle input for the info view. */
void process_input_info(ProtoViewApp *app, InputEvent input) {
if (process_subview_updown(app,input,SubViewInfoLast)) return;
if (input.type == InputTypeShort) {
if (input.key == InputKeyOk) {
/* Reset the current sample to capture the next. */
Expand Down

0 comments on commit 2de5c2a

Please sign in to comment.