From e6a83b1270d24d4328e3c579cc1656bcda5aa8e4 Mon Sep 17 00:00:00 2001 From: Sandro Kalatozishvili Date: Tue, 3 Oct 2023 00:31:46 +0400 Subject: [PATCH] Fixed back button behavior in control page --- views/xremote_common_view.c | 37 ++++++++++-------------------------- views/xremote_common_view.h | 7 +++---- views/xremote_control_view.c | 7 ++++--- views/xremote_learn_view.c | 2 +- xremote.h | 4 ++-- xremote_app.c | 14 ++++++++++++++ xremote_app.h | 2 ++ xremote_learn.c | 2 +- 8 files changed, 37 insertions(+), 38 deletions(-) diff --git a/views/xremote_common_view.c b/views/xremote_common_view.c index 1c3e9a8..cd5e712 100644 --- a/views/xremote_common_view.c +++ b/views/xremote_common_view.c @@ -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)); @@ -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) @@ -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); } } @@ -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) @@ -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) @@ -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); -} \ No newline at end of file +} diff --git a/views/xremote_common_view.h b/views/xremote_common_view.h index a60be46..cc5ab0d 100644 --- a/views/xremote_common_view.h +++ b/views/xremote_common_view.h @@ -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); \ No newline at end of file +void* xremote_view_get_app_context(XRemoteView* rview); +View* xremote_view_get_view(XRemoteView* rview); diff --git a/views/xremote_control_view.c b/views/xremote_control_view.c index bf7c321..3f6f96d 100644 --- a/views/xremote_control_view.c +++ b/views/xremote_control_view.c @@ -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) diff --git a/views/xremote_learn_view.c b/views/xremote_learn_view.c index e06c605..d02eb31 100644 --- a/views/xremote_learn_view.c +++ b/views/xremote_learn_view.c @@ -37,4 +37,4 @@ XRemoteView* xremote_learn_view_alloc(void* app_ctx) ); return view; -} \ No newline at end of file +} diff --git a/xremote.h b/xremote.h index 615563c..11e92e8 100644 --- a/xremote.h +++ b/xremote.h @@ -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); \ No newline at end of file +void xremote_get_version(char *version, size_t length); diff --git a/xremote_app.c b/xremote_app.c index 3c36ac1..3f0a689 100644 --- a/xremote_app.c +++ b/xremote_app.c @@ -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)); @@ -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); diff --git a/xremote_app.h b/xremote_app.h index 2e5af1e..08cd19b 100644 --- a/xremote_app.h +++ b/xremote_app.h @@ -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); diff --git a/xremote_learn.c b/xremote_learn.c index 3366d37..9846af5 100644 --- a/xremote_learn.c +++ b/xremote_learn.c @@ -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;