Skip to content

Commit e7b67f5

Browse files
committed
Improve os_input example.
1 parent 97b2957 commit e7b67f5

File tree

2 files changed

+25
-38
lines changed

2 files changed

+25
-38
lines changed

examples/os_input/autotester.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,17 @@
1515
"key|2",
1616
"delay|200",
1717
"key|enter",
18-
"delay|200",
19-
"hash|1",
18+
"hashWait|1",
2019
"key|enter",
21-
"delay|200",
2220
"hashWait|2"
2321
],
2422
"hashes": {
2523
"1": {
26-
"description": "Output should be N is 12",
24+
"description": "Output should be 'N is 12.'",
2725
"start": "0xD44B00",
28-
"size": "0x25800",
29-
"expected_CRCs": [ "7DBE5A77" ]
26+
"size": "128000",
27+
"size_comment": "offset + 320x200x2 because we don't want the busy indicator",
28+
"expected_CRCs": [ "44FD49F5" ]
3029
},
3130
"2": {
3231
"description": "Back to the home screen (exit check)",

examples/os_input/src/main.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,36 @@
11
#include <stdbool.h>
22
#include <stddef.h>
33
#include <stdint.h>
4-
#include <tice.h>
5-
6-
#include <math.h>
74
#include <stdio.h>
8-
#include <stdlib.h>
9-
#include <string.h>
5+
#include <tice.h>
106

11-
#define INPUT_SIZE 10
12-
#define BUFFER_SIZE 20
7+
/* Make sure to adjust those sizes according to your usage! */
8+
#define INPUT_SIZE 10
9+
#define RESP_SIZE 20
1310

14-
/* Function prototypes */
15-
void print(char *text, uint8_t xpos, uint8_t ypos);
11+
/* Draw text on the homescreen at the given X/Y location */
12+
void print(const char* text, uint8_t xpos, uint8_t ypos) {
13+
os_SetCursorPos(ypos, xpos);
14+
os_PutStrFull(text);
15+
}
1616

17-
/* Main Function */
1817
void main(void) {
19-
const char prompt[] = "What is N? ";
20-
char input[INPUT_SIZE];
21-
char response[BUFFER_SIZE];
22-
18+
char inputBuffer[INPUT_SIZE];
19+
char response[RESP_SIZE];
20+
2321
/* Clear the homescreen */
2422
os_ClrHome();
25-
26-
/* Get an input string from the user */
27-
os_GetStringInput(prompt, input, sizeof input);
23+
24+
/* Ask the user to type a string, which gets stored in `inputBuf` */
25+
os_GetStringInput("What is N? ", inputBuffer, INPUT_SIZE);
2826

2927
/* Build the user response */
30-
strcpy(response, "N is ");
31-
strcat(response, input);
32-
33-
/* Clear the homescreen */
28+
sprintf(response, "N is %s.", inputBuffer);
29+
30+
/* Clear the homescreen and display the built response */
3431
os_ClrHome();
35-
36-
/* Print the message back to the user */
3732
print(response, 0, 0);
38-
39-
/* Wait for a key press */
40-
while (!os_GetCSC());
41-
}
4233

43-
/* Draw text on the homescreen at the given X/Y location */
44-
void print(char *text, uint8_t xpos, uint8_t ypos) {
45-
os_SetCursorPos(ypos, xpos);
46-
os_PutStrFull(text);
34+
/* Wait for a key press before quitting */
35+
while (!os_GetCSC());
4736
}
48-

0 commit comments

Comments
 (0)