Skip to content

Commit

Permalink
Fixed back button behavior in control page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandro Kalatozishvili committed Oct 2, 2023
1 parent e1add54 commit e6a83b1
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 38 deletions.
37 changes: 10 additions & 27 deletions views/xremote_common_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ struct XRemoteView {
void *context;
};

const NotificationSequence g_sequence_blink_purple_50 = {
&message_red_255,
&message_blue_255,
&message_delay_50,
NULL,
};

XRemoteView* xremote_view_alloc(void* app_ctx, ViewInputCallback input_cb, ViewDrawCallback draw_cb)
{
XRemoteView* remote_view = malloc(sizeof(XRemoteView));
Expand Down Expand Up @@ -95,33 +88,24 @@ InfraredRemoteButton* xremote_view_get_button_by_name(XRemoteView *rview, const
return infrared_remote_get_button_by_name(remote, name);
}

bool xremote_view_send_ir_by_name(XRemoteView *rview, const char *name)
bool xremote_view_press_button(XRemoteView *rview, InfraredRemoteButton* button)
{
InfraredRemoteButton* button = xremote_view_get_button_by_name(rview, name);
xremote_app_assert(button, false);
XRemoteAppSettings* settings = rview->app_ctx->app_settings;

InfraredSignal* signal = infrared_remote_button_get_signal(button);
xremote_app_assert(signal, false);

infrared_signal_transmit(signal);
NotificationApp* notifications = rview->app_ctx->notifications;
notification_message(notifications, &g_sequence_blink_purple_50);
infrared_signal_transmit_times(signal, settings->repeat_count);
xremote_app_context_notify_led(rview->app_ctx);

return true;
}

bool xremote_view_press_button(XRemoteView *rview, InfraredRemoteButton* button)
bool xremote_view_send_ir_msg_by_name(XRemoteView *rview, const char *name)
{
xremote_app_assert(button, false);

InfraredSignal* signal = infrared_remote_button_get_signal(button);
xremote_app_assert(signal, false);

infrared_signal_transmit(signal);
NotificationApp* notifications = rview->app_ctx->notifications;
notification_message(notifications, &g_sequence_blink_purple_50);

return true;
InfraredRemoteButton* button = xremote_view_get_button_by_name(rview, name);
return (button != NULL) ? xremote_view_press_button(rview, button) : false;
}

void xremote_canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, XRemoteIcon icon)
Expand Down Expand Up @@ -241,7 +225,8 @@ void xremote_canvas_draw_exit_footer(Canvas* canvas, ViewOrientation orient, con
}
else
{
xremote_canvas_draw_icon(canvas, 71, 60, XRemoteIconBack);
uint8_t x = strncmp(text, "Hold", 4) ? 71 : 76;
xremote_canvas_draw_icon(canvas, x, 60, XRemoteIconBack);
elements_multiline_text_aligned(canvas, 128, 64, AlignRight, AlignBottom, text);
}
}
Expand Down Expand Up @@ -276,7 +261,6 @@ void xremote_canvas_draw_button_png(Canvas* canvas, bool pressed, uint8_t x, uin

void xremote_canvas_draw_button_wide(Canvas* canvas, bool pressed, uint8_t x, uint8_t y, char* text, XRemoteIcon icon)
{
(void)icon;
elements_slightly_rounded_frame(canvas, x + 4, y, 56, 15);

if (pressed)
Expand All @@ -292,7 +276,6 @@ void xremote_canvas_draw_button_wide(Canvas* canvas, bool pressed, uint8_t x, ui

void xremote_canvas_draw_button_size(Canvas* canvas, bool pressed, uint8_t x, uint8_t y, uint8_t xy, char* text, XRemoteIcon icon)
{
(void)icon;
elements_slightly_rounded_frame(canvas, x + 4, y, xy, 15);

if (pressed)
Expand All @@ -318,4 +301,4 @@ void xremote_canvas_draw_frame(Canvas* canvas, bool pressed, uint8_t x, uint8_t

canvas_draw_str(canvas, x + 3, y + 11, text);
canvas_set_color(canvas, ColorBlack);
}
}
7 changes: 3 additions & 4 deletions views/xremote_common_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,12 @@ void xremote_canvas_draw_frame(Canvas* canvas, bool pressed, uint8_t x, uint8_t
XRemoteView* xremote_view_alloc(void *app_ctx, ViewInputCallback input_cb, ViewDrawCallback draw_cb);
void xremote_view_free(XRemoteView* rview);

View* xremote_view_get_view(XRemoteView* rview);
bool xremote_view_send_ir_by_name(XRemoteView *rview, const char *name);

InfraredRemoteButton* xremote_view_get_button_by_name(XRemoteView *rview, const char* name);
bool xremote_view_press_button(XRemoteView *rview, InfraredRemoteButton* button);
bool xremote_view_send_ir_msg_by_name(XRemoteView *rview, const char *name);

void xremote_view_set_context(XRemoteView* rview, void *context, XRemoteViewClearCallback on_clear);
void* xremote_view_get_context(XRemoteView* rview);
void xremote_view_clear_context(XRemoteView* rview);
void* xremote_view_get_app_context(XRemoteView* rview);
void* xremote_view_get_app_context(XRemoteView* rview);
View* xremote_view_get_view(XRemoteView* rview);
7 changes: 4 additions & 3 deletions views/xremote_control_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ static void xremote_control_view_draw_callback(Canvas* canvas, void* context)
furi_assert(context);
XRemoteViewModel* model = context;
XRemoteAppContext *app_ctx = model->context;
XRemoteViewDrawFunction xremote_control_view_draw_body;

ViewOrientation orientation = app_ctx->app_settings->orientation;
const char *exit_str = xremote_app_context_get_exit_str(app_ctx);

XRemoteViewDrawFunction xremote_control_view_draw_body;
xremote_control_view_draw_body = orientation == ViewOrientationVertical ?
xremote_control_view_draw_vertical : xremote_control_view_draw_horizontal;

xremote_canvas_draw_header(canvas, orientation, "Control");
xremote_control_view_draw_body(canvas, model);
xremote_canvas_draw_exit_footer(canvas, orientation, "Press to exit");
xremote_canvas_draw_exit_footer(canvas, orientation, exit_str);
}

static void xremote_control_view_process(XRemoteView* view, InputEvent* event)
Expand Down
2 changes: 1 addition & 1 deletion views/xremote_learn_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ XRemoteView* xremote_learn_view_alloc(void* app_ctx)
);

return view;
}
}
4 changes: 2 additions & 2 deletions xremote.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@

