/
tt.c
170 lines (137 loc) · 3.54 KB
/
tt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "teletype.h"
#include "teletype_io.h"
#include "util.h"
void tele_metro_updated() {
printf("METRO UPDATED");
printf("\n");
}
void tele_metro_reset() {
printf("METRO RESET");
printf("\n");
}
void tele_tr(uint8_t i, int16_t v) {
printf("TR i:%" PRIu8 " v:%" PRId16, i, v);
printf("\n");
}
void tele_cv(uint8_t i, int16_t v, uint8_t s) {
printf("CV i:%" PRIu8 " v:%" PRId16 " s:%" PRIu8, i, v, s);
printf("\n");
}
void tele_cv_slew(uint8_t i, int16_t v) {
printf("CV_SLEW i:%" PRIu8 " v:%" PRId16, i, v);
printf("\n");
}
void tele_update_in(void) {
printf("UPDATE IN");
printf("\n");
}
void tele_has_delays(bool i) {
printf("DELAY i:%s", i ? "true" : "false");
printf("\n");
}
void tele_has_stack(bool i) {
printf("STACK i:%s", i ? "true" : "false");
printf("\n");
}
void tele_cv_off(uint8_t i, int16_t v) {
printf("CV_OFF i:%" PRIu8 " v:%" PRId16, i, v);
printf("\n");
}
void tele_ii_tx(uint8_t addr, uint8_t *data, uint8_t l) {
printf("II_tx addr:%" PRIu8 " l:%" PRIu8, addr, l);
printf("\n");
for (size_t i = 0; i < l; i++) {
printf("[%" PRIuPTR "] = %" PRIu8 "\n", i, data[i]);
}
}
void tele_vars_updated() {}
void tele_ii_rx(uint8_t addr, uint8_t *data, uint8_t l) {
printf("II_rx addr:%" PRIu8 " l:%" PRIu8, addr, l);
printf("\n");
}
void tele_scene(uint8_t i) {
printf("SCENE i:%" PRIu8, i);
printf("\n");
}
void tele_pattern_updated() {
printf("PATTERN UPDATED");
printf("\n");
}
void tele_kill() {
printf("KILL");
printf("\n");
}
void tele_mute() {
printf("MUTE");
printf("\n");
}
bool tele_get_input_state(uint8_t n) {
printf("INPUT_STATE n:%" PRIu8, n);
printf("\n");
return false;
}
void tele_save_calibration() {}
void tele_profile_script(size_t s) {}
void tele_profile_delay(uint8_t d) {}
int main() {
char *in;
time_t t;
error_t status;
int i;
srand((unsigned)time(&t));
// tele_command_t stored;
// stored.data[0].t = OP;
// stored.data[0].v = 2;
// stored.data[1].t = NUMBER;
// stored.data[1].v = 8;
// stored.data[2].t = NUMBER;
// stored.data[2].v = 10;
// stored.separator = -1;
// stored.l = 3;
// printf("\nstored process: ");
// process(&stored);
in = malloc(256);
printf("teletype. (blank line quits)\n\n");
scene_state_t ss;
ss_init(&ss);
do {
printf("> ");
fgets(in, 256, stdin);
i = 0;
while (in[i]) {
in[i] = toupper(in[i]);
i++;
}
tele_command_t temp;
exec_state_t es;
es_init(&es);
char error_msg[TELE_ERROR_MSG_LENGTH];
status = parse(in, &temp, error_msg);
if (status == E_OK) {
status = validate(&temp, error_msg);
printf("validate: %s", tele_error(status));
if (error_msg[0]) printf(": %s", error_msg);
printf("\n");
if (status == E_OK) {
process_result_t output = process_command(&ss, &es, &temp);
if (output.has_value) { printf(">>> %i\n", output.value); }
}
}
else {
printf("ERROR: %s", tele_error(status));
if (error_msg[0]) printf(": %s", error_msg);
printf("\n");
}
// tele_tick(100);
printf("\n");
} while (in[0] != 10);
free(in);
printf("(teletype exit.)\n");
}