-
Notifications
You must be signed in to change notification settings - Fork 8
/
main.c
286 lines (241 loc) · 6.63 KB
/
main.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
// they are: stdio.h stdlib.h and libserialport.h
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include <libserialport.h>
#include "dgus.h"
#include "dgus_control_curve.h"
#include "dgus_control_text.h"
#define BAUD 115200
/* internal */
uint8_t _cur_pg = 0;
int filecount = 18;
int _sub_idx;
int _sub_depth;
int files_in_folder = 7;
int folders_count = 8;
void _pg(uint8_t pg) {
char files[32][32] = {
{"Ultimaker"},
{"Models"},
{"Firmware1"},
{"Firmware2"},
{"Firmware3"},
{"Firmware4"},
{"Firmware5"},
{"E6"},
{"File 1 test. testing long1"},
{"File 1 test. testing long2"},
{"File 1 test. testing long3"},
{"File 1 test. testing long4"},
{"File 1 test. testing long5"},
{"File 1 test. testing long6"},
{"File 1 test. testing long7"},
{"File 2 test. testing long1"},
{"File 2 test. testing long2"},
{"File 2 test. testing long3"},
{"File 2 test. testing long4"},
{"File 2 test. testing long5"},
{"File 2 test. testing long6"},
{"File 2 test. testing long7"},
{"File 2 test. testing long1"},
{"File 3 test. testing long2"},
{"File 3 test. testing long3"},
{"File 3 test. testing long4"},
};
char files1[10][32] = {
{".."},
{"pre level"},
{"reset (1)"},
{"reset (2)"},
{"reset (3)"},
};
files_in_folder = 7;
folders_count = 8;
for (int i = 0; i < 7; i++) {
dgus_set_icon(0x6300 + i + 1, 0);
}
int x = 0;
char ebuf[32];
memset(ebuf, 0x20, sizeof(ebuf));
for (int i = 0; i < files_in_folder; i++) {
//if (files[i + (pg * files_in_folder)][0] == '\0') {
//dgus_set_text_padded(0x6200 + x, ebuf, 32);
// }
//else {
char * f = files[i + (pg * files_in_folder)];
if (_sub_idx == 1) {
f = files1[i + (pg * files_in_folder)];
folders_count = 0;
_sub_depth = 1;
//filecount = 0;
//files_in_folder = 5;
};
memset(ebuf, 0x20, sizeof(ebuf));
if (i + (pg * files_in_folder) < folders_count) {
snprintf(ebuf, 30, "> %s\\", f);
}
else {
snprintf(ebuf, 30, "%s", f);
}
dgus_set_text_padded(0x6200 + x, ebuf, 32);
//}
x += 32;
}
char buf[10];
sprintf(buf, "%-2d/%-2d", pg + 1, (filecount / 7) + 1);
dgus_set_text(0x62E0, buf);
}
// platform impl of serial
static struct sp_port *port;
void _a_recv_handler(char *data, uint8_t cmd, uint8_t len, uint16_t addr, uint8_t bytelen) {
printf("JSNDJNASD\n");
if (addr == 0x5002 && (uint16_t)*(uint16_t *)data == 1) {
if (_cur_pg > 0)
_pg(--_cur_pg);
}
else if (addr == 0x5002 && (uint16_t)*(uint16_t *)data == 0x2) {
if ((_cur_pg + 1 * 7) < filecount)
_pg(++_cur_pg);
}
else if (addr == 0x5004 && (uint16_t)*(uint16_t *)data >= 0x01 && (uint16_t)*(uint16_t *)data < 0x08) {
uint16_t u = (uint16_t)*(uint16_t *)data;
// ".." clicked
if (_sub_depth && u == 1) {
_sub_idx = 0;
_sub_depth = 0;
_pg(0);
return;
}
if (u < folders_count) {
_sub_idx = u;
_pg(0);
return;
}
for (int i = 0; i < 7; i++) {
dgus_set_icon(0x610A + i + 1, i + 1 == u);
}
}
else if (addr == 0x5000 && (uint16_t)*(uint16_t *)data == 0x01) {
//dgus_set_page(2);
}
else if (addr == 0x5002 && (uint16_t)*(uint16_t *)data == 0x03) {
dgus_set_page(4);
}
else if (addr == 0x5006 && (uint16_t)*(uint16_t *)data == 0x03) {
dgus_set_page(7);
}
else if (addr == 0x5008 && (uint16_t)*(uint16_t *)data == 0x01) {
dgus_set_page(7);
}
else if (addr == 0x5008 && (uint16_t)*(uint16_t *)data == 0x02) {
dgus_set_page(9);
}
else if (addr == 0x5008 && (uint16_t)*(uint16_t *)data == 0x03) {
dgus_set_page(8);
}
}
uint8_t _serial_bytes_available() {
return sp_input_waiting(port);
}
char _serial_recv_byte() {
char c;
sp_nonblocking_read(port, (void *)&c, 1);
return c;
}
void _serial_send_data(char *data, size_t len) {
sp_blocking_write(port, data, len, SEND_TIMEOUT);
}
int main(int argc, char *argv[])
{
fprintf(stderr,"Start\n");
int err;
int i,cmd;
int count=4096;
// We need a serial port name
if (argc<2)
{
fprintf(stderr,"Usage port\n");
exit(1);
}
// Open serial port
err=sp_get_port_by_name(argv[1],&port);
if (err==SP_OK)
err=sp_open(port,SP_MODE_READ_WRITE);
if (err!=SP_OK)
{
fprintf(stderr,"Can't open port %s\n",argv[1]);
exit(2);
}
// set Baud rate
sp_set_baudrate(port,BAUD);
// write reset
cmd=0;
dgus_init(_serial_bytes_available, _serial_recv_byte, _serial_send_data, _a_recv_handler);
dgus_set_page(1);
dgus_set_text_padded(0x6000, "xyz 260.0 000.0 000.0", 32);
dgus_set_text_padded(0x6010, "192/220c 57/60c", 16);
dgus_set_var(0x500A, 999);
dgus_set_text_padded(0x6030, "300/62000", 16);
dgus_set_text_padded(0x6038, "00:24 / 02:16", 16);
/*uint16_t buf[20];
uint8_t *ubuf = (uint8_t *)buf;
memset(buf, 0, sizeof(buf));
//dgus_request_var(0x1036, 1);
dgus_get_var(0x5014, buf, 1);
printf("BUF 0x%02x (%d)\n", buf[0], buf[0]);
dgus_get_text(0x6100, ubuf, 10);
printf("BUF %s\n", (char *)(ubuf));
*/
// file testing
_pg(0);
static int16_t curve_val = 0;
static clock_t start_time = 0;
if (start_time == 0)
start_time = clock();
curve *cur = dgus_curve_buffer_create(2, 5);
dgus_curve_init_channel(cur, 0);
dgus_curve_init_channel(cur, 1);
int x = 0;
while(x < 200) {
dgus_recv_data();
// looping till required time is not achieved
if (clock() > start_time + (CLOCKS_PER_SEC/1000) * 500) {
dgus_curve_add_data(cur, 0, (uint16_t)rand() % 300);
dgus_curve_add_data(cur, 1, (uint16_t)rand() % 300);
dgus_curve_send_data(cur);
printf("CLOCK %ld\n", start_time);
curve_val = rand() % 1000;
start_time = clock();
x++;
}
}
uint16_t page = 0;
dgus_get_page(&page);
printf("PAGE %d\n", page);
uint8_t br = 0;
dgus_get_brightness(&br);
printf("BRI %d\n", br);
dgus_set_brightness(50);
sleep(3);
dgus_cmd_system_config conf;
dgus_get_system_config(&conf);
printf("System Config: \n");
printf(" Touch Sense: 0x%02x \n", conf.touch_panel_sensitivity_ro);
printf(" Touch Mode : 0x%02x \n", conf.touch_panel_mode_config_ro);
printf(" CRC : 0x%02x \n", conf.crc_enabled);
printf(" Audio En : 0x%02x \n", conf.music_enabled);
printf(" 22 bin : 0x%02x \n", conf.load_22_bin_ro);
printf(" Var Upload : 0x%02x \n", conf.var_auto_upload);
printf(" AudioC : 0x%02x \n", conf.touch_audio_enabled);
printf(" BL Standby : 0x%02x \n", conf.backight_standby);
printf(" Orientation: 0x%02x \n", conf.screen_orientation);
dgus_system_reset(0);
putchar('\n');
i = 0;
sp_close(port);
return 0;
}