#define XREMOTE_VERSION_MAJOR 0
#define XREMOTE_VERSION_MINOR 9
#define XREMOTE_BUILD_NUMBER 24
#define XREMOTE_BUILD_NUMBER 26

void xremote_get_version(char *version, size_t length);
void xremote_get_version(char *version, size_t length);
14 changes: 14 additions & 0 deletions xremote_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@
#define XREMOTE_APP_SETTINGS ANY_PATH("infrared/assets/xremote.cfg")
#define TAG "XRemoteApp"

const NotificationSequence g_sequence_blink_purple_50 = {
&message_red_255,
&message_blue_255,
&message_delay_50,
NULL,
};

XRemoteAppSettings* xremote_app_settings_alloc()
{
XRemoteAppSettings* settings = malloc(sizeof(XRemoteAppSettings));
Expand Down Expand Up @@ -137,6 +144,13 @@ const char* xremote_app_context_get_exit_str(XRemoteAppContext* ctx)
return exit_behavior == XRemoteAppExitHold ? "Hold to exit" : "Press to exit";
}

void xremote_app_context_notify_led(XRemoteAppContext* app_ctx)
{
xremote_app_assert_void(app_ctx);
NotificationApp* notifications = app_ctx->notifications;
notification_message(notifications, &g_sequence_blink_purple_50);
}

void xremote_app_view_alloc(XRemoteApp *app, uint32_t view_id, XRemoteViewAllocator allocator)
{
furi_assert(app);
Expand Down
2 changes: 2 additions & 0 deletions xremote_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ typedef struct {

XRemoteAppContext* xremote_app_context_alloc(void* arg);
void xremote_app_context_free(XRemoteAppContext* ctx);

const char* xremote_app_context_get_exit_str(XRemoteAppContext* ctx);
void xremote_app_context_notify_led(XRemoteAppContext* app_ctx);

typedef XRemoteView* (*XRemoteViewAllocator)(void* app_ctx);
typedef void (*XRemoteAppClearCallback)(void *context);
Expand Down
2 changes: 1 addition & 1 deletion xremote_learn.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "xremote_learn.h"
#include "views/xremote_learn_view.h"

uint32_t xremote_learn_view_exit_callback(void* context)
static uint32_t xremote_learn_view_exit_callback(void* context)
{
UNUSED(context);
return XRemoteViewSubmenu;
Expand Down

0 comments on commit e6a83b1

Please sign in to comment.