Skip to content

Commit e1c72bb

Browse files
author
David Lee
committed
Struggling with null pointers in int_input form
1 parent 11a23ce commit e1c72bb

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

helpers/gui/int_input.c

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ typedef struct {
2121
size_t text_buffer_size;
2222
bool clear_default_text;
2323

24-
IntInputCallback input_callback;
24+
IntInputCallback callback;
2525
//IntChangedCallback changed_callback;
2626
void* callback_context;
2727

@@ -263,13 +263,14 @@ UNUSED(text_length);
263263
if (model->clear_default_text) {
264264
text_length = 0;
265265
}
266-
if(text_length < (model->text_buffer_size - 1)) {
266+
//if(text_length < (model->text_buffer_size - 1)) {
267267
//model->text_buffer[text_length] = selected;
268268
//model->text_buffer[text_length + 1] = 0;
269-
//FURI_LOG_D("INT_INPUT", model->text_buffer);
270-
FURI_LOG_D("INT_INPUT", "%u", text_length);
271-
FURI_LOG_D("INT_INPUT", "%u", model->text_buffer_size);
272-
}
269+
FURI_LOG_D("INT_INPUT", model->text_buffer);
270+
//FURI_LOG_D("INT_INPUT", "%u", text_length);
271+
//FURI_LOG_D("INT_INPUT", "%u", model->text_buffer_size);
272+
FURI_LOG_D("INT_INPUT", "%d", selected);
273+
//}
273274
}
274275
model->clear_default_text = false;
275276
}
@@ -402,6 +403,7 @@ static bool int_input_view_input_callback(InputEvent* event, void* context) {
402403
int_input_handle_ok(model);
403404
break;
404405
default:
406+
consumed = false;
405407
break;
406408
}
407409
}
@@ -412,15 +414,26 @@ static bool int_input_view_input_callback(InputEvent* event, void* context) {
412414
return consumed;
413415
}
414416

415-
/** Reset all input-related data in model
416-
*
417-
* @param model The model
418-
*/
419-
static void int_input_reset_model_input_data(IntInputModel* model) {
420-
model->selected_row = 0;
421-
model->selected_column = 0;
417+
void int_input_reset(IntInput* int_input) {
418+
FURI_LOG_D("INT_INPUT", "Resetting Model");
419+
furi_assert(int_input);
420+
with_view_model(
421+
int_input->view,
422+
IntInputModel * model,
423+
{
424+
model->header = "";
425+
model->selected_row = 0;
426+
model->selected_column = 0;
427+
model->clear_default_text = false;
428+
model->text_buffer = "";
429+
model->text_buffer_size = 0;
430+
model->callback = NULL;
431+
model->callback_context = NULL;
432+
},
433+
true);
422434
}
423435

436+
424437
IntInput* int_input_alloc() {
425438
IntInput* int_input = malloc(sizeof(IntInput));
426439
int_input->view = view_alloc();
@@ -429,17 +442,7 @@ IntInput* int_input_alloc() {
429442
view_set_draw_callback(int_input->view, int_input_view_draw_callback);
430443
view_set_input_callback(int_input->view, int_input_view_input_callback);
431444

432-
with_view_model(
433-
int_input->view,
434-
IntInputModel * model,
435-
{
436-
model->header = "";
437-
model->input_callback = NULL;
438-
// model->changed_callback = NULL;
439-
model->callback_context = NULL;
440-
int_input_reset_model_input_data(model);
441-
},
442-
true);
445+
int_input_reset(int_input);
443446

444447
return int_input;
445448
}
@@ -457,19 +460,16 @@ View* int_input_get_view(IntInput* int_input) {
457460

458461
void int_input_set_result_callback(
459462
IntInput* int_input,
460-
IntInputCallback input_callback,
461-
//IntChangedCallback changed_callback,
463+
IntInputCallback callback,
462464
void* callback_context,
463465
char* text_buffer,
464466
size_t text_buffer_size,
465467
bool clear_default_text) {
466-
//UNUSED(changed_callback);
467468
with_view_model(
468469
int_input->view,
469470
IntInputModel * model,
470471
{
471-
int_input_reset_model_input_data(model);
472-
model->input_callback = input_callback;
472+
model->callback = callback;
473473
model->callback_context = callback_context;
474474
model->text_buffer = text_buffer;
475475
model->text_buffer_size = text_buffer_size;

meal_pager.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ Meal_Pager* meal_pager_app_alloc() {
6161
app->max_station = 8191;
6262
app->max_pager = 999;
6363

64+
snprintf(app->text_buffer, 32, "%lu", app->first_station);
65+
//app->text_buffer = text_buffer;
66+
6467
// Used for File Browser
6568
app->dialogs = furi_record_open(RECORD_DIALOGS);
6669
app->file_path = furi_string_alloc();

scenes/meal_pager_scene_set_station.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,23 @@
1111
#include "../views/meal_pager_transmit.h"
1212
#include <dolphin/dolphin.h>
1313

14-
void meal_pager_set_station_callback(Meal_PagerCustomEvent event, void* context) {
14+
void meal_pager_set_station_callback(void* context) {
1515
furi_assert(context);
1616
Meal_Pager* app = context;
17-
18-
UNUSED(app);
19-
UNUSED(event);
17+
view_dispatcher_send_custom_event(app->view_dispatcher, Meal_PagerCustomerEventIntInput);
2018
}
2119

22-
static void meal_pager_int_input_callback(void* context) {
20+
/*static void meal_pager_int_input_callback(void* context) {
2321
furi_assert(context);
2422
Meal_Pager* app = context;
2523
view_dispatcher_send_custom_event(app->view_dispatcher, Meal_PagerCustomerEventIntInput);
26-
}
24+
}*/
2725

2826
void meal_pager_scene_set_station_on_enter(void* context) {
2927
furi_assert(context);
3028
Meal_Pager* app = context;
3129
IntInput* int_input = app->int_input;
32-
uint8_t enter_name_length = 4;
30+
size_t enter_name_length = 4;
3331
meal_pager_set_max_values(app);
3432
char *str = "Set first Station (0 - 9999)";
3533
const char *constStr = str;
@@ -39,7 +37,7 @@ void meal_pager_scene_set_station_on_enter(void* context) {
3937

4038
int_input_set_result_callback(
4139
int_input,
42-
meal_pager_int_input_callback,
40+
meal_pager_set_station_callback,
4341
context,
4442
app->text_buffer,
4543
enter_name_length,
@@ -55,7 +53,10 @@ bool meal_pager_scene_set_station_on_event(void* context, SceneManagerEvent even
5553
Meal_Pager* app = context;
5654
bool consumed = false;
5755

58-
if(event.type == SceneManagerEventTypeCustom) {
56+
if(event.type == SceneManagerEventTypeBack) {
57+
scene_manager_previous_scene(app->scene_manager);
58+
return true;
59+
} else if(event.type == SceneManagerEventTypeCustom) {
5960
switch(event.event) {
6061
case Meal_PagerCustomEventTransmitLeft:
6162
case Meal_PagerCustomEventTransmitRight:

0 commit comments

Comments
 (0)