Skip to content

Commit fe2a588

Browse files
committed
Clean up
1 parent 5de75d5 commit fe2a588

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

examples/lvglterm/lvglterm.c

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -124,26 +124,27 @@ static lv_timer_t *g_timer;
124124
* Private Functions
125125
****************************************************************************/
126126

127-
// Create an LVGL Terminal that will let us interact with NuttX NSH Shell
127+
// Create an LVGL Terminal that will let us interact with NSH Shell
128128
static int create_terminal(void)
129129
{
130130
int ret;
131-
static uint32_t user_data = 0; // TODO
132131

133-
/* Create the pipes for NSH Shell */
132+
/* Create the pipes for NSH Shell: stdin, stdout and stderr */
134133

135134
ret = pipe(g_nsh_stdin);
136135
if (ret < 0)
137136
{
138-
_err("stdin pipe failed: %d\n", errno);
137+
_err("stdin pipe failed: %d\n", errno);
139138
return ERROR;
140139
}
140+
141141
ret = pipe(g_nsh_stdout);
142142
if (ret < 0)
143-
{
143+
{
144144
_err("stdout pipe failed: %d\n", errno);
145-
return ERROR;
145+
return ERROR;
146146
}
147+
147148
ret = pipe(g_nsh_stderr);
148149
if (ret < 0)
149150
{
@@ -180,8 +181,8 @@ static int create_terminal(void)
180181
/* Create an LVGL Timer to poll for output from NSH Shell */
181182

182183
g_timer = lv_timer_create(timer_callback, /* Callback Function */
183-
TIMER_PERIOD, /* Timer Period (Milliseconds) */
184-
&user_data); /* Callback Data */
184+
TIMER_PERIOD, /* Timer Period (millisec) */
185+
NULL); /* Callback Argument */
185186
DEBUGASSERT(g_timer != NULL);
186187

187188
/* Create the LVGL Terminal Widgets */
@@ -287,6 +288,7 @@ static int create_widgets(void)
287288
lv_obj_add_event_cb(input, input_callback, LV_EVENT_ALL, NULL);
288289

289290
/* Set the Keyboard to populate the NSH Input Text Area */
291+
290292
lv_keyboard_set_textarea(kb, input);
291293

292294
return OK;
@@ -312,7 +314,10 @@ static void input_callback(lv_event_t *e)
312314
/* Get the Text of the Keyboard Button */
313315

314316
const char *key = lv_keyboard_get_btn_text(kb, id);
315-
if (key == NULL) { return; }
317+
if (key == NULL)
318+
{
319+
return;
320+
}
316321

317322
/* If Key Pressed is Enter, send the Command to NSH stdin */
318323

@@ -323,16 +328,15 @@ static void input_callback(lv_event_t *e)
323328
const char *cmd;
324329
DEBUGASSERT(input != NULL);
325330
cmd = lv_textarea_get_text(input);
326-
if (cmd == NULL || cmd[0] == 0) { return; }
331+
if (cmd == NULL || cmd[0] == 0)
332+
{
333+
return;
334+
}
327335

328336
/* Send the Command to NSH stdin */
329337

330338
DEBUGASSERT(g_nsh_stdin[WRITE_PIPE] != 0);
331-
ret = write(
332-
g_nsh_stdin[WRITE_PIPE],
333-
cmd,
334-
strlen(cmd)
335-
);
339+
ret = write(g_nsh_stdin[WRITE_PIPE], cmd, strlen(cmd));
336340
DEBUGASSERT(ret == strlen(cmd));
337341

338342
/* Erase the NSH Input */
@@ -352,22 +356,20 @@ static bool has_input(int fd)
352356
struct pollfd fdp;
353357
fdp.fd = fd;
354358
fdp.events = POLLIN;
355-
ret = poll(
356-
&fdp, /* File Descriptors */
357-
1, /* Number of File Descriptors */
358-
0 /* Poll Timeout (Milliseconds) */
359-
);
359+
ret = poll(&fdp, /* File Descriptors */
360+
1, /* Number of File Descriptors */
361+
0); /* Poll Timeout (Milliseconds) */
360362

361363
if (ret > 0)
362364
{
363365
/* If Poll is OK and there is Input */
364366

365367
if ((fdp.revents & POLLIN) != 0)
366-
{
367-
/* Report that there's Input */
368+
{
369+
/* Report that there's Input */
368370

369-
return true;
370-
}
371+
return true;
372+
}
371373

372374
/* Else report No Input */
373375

@@ -389,7 +391,7 @@ static bool has_input(int fd)
389391

390392
/* Never comes here */
391393

392-
DEBUGASSERT(false);
394+
DEBUGPANIC();
393395
return false;
394396
}
395397

0 commit comments

Comments
 (0)