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

Struggling with null pointers in int_input form

David Lee 2 лет назад
Родитель
Сommit
e1c72bb766
3 измененных файлов с 42 добавлено и 38 удалено
  1. 29 29
      helpers/gui/int_input.c
  2. 3 0
      meal_pager.c
  3. 10 9
      scenes/meal_pager_scene_set_station.c

+ 29 - 29
helpers/gui/int_input.c

@@ -21,7 +21,7 @@ typedef struct {
     size_t text_buffer_size;
     bool clear_default_text;
     
-    IntInputCallback input_callback;
+    IntInputCallback callback;
     //IntChangedCallback changed_callback;
     void* callback_context;
 
@@ -263,13 +263,14 @@ UNUSED(text_length);
         if (model->clear_default_text) {
             text_length = 0;
         }
-        if(text_length < (model->text_buffer_size - 1)) {
+        //if(text_length < (model->text_buffer_size - 1)) {
             //model->text_buffer[text_length] = selected;
             //model->text_buffer[text_length + 1] = 0;
-            //FURI_LOG_D("INT_INPUT", model->text_buffer);
-            FURI_LOG_D("INT_INPUT", "%u", text_length);
-            FURI_LOG_D("INT_INPUT", "%u", model->text_buffer_size);
-        }
+            FURI_LOG_D("INT_INPUT", model->text_buffer);
+            //FURI_LOG_D("INT_INPUT", "%u", text_length);
+            //FURI_LOG_D("INT_INPUT", "%u", model->text_buffer_size);
+            FURI_LOG_D("INT_INPUT", "%d", selected);
+        //}
     }
     model->clear_default_text = false;
 }
@@ -402,6 +403,7 @@ static bool int_input_view_input_callback(InputEvent* event, void* context) {
             int_input_handle_ok(model);
             break;
         default:
+            consumed = false;
             break;
         }
     }
@@ -412,15 +414,26 @@ static bool int_input_view_input_callback(InputEvent* event, void* context) {
     return consumed;
 }
 
-/** Reset all input-related data in model
- *
- * @param      model  The model
- */
-static void int_input_reset_model_input_data(IntInputModel* model) {
-    model->selected_row = 0;
-    model->selected_column = 0;
+void int_input_reset(IntInput* int_input) {
+    FURI_LOG_D("INT_INPUT", "Resetting Model");
+    furi_assert(int_input);
+    with_view_model(
+        int_input->view,
+        IntInputModel * model,
+        {
+            model->header = "";
+            model->selected_row = 0;
+            model->selected_column = 0;
+            model->clear_default_text = false;
+            model->text_buffer = "";
+            model->text_buffer_size = 0;
+            model->callback = NULL;
+            model->callback_context = NULL;
+        },
+        true);
 }
 
+
 IntInput* int_input_alloc() {
     IntInput* int_input = malloc(sizeof(IntInput));
     int_input->view = view_alloc();
@@ -429,17 +442,7 @@ IntInput* int_input_alloc() {
     view_set_draw_callback(int_input->view, int_input_view_draw_callback);
     view_set_input_callback(int_input->view, int_input_view_input_callback);
 
-    with_view_model(
-        int_input->view,
-        IntInputModel * model,
-        {
-            model->header = "";
-            model->input_callback = NULL;
-           // model->changed_callback = NULL;
-            model->callback_context = NULL;
-            int_input_reset_model_input_data(model);
-        },
-        true);
+    int_input_reset(int_input);
 
     return int_input;
 }
@@ -457,19 +460,16 @@ View* int_input_get_view(IntInput* int_input) {
 
 void int_input_set_result_callback(
     IntInput* int_input,
-    IntInputCallback input_callback,
-    //IntChangedCallback changed_callback,
+    IntInputCallback callback,
     void* callback_context,
     char* text_buffer,
     size_t text_buffer_size,
     bool clear_default_text) {
-    //UNUSED(changed_callback);
     with_view_model(
         int_input->view,
         IntInputModel * model,
         {
-            int_input_reset_model_input_data(model);
-            model->input_callback = input_callback;
+            model->callback = callback;
             model->callback_context = callback_context;
             model->text_buffer = text_buffer;
             model->text_buffer_size = text_buffer_size;

+ 3 - 0
meal_pager.c

@@ -61,6 +61,9 @@ Meal_Pager* meal_pager_app_alloc() {
     app->max_station = 8191;
     app->max_pager = 999;
 
+    snprintf(app->text_buffer, 32, "%lu", app->first_station);
+    //app->text_buffer = text_buffer;
+
     // Used for File Browser
     app->dialogs = furi_record_open(RECORD_DIALOGS);
     app->file_path = furi_string_alloc();

+ 10 - 9
scenes/meal_pager_scene_set_station.c

@@ -11,25 +11,23 @@
 #include "../views/meal_pager_transmit.h"
 #include <dolphin/dolphin.h>
 
-void meal_pager_set_station_callback(Meal_PagerCustomEvent event, void* context) {
+void meal_pager_set_station_callback(void* context) {
     furi_assert(context);
     Meal_Pager* app = context;
-    
-    UNUSED(app);
-    UNUSED(event);
+    view_dispatcher_send_custom_event(app->view_dispatcher, Meal_PagerCustomerEventIntInput);
 }
 
-static void meal_pager_int_input_callback(void* context) {
+/*static void meal_pager_int_input_callback(void* context) {
     furi_assert(context);
     Meal_Pager* app = context;
     view_dispatcher_send_custom_event(app->view_dispatcher, Meal_PagerCustomerEventIntInput);
-}
+}*/
 
 void meal_pager_scene_set_station_on_enter(void* context) {
     furi_assert(context);
     Meal_Pager* app = context;
     IntInput* int_input = app->int_input;
-    uint8_t enter_name_length = 4;
+    size_t enter_name_length = 4;
     meal_pager_set_max_values(app);
     char *str = "Set first Station (0 - 9999)";
     const char *constStr = str;
@@ -39,7 +37,7 @@ void meal_pager_scene_set_station_on_enter(void* context) {
     
     int_input_set_result_callback(
         int_input,
-        meal_pager_int_input_callback,
+        meal_pager_set_station_callback,
         context,
         app->text_buffer,
         enter_name_length,
@@ -55,7 +53,10 @@ bool meal_pager_scene_set_station_on_event(void* context, SceneManagerEvent even
     Meal_Pager* app = context;
     bool consumed = false;
 
-    if(event.type == SceneManagerEventTypeCustom) {
+    if(event.type == SceneManagerEventTypeBack) {
+        scene_manager_previous_scene(app->scene_manager);
+        return true;
+    } else if(event.type == SceneManagerEventTypeCustom) {
         switch(event.event) {
         case Meal_PagerCustomEventTransmitLeft:
         case Meal_PagerCustomEventTransmitRight: