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

Added Number Input in parallel

David Lee 1 год назад
Родитель
Сommit
33775c7a2f
4 измененных файлов с 39 добавлено и 12 удалено
  1. 29 11
      scenes/xremote_scene_ir_timer.c
  2. 7 1
      xremote.c
  3. 2 0
      xremote.h
  4. 1 0
      xremote_i.h

+ 29 - 11
scenes/xremote_scene_ir_timer.c

@@ -1,19 +1,36 @@
 #include "../xremote.h"
 #include "../models/cross/xremote_cross_remote.h"
 
-void xremote_scene_ir_timer_callback(void* context) {
+void xremote_scene_ir_timer_callback(void* context, int32_t number) {
     XRemote* app = context;
-    view_dispatcher_send_custom_event(app->view_dispatcher, XRemoteCustomEventTextInput);
+    CrossRemoteItem* item = xremote_cross_remote_get_item(app->cross_remote, app->edit_item);
+    item->time = number;
+    view_dispatcher_send_custom_event(app->view_dispatcher, 0);
 }
 
 void xremote_scene_ir_timer_on_enter(void* context) {
     furi_assert(context);
     XRemote* app = context;
-    IntInput* int_input = app->int_input;
-    size_t enter_name_length = 5;
-    char* str = "Transmit in ms (0 - 9999)";
-    const char* constStr = str;
+    NumberInput* number_input = app->number_input;
+
+    char str[50];
+    int32_t min_value = 0;
+    int32_t max_value = 9999;
+    snprintf(str, sizeof(str), "Transmit in ms (%ld - %ld)", min_value, max_value);
     CrossRemoteItem* item = xremote_cross_remote_get_item(app->cross_remote, app->edit_item);
+    
+    number_input_set_header_text(number_input, str);
+    number_input_set_result_callback(
+        number_input,
+        xremote_scene_ir_timer_callback,
+        context,
+        item->time,
+        min_value,
+        max_value);
+
+    view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdNumberInput);
+
+   /* CrossRemoteItem* item = xremote_cross_remote_get_item(app->cross_remote, app->edit_item);
     int_input_set_header_text(int_input, constStr);
     snprintf(app->text_store[1], 5, "%lu", item->time);
 
@@ -25,24 +42,25 @@ void xremote_scene_ir_timer_on_enter(void* context) {
         enter_name_length,
         false);
 
-    view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdIntInput);
+    view_dispatcher_switch_to_view(app->view_dispatcher, XRemoteViewIdIntInput);*/
 }
 
 bool xremote_scene_ir_timer_on_event(void* context, SceneManagerEvent event) {
     XRemote* app = context;
     bool consumed = false;
 
-    if(event.type == SceneManagerEventTypeBack) {
+    //if(event.type == SceneManagerEventTypeBack) {
+    if(event.type == SceneManagerEventTypeCustom) {
         scene_manager_previous_scene(app->scene_manager);
         return true;
-    } else if(event.type == SceneManagerEventTypeCustom) {
+    /*} else if(event.type == SceneManagerEventTypeCustom) {
         CrossRemoteItem* item = xremote_cross_remote_get_item(app->cross_remote, app->edit_item);
-        xremote_cross_remote_item_set_time(item, atoi(app->text_store[1]));
+        xremote_cross_remote_item_set_time(item, (app->text_store[1]));
         if(item->time > 9999) {
             item->time = 9999;
         }
         scene_manager_previous_scene(app->scene_manager);
-        return true;
+        return true;*/
     }
     return consumed;
 }

+ 7 - 1
xremote.c

@@ -29,7 +29,7 @@ XRemote* xremote_app_alloc() {
 
     //Scene additions
     app->view_dispatcher = view_dispatcher_alloc();
-    view_dispatcher_enable_queue(app->view_dispatcher);
+    //view_dispatcher_enable_queue(app->view_dispatcher);
 
     app->scene_manager = scene_manager_alloc(&xremote_scene_handlers, app);
     view_dispatcher_set_event_callback_context(app->view_dispatcher, app);
@@ -76,6 +76,10 @@ XRemote* xremote_app_alloc() {
     view_dispatcher_add_view(
         app->view_dispatcher, XRemoteViewIdIntInput, int_input_get_view(app->int_input));
 
+    app->number_input = number_input_alloc();
+    view_dispatcher_add_view(
+        app->view_dispatcher, XRemoteViewIdNumberInput, number_input_get_view(app->number_input));
+
     view_dispatcher_add_view(
         app->view_dispatcher, XRemoteViewIdTextInput, text_input_get_view(app->text_input));
 
@@ -149,11 +153,13 @@ void xremote_app_free(XRemote* app) {
     view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdStack);
     view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdTextInput);
     view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdIntInput);
+    view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdNumberInput);
     view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdTransmit);
     view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdPauseSet);
     view_dispatcher_remove_view(app->view_dispatcher, XRemoteViewIdIrRemote);
     text_input_free(app->text_input);
     int_input_free(app->int_input);
+    number_input_free(app->number_input);
     button_menu_free(app->button_menu_create);
     button_menu_free(app->button_menu_create_add);
     button_menu_free(app->button_menu_ir);

+ 2 - 0
xremote.h

@@ -53,6 +53,7 @@ typedef struct {
     char text_store[XREMOTE_TEXT_STORE_NUM][XREMOTE_TEXT_STORE_SIZE + 1];
     SubGhz* subghz;
     IntInput* int_input;
+    NumberInput* number_input;
 } XRemote;
 
 typedef enum {
@@ -67,6 +68,7 @@ typedef enum {
     XRemoteViewIdStack,
     XRemoteViewIdTextInput,
     XRemoteViewIdIntInput,
+    XRemoteViewIdNumberInput,
     XRemoteViewIdTransmit,
     XRemoteViewIdPauseSet,
 } XRemoteViewId;

+ 1 - 0
xremote_i.h

@@ -19,6 +19,7 @@
 #include <gui/modules/loading.h>
 #include <gui/modules/submenu.h>
 #include <gui/modules/dialog_ex.h>
+#include <gui/modules/number_input.h>
 #include <gui/modules/text_input.h>
 #include <gui/modules/button_menu.h>
 #include <gui/modules/button_panel.h>