collab/mm20

git clone https://git.julia.blue/collab/mm20

Joseph RyanAdd printf UART backend and starter sim files321d415

algorithms
2.1 KiB112 linesraw
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5#define BUFFER_SIZE 32
6
7int get_int(char* command) {
8    printf("%s\n", command);
9    fflush(stdout);
10    char response[BUFFER_SIZE];
11    fgets(response, BUFFER_SIZE, stdin);
12    int value = atoi(response);
13    return value;
14}
15
16int get_bool(char* command) {
17    printf("%s\n", command);
18    fflush(stdout);
19    char response[BUFFER_SIZE];
20    fgets(response, BUFFER_SIZE, stdin);
21    int value = (strcmp(response, "true\n") == 0);
22    return value;
23}
24
25int get_ack(char* command) {
26    printf("%s\n", command);
27    fflush(stdout);
28    char response[BUFFER_SIZE];
29    fgets(response, BUFFER_SIZE, stdin);
30    int success = (strcmp(response, "ack\n") == 0);
31    return success;
32}
33
34int API_maze_width() {
35    return get_int("mazeWidth");
36}
37
38int API_maze_height() {
39    return get_int("mazeHeight");
40}
41
42int API_wall_front() {
43    return get_bool("wallFront");
44}
45
46int API_wall_right() {
47    return get_bool("wallRight");
48}
49
50int API_wall_left() {
51    return get_bool("wallLeft");
52}
53
54int API_move_forward() {
55    return get_ack("moveForward");
56}
57
58void API_turn_right() {
59    get_ack("turnRight");
60}
61
62void API_turn_left() {
63    get_ack("turnLeft");
64}
65
66void API_set_wall(int x, int y, char direction) {
67    printf("setWall %d %d %c\n", x, y, direction);
68    fflush(stdout);
69}
70
71void API_clear_wall(int x, int y, char direction) {
72    printf("clearWall %d %d %c\n", x, y, direction);
73    fflush(stdout);
74}
75
76void API_set_color(int x, int y, char color) {
77    printf("setColor %d %d %c\n", x, y, color);
78    fflush(stdout);
79}
80
81void API_clear_color(int x, int y) {
82    printf("clearColor %d %d\n", x, y);
83    fflush(stdout);
84}
85
86void API_clear_all_color() {
87    printf("clearAllColor\n");
88    fflush(stdout);
89}
90
91void API_set_text(int x, int y, char* text) {
92    printf("setText %d %d %s\n", x, y, text);
93    fflush(stdout);
94}
95
96void API_clear_text(int x, int y) {
97    printf("clearText %d %d\n", x, y);
98    fflush(stdout);
99}
100
101void API_clear_all_text() {
102    printf("clearAllText\n");
103    fflush(stdout);
104}
105
106int API_was_reset() {
107    return get_bool("wasReset");
108}
109
110void API_ack_reset() {
111    get_ack("ackReset");
112}