Просмотр исходного кода

Implemented saved remote general buttons view

Sandro Kalatozishvili 2 лет назад
Родитель
Сommit
8dbafef776

+ 1 - 1
README.md

@@ -14,7 +14,7 @@ The application works with standard `.ir` files, but for the buttons to work, th
 
 - [ ] Learn new remote
 - [ ] Use saved remote
-    - [ ] Saved remote general category
+    - [x] Saved remote general category
     - [ ] Saved remote control category
     - [x] Saved remote navigation category
     - [x] Saved remote player category

+ 1 - 1
application.fam

@@ -7,10 +7,10 @@ App(
     stack_size=3 * 1024,
     order=1,
     fap_version="1.0",
-    fap_icon="icon.png",
     fap_category="Infrared",
     fap_icon_assets="assets",
     fap_icon_assets_symbol="xc",
+    fap_icon="assets/App_Icon_10x10.png",
     fap_author="@kala13x",
     fap_weburl="https://github.com/kala13x/flipper-xremote",
     fap_description="Advanced infrared remote control",

+ 0 - 0
icon.png → assets/App_Icon_10x10.png


BIN
assets/Back_icon_10x8.png


BIN
assets/OK_Icon_9x9.png


+ 21 - 8
views/xremote_common_view.c

@@ -105,7 +105,20 @@ void xremote_view_send_ir(XRemoteView *rview, const char *name)
 
 void xremote_canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, XRemoteIcon icon)
 {
-    if (icon == XRemoteIconArrowUp)
+    if (icon == XRemoteIconEnter)
+    {
+        canvas_draw_circle(canvas, x - 2, y, 4);
+        canvas_draw_disc(canvas, x - 2, y, 2);
+    }
+    else if (icon == XRemoteIconBack)
+    {
+        canvas_draw_triangle(canvas, x - 4, y - 2, 5, 3, CanvasDirectionRightToLeft);
+        canvas_draw_line(canvas, x + 1, y - 2, x - 5, y - 2);
+        canvas_draw_line(canvas, x + 1, y + 3, x - 3, y + 3);
+        canvas_draw_line(canvas, x + 3, y + 1, x + 2, y + 2);
+        canvas_draw_line(canvas, x + 3, y, x + 2, y - 1);
+    }
+    else if (icon == XRemoteIconArrowUp)
     {
         canvas_draw_triangle(canvas, x - 2, y - 2, 5, 3, CanvasDirectionBottomToTop);
         canvas_draw_line(canvas, x - 2, y - 3, x - 2, y + 4);
@@ -182,7 +195,6 @@ void xremote_canvas_draw_header(Canvas* canvas, const char* section)
 {
     canvas_set_font(canvas, FontPrimary);
     elements_multiline_text_aligned(canvas, 0, 0, AlignLeft, AlignTop, "XRemote");
-
     canvas_set_font(canvas, FontSecondary);
     canvas_draw_str(canvas, 0, 20, section);
 }
@@ -190,7 +202,7 @@ void xremote_canvas_draw_header(Canvas* canvas, const char* section)
 void xremote_canvas_draw_exit_footer(Canvas* canvas, char *text)
 {
     canvas_set_font(canvas, FontSecondary);
-    canvas_draw_icon(canvas, 0, 120, &I_Back_icon_10x8);
+    xremote_canvas_draw_icon(canvas, 6, 124, XRemoteIconBack);
     canvas_draw_str(canvas, 12, 128, text);
 }
 
@@ -208,17 +220,18 @@ void xremote_canvas_draw_button(Canvas* canvas, bool pressed, uint8_t x, uint8_t
     canvas_set_color(canvas, ColorBlack);
 }
 
-void xremote_canvas_draw_button_wide(Canvas* canvas, bool pressed, uint8_t x, uint8_t y, char* text, const Icon* icon)
+void xremote_canvas_draw_button_wide(Canvas* canvas, bool pressed, uint8_t x, uint8_t y, char* text, XRemoteIcon icon)
 {
-    elements_slightly_rounded_frame(canvas, x, y, 64, 17);
+    (void)icon;
+    elements_slightly_rounded_frame(canvas, x + 4, y, 56, 15);
 
     if (pressed)
     {
-        elements_slightly_rounded_box(canvas, x + 2, y + 2, 60, 13);
+        elements_slightly_rounded_box(canvas, x + 6, y + 2, 52, 11);
         canvas_set_color(canvas, ColorWhite);
     }
 
-    canvas_draw_icon(canvas, x + 11, y + 4, icon);
-    elements_multiline_text_aligned(canvas, x + 28, y + 12, AlignLeft, AlignBottom, text);
+    xremote_canvas_draw_icon(canvas, x + 16, y + 7, icon);
+    elements_multiline_text_aligned(canvas, x + 26, y + 10, AlignLeft, AlignBottom, text);
     canvas_set_color(canvas, ColorBlack);
 }

+ 5 - 3
views/xremote_common_view.h

@@ -19,7 +19,7 @@
 #include <xc_icons.h>
 
 #define XREMOTE_COMMAND_POWER           "Power"
-#define XREMOTE_COMMAND_SETTINGS        "Settings"
+#define XREMOTE_COMMAND_SETUP           "Setup"
 #define XREMOTE_COMMAND_INPUT           "Input"
 #define XREMOTE_COMMAND_MENU            "Menu"
 #define XREMOTE_COMMAND_LIST            "List"
@@ -44,8 +44,10 @@
 #define XREMOTE_COMMAND_PREV_CHAN       "Prev_chan"
 
 typedef enum {
-    /* Controller */
+    /* Navigation */
     XRemoteIconOk,
+    XRemoteIconEnter,
+    XRemoteIconBack,
     XRemoteIconArrowUp,
     XRemoteIconArrowDown,
     XRemoteIconArrowLeft,
@@ -99,7 +101,7 @@ void xremote_canvas_draw_exit_footer(Canvas* canvas, char *text);
 
 void xremote_canvas_draw_icon(Canvas* canvas, uint8_t x, uint8_t y, XRemoteIcon icon);
 void xremote_canvas_draw_button(Canvas* canvas, bool pressed, uint8_t x, uint8_t y, XRemoteIcon icon);
-void xremote_canvas_draw_button_wide(Canvas* canvas, bool pressed, uint8_t x, uint8_t y, char* text, const Icon* icon);
+void xremote_canvas_draw_button_wide(Canvas* canvas, bool pressed, uint8_t x, uint8_t y, char* text, XRemoteIcon icon);
 
 XRemoteView* xremote_view_alloc(NotificationApp* notifications, ViewInputCallback input_cb, ViewDrawCallback draw_cb);
 void xremote_view_free(XRemoteView* rview);

+ 66 - 4
views/xremote_general_view.c

@@ -10,15 +10,77 @@
 
 static void xremote_general_view_draw_callback(Canvas* canvas, void* context)
 {
-    (void)context;
+    furi_assert(context);
+    XRemoteViewModel* model = context;
+
     xremote_canvas_draw_header(canvas, "General");
-    canvas_set_font(canvas, FontSecondary);
-    canvas_draw_str(canvas, 0, 70, "Coming Soon");
+    xremote_canvas_draw_button_wide(canvas, model->ok_pressed, 0, 27, "Power", XRemoteIconEnter);
+    xremote_canvas_draw_button_wide(canvas, model->up_pressed, 0, 45, "Input", XRemoteIconArrowUp);
+    xremote_canvas_draw_button_wide(canvas, model->down_pressed, 0, 63, "Setup", XRemoteIconArrowDown);
+    xremote_canvas_draw_button_wide(canvas, model->left_pressed, 0, 81, "List", XRemoteIconArrowLeft);
+    xremote_canvas_draw_button_wide(canvas, model->right_pressed, 0, 99, "Menu", XRemoteIconArrowRight);
     xremote_canvas_draw_exit_footer(canvas, "Press to exit");
 }
 
+static void xremote_general_view_process(XRemoteView* view, InputEvent* event)
+{
+    with_view_model(
+        xremote_view_get_view(view),
+        XRemoteViewModel* model,
+        {
+            if (event->type == InputTypePress)
+            {
+                if (event->key == InputKeyOk)
+                {
+                    model->ok_pressed = true;
+                    xremote_view_send_ir(view, XREMOTE_COMMAND_POWER);
+                }
+                else if (event->key == InputKeyUp)
+                {
+                    model->up_pressed = true;
+                    xremote_view_send_ir(view, XREMOTE_COMMAND_INPUT);
+                }
+                else if (event->key == InputKeyDown)
+                {
+                    model->down_pressed = true;
+                    xremote_view_send_ir(view, XREMOTE_COMMAND_SETUP);
+                }
+                else if (event->key == InputKeyLeft)
+                {
+                    model->left_pressed = true;
+                    xremote_view_send_ir(view, XREMOTE_COMMAND_LIST);
+                }
+                else if (event->key == InputKeyRight)
+                {
+                    model->right_pressed = true;
+                    xremote_view_send_ir(view, XREMOTE_COMMAND_MENU);
+                }
+            }
+            else if (event->type == InputTypeRelease)
+            {
+                if (event->key == InputKeyOk) model->ok_pressed = false;
+                else if (event->key == InputKeyUp) model->up_pressed = false;
+                else if (event->key == InputKeyDown) model->down_pressed = false;
+                else if (event->key == InputKeyLeft) model->left_pressed = false;
+                else if (event->key == InputKeyRight) model->right_pressed = false;
+            }
+        },
+        true);
+}
+
+static bool xremote_general_view_input_callback(InputEvent* event, void* context)
+{
+    furi_assert(context);
+    XRemoteView* view = (XRemoteView*)context;
+    if (event->key == InputKeyBack) return false;
+
+    xremote_general_view_process(view, event);
+    return true;
+}
+
 XRemoteView* xremote_general_view_alloc(NotificationApp* notifications)
 {
     return xremote_view_alloc(notifications,
-        NULL, xremote_general_view_draw_callback);
+        xremote_general_view_input_callback,
+        xremote_general_view_draw_callback);
 }

+ 1 - 1
views/xremote_navigation_view.c

@@ -19,7 +19,7 @@ static void xremote_navigation_view_draw_callback(Canvas* canvas, void* context)
     xremote_canvas_draw_button(canvas, model->left_pressed, 2, 51, XRemoteIconArrowLeft);
     xremote_canvas_draw_button(canvas, model->right_pressed, 44, 51, XRemoteIconArrowRight);
     xremote_canvas_draw_button(canvas, model->ok_pressed, 23, 51, XRemoteIconOk);
-    xremote_canvas_draw_button_wide(canvas, model->back_pressed, 0, 95, "BACK", &I_Back_icon_10x8);
+    xremote_canvas_draw_button_wide(canvas, model->back_pressed, 0, 95, "Back", XRemoteIconBack);
     xremote_canvas_draw_exit_footer(canvas, "Hold to exit");
 }
 

+ 1 - 1
xremote.h

@@ -10,6 +10,6 @@
 
 #define XREMOTE_VERSION_MAJOR  0
 #define XREMOTE_VERSION_MINOR  9
-#define XREMOTE_BUILD_NUMBER   14
+#define XREMOTE_BUILD_NUMBER   15
 
 void xremote_get_version(char *version, size_t length);

+ 1 - 2
xremote_control.c

@@ -7,6 +7,7 @@
  */
 
 #include "xremote_control.h"
+#include "infrared/infrared_remote.h"
 
 #include "views/xremote_general_view.h"
 #include "views/xremote_control_view.h"
@@ -14,8 +15,6 @@
 #include "views/xremote_player_view.h"
 #include "views/xremote_custom_view.h"
 
-#include "infrared/infrared_remote.h"
-
 #define XREMOTE_APP_EXTENSION   ".ir"
 #define XREMOTE_APP_FOLDER      ANY_PATH("infrared")