Jelajahi Sumber

Fixed back button behavior in control page

Sandro Kalatozishvili 2 tahun lalu
induk
melakukan
e6a83b1270

+ 10 - 27
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);
-}
+}

+ 3 - 4
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);
+void* xremote_view_get_app_context(XRemoteView* rview);
+View* xremote_view_get_view(XRemoteView* rview);

+ 4 - 3
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)

+ 1 - 1
views/xremote_learn_view.c

@@ -37,4 +37,4 @@ XRemoteView* xremote_learn_view_alloc(void* app_ctx)
     );
 
     return view;
-}
+}

+ 2 - 2
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);
+void xremote_get_version(char *version, size_t length);

+ 14 - 0
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);

+ 2 - 0
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);

+ 1 - 1
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;