Lines Matching +full:0 +full:- +full:1
4 * Copyright (c) 2008, 2010-2011, 2016-2017 Samuel Thibault
28 #include "qemu/main-loop.h"
38 #if 0
45 #define ESC 0x1B
47 #define BAUM_REQ_DisplayData 0x01
48 #define BAUM_REQ_GetVersionNumber 0x05
49 #define BAUM_REQ_GetKeys 0x08
50 #define BAUM_REQ_SetMode 0x12
51 #define BAUM_REQ_SetProtocol 0x15
52 #define BAUM_REQ_GetDeviceIdentity 0x84
53 #define BAUM_REQ_GetSerialNumber 0x8A
55 #define BAUM_RSP_CellCount 0x01
56 #define BAUM_RSP_VersionNumber 0x05
57 #define BAUM_RSP_ModeSetting 0x11
58 #define BAUM_RSP_CommunicationChannel 0x16
59 #define BAUM_RSP_PowerdownSignal 0x17
60 #define BAUM_RSP_HorizontalSensors 0x20
61 #define BAUM_RSP_VerticalSensors 0x21
62 #define BAUM_RSP_RoutingKeys 0x22
63 #define BAUM_RSP_Switches 0x23
64 #define BAUM_RSP_TopKeys 0x24
65 #define BAUM_RSP_HorizontalSensor 0x25
66 #define BAUM_RSP_VerticalSensor 0x26
67 #define BAUM_RSP_RoutingKey 0x27
68 #define BAUM_RSP_FrontKeys6 0x28
69 #define BAUM_RSP_BackKeys6 0x29
70 #define BAUM_RSP_CommandKeys 0x2B
71 #define BAUM_RSP_FrontKeys10 0x2C
72 #define BAUM_RSP_BackKeys10 0x2D
73 #define BAUM_RSP_EntryKeys 0x33
74 #define BAUM_RSP_JoyStick 0x34
75 #define BAUM_RSP_ErrorCode 0x40
76 #define BAUM_RSP_InfoBlock 0x42
77 #define BAUM_RSP_DeviceIdentity 0x84
78 #define BAUM_RSP_SerialNumber 0x8A
79 #define BAUM_RSP_BluetoothName 0x8C
81 #define BAUM_TL1 0x01
82 #define BAUM_TL2 0x02
83 #define BAUM_TL3 0x04
84 #define BAUM_TR1 0x08
85 #define BAUM_TR2 0x10
86 #define BAUM_TR3 0x20
91 #define Y_MAX 1
110 #define TYPE_CHARDEV_BRAILLE "chardev-braille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1, 0, 0), '.'),
201 DO(BRLAPI_DOTS(0, 0, 1, 1, 0, 1, 0, 0), '+'),
202 DO(BRLAPI_DOTS(0, 0, 1, 0, 0, 1, 0, 0), '-'),
203 DO(BRLAPI_DOTS(1, 0, 0, 0, 0, 1, 0, 0), '*'),
204 DO(BRLAPI_DOTS(0, 0, 1, 1, 0, 0, 0, 0), '/'),
205 DO(BRLAPI_DOTS(1, 1, 1, 0, 1, 1, 0, 0), '('),
206 DO(BRLAPI_DOTS(0, 1, 1, 1, 1, 1, 0, 0), ')'),
208 DO(BRLAPI_DOTS(1, 1, 1, 1, 0, 1, 0, 0), '&'),
209 DO(BRLAPI_DOTS(0, 0, 1, 1, 1, 1, 0, 0), '#'),
211 DO(BRLAPI_DOTS(0, 0, 0, 0, 0, 1, 0, 0), ','),
212 DO(BRLAPI_DOTS(0, 0, 0, 0, 1, 1, 0, 0), ';'),
213 DO(BRLAPI_DOTS(1, 0, 0, 0, 1, 1, 0, 0), ':'),
214 DO(BRLAPI_DOTS(0, 1, 1, 1, 0, 1, 0, 0), '!'),
215 DO(BRLAPI_DOTS(1, 0, 0, 1, 1, 1, 0, 0), '?'),
216 DO(BRLAPI_DOTS(0, 0, 0, 0, 1, 0, 0, 0), '"'),
217 DO(BRLAPI_DOTS(0, 0, 1, 0, 0, 0, 0, 0), '\''),
218 DO(BRLAPI_DOTS(0, 0, 0, 1, 0, 0, 0, 0), '`'),
219 DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 0, 1, 0), '^'),
220 DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 0, 0, 0), '~'),
221 DO(BRLAPI_DOTS(0, 1, 0, 1, 0, 1, 1, 0), '['),
222 DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 1, 1, 0), ']'),
223 DO(BRLAPI_DOTS(0, 1, 0, 1, 0, 1, 0, 0), '{'),
224 DO(BRLAPI_DOTS(1, 1, 0, 1, 1, 1, 0, 0), '}'),
225 DO(BRLAPI_DOTS(1, 1, 1, 1, 1, 1, 0, 0), '='),
226 DO(BRLAPI_DOTS(1, 1, 0, 0, 0, 1, 0, 0), '<'),
227 DO(BRLAPI_DOTS(0, 0, 1, 1, 1, 0, 0, 0), '>'),
228 DO(BRLAPI_DOTS(1, 1, 0, 1, 0, 1, 0, 0), '$'),
229 DO(BRLAPI_DOTS(1, 0, 0, 1, 0, 1, 0, 0), '%'),
230 DO(BRLAPI_DOTS(0, 0, 0, 1, 0, 0, 1, 0), '@'),
231 DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 0, 0), '|'),
232 DO(BRLAPI_DOTS(1, 1, 0, 0, 1, 1, 1, 0), '\\'),
233 DO(BRLAPI_DOTS(0, 0, 0, 1, 1, 1, 0, 0), '_'),
242 if (baum->deferred_init) { in baum_deferred_init()
243 return 1; in baum_deferred_init()
246 if (brlapi__getDisplaySize(baum->brlapi, &baum->x, &baum->y) == -1) { in baum_deferred_init()
248 return 0; in baum_deferred_init()
250 if (baum->y > Y_MAX) { in baum_deferred_init()
251 baum->y = Y_MAX; in baum_deferred_init()
253 if (baum->x > X_MAX) { in baum_deferred_init()
254 baum->x = X_MAX; in baum_deferred_init()
257 con = qemu_console_lookup_by_index(0); in baum_deferred_init()
260 if (tty == -1) in baum_deferred_init()
264 if (brlapi__enterTtyMode(baum->brlapi, tty, NULL) == -1) { in baum_deferred_init()
266 return 0; in baum_deferred_init()
268 baum->deferred_init = 1; in baum_deferred_init()
269 return 1; in baum_deferred_init()
278 if (!baum->out_buf_used) in baum_chr_accept_input()
283 if (room > baum->out_buf_used) in baum_chr_accept_input()
284 room = baum->out_buf_used; in baum_chr_accept_input()
286 first = BUF_SIZE - baum->out_buf_ptr; in baum_chr_accept_input()
288 qemu_chr_be_write(chr, baum->out_buf + baum->out_buf_ptr, first); in baum_chr_accept_input()
289 baum->out_buf_ptr = 0; in baum_chr_accept_input()
290 baum->out_buf_used -= first; in baum_chr_accept_input()
291 room -= first; in baum_chr_accept_input()
293 qemu_chr_be_write(chr, baum->out_buf + baum->out_buf_ptr, room); in baum_chr_accept_input()
294 baum->out_buf_ptr += room; in baum_chr_accept_input()
295 baum->out_buf_used -= room; in baum_chr_accept_input()
302 g_autofree uint8_t *io_buf = g_malloc(1 + 2 * len); in baum_write_packet()
306 while (len--) in baum_write_packet()
310 len = cur - io_buf; in baum_write_packet()
319 len -= room; in baum_write_packet()
321 if (len > BUF_SIZE - baum->out_buf_used) { in baum_write_packet()
324 baum->out_buf_used = 0; in baum_write_packet()
325 baum->out_buf_ptr = 0; in baum_write_packet()
327 out = baum->out_buf_ptr; in baum_write_packet()
328 baum->out_buf_used += len; in baum_write_packet()
329 first = BUF_SIZE - baum->out_buf_ptr; in baum_write_packet()
331 memcpy(baum->out_buf + out, cur, first); in baum_write_packet()
332 out = 0; in baum_write_packet()
333 len -= first; in baum_write_packet()
336 memcpy(baum->out_buf + out, cur, len); in baum_write_packet()
344 uint8_t cell_count[] = { BAUM_RSP_CellCount, baum->x * baum->y }; in baum_cellCount_timer_cb()
353 uint8_t req = 0; in baum_eat_packet()
355 if (!len--) in baum_eat_packet()
356 return 0; in baum_eat_packet()
359 if (!len--) in baum_eat_packet()
360 return 0; in baum_eat_packet()
363 DPRINTF("Dropped %td bytes!\n", cur - buf); in baum_eat_packet()
367 if (!len--) \ in baum_eat_packet()
368 return 0; \ in baum_eat_packet()
370 if (!len--) \ in baum_eat_packet()
371 return 0; \ in baum_eat_packet()
374 if (timer_pending(baum->cellCount_timer)) { \ in baum_eat_packet()
375 timer_del(baum->cellCount_timer); \ in baum_eat_packet()
378 return (cur - 2 - buf); \ in baum_eat_packet()
381 } while (0) in baum_eat_packet()
394 timer_mod(baum->cellCount_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + in baum_eat_packet()
396 for (i = 0; i < baum->x * baum->y ; i++) { in baum_eat_packet()
401 cursor = i + 1; in baum_eat_packet()
410 timer_del(baum->cellCount_timer); in baum_eat_packet()
412 memset(zero, 0, baum->x * baum->y); in baum_eat_packet()
416 .regionBegin = 1, in baum_eat_packet()
417 .regionSize = baum->x * baum->y, in baum_eat_packet()
419 .textSize = baum->x * baum->y, in baum_eat_packet()
423 .charset = (char *)"ISO-8859-1", in baum_eat_packet()
426 if (brlapi__write(baum->brlapi, &wa) == -1) in baum_eat_packet()
452 identity[11] = '0' + baum->x / 10; in baum_eat_packet()
453 identity[12] = '0' + baum->x % 10; in baum_eat_packet()
459 uint8_t version[] = { BAUM_RSP_VersionNumber, 1 }; /* ? */ in baum_eat_packet()
467 '0','0','0','0','0','0','0','0' }; in baum_eat_packet()
474 DPRINTF("Get%0#2x\n", req); in baum_eat_packet()
479 DPRINTF("unrecognized request %0#2x\n", req); in baum_eat_packet()
481 if (!len--) in baum_eat_packet()
482 return 0; in baum_eat_packet()
484 cur--; in baum_eat_packet()
487 return cur - buf; in baum_eat_packet()
497 return 0; in baum_chr_write()
498 if (!baum->brlapi) in baum_chr_write()
506 if (tocopy > BUF_SIZE - baum->in_buf_used) in baum_chr_write()
507 tocopy = BUF_SIZE - baum->in_buf_used; in baum_chr_write()
509 memcpy(baum->in_buf + baum->in_buf_used, buf, tocopy); in baum_chr_write()
510 baum->in_buf_used += tocopy; in baum_chr_write()
512 len -= tocopy; in baum_chr_write()
515 cur = 0; in baum_chr_write()
516 while (cur < baum->in_buf_used && in baum_chr_write()
517 (eaten = baum_eat_packet(baum, baum->in_buf + cur, baum->in_buf_used - cur))) in baum_chr_write()
522 memmove(baum->in_buf, baum->in_buf + cur, baum->in_buf_used - cur); in baum_chr_write()
523 baum->in_buf_used -= cur; in baum_chr_write()
553 if (!baum->brlapi) in baum_chr_read()
557 while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) { in baum_chr_read()
564 baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1); in baum_chr_read()
565 baum_send_key(baum, BAUM_RSP_RoutingKey, 0); in baum_chr_read()
567 case 0: in baum_chr_read()
571 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
575 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
579 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
583 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
587 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
591 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
595 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
599 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
603 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
607 baum_send_key(baum, BAUM_RSP_TopKeys, 0); in baum_chr_read()
615 if (keysym < 0x100) { in baum_chr_read()
618 baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, dots); in baum_chr_read()
619 baum_send_key2(baum, BAUM_RSP_EntryKeys, 0, 0); in baum_chr_read()
626 if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) { in baum_chr_read()
628 brlapi__closeConnection(baum->brlapi); in baum_chr_read()
629 g_free(baum->brlapi); in baum_chr_read()
630 baum->brlapi = NULL; in baum_chr_read()
638 timer_free(baum->cellCount_timer); in char_braille_finalize()
639 if (baum->brlapi) { in char_braille_finalize()
640 brlapi__closeConnection(baum->brlapi); in char_braille_finalize()
641 g_free(baum->brlapi); in char_braille_finalize()
654 baum->brlapi = handle; in baum_chr_open()
656 baum->brlapi_fd = brlapi__openConnection(handle, NULL, NULL); in baum_chr_open()
657 if (baum->brlapi_fd == -1) { in baum_chr_open()
661 baum->brlapi = NULL; in baum_chr_open()
664 baum->deferred_init = 0; in baum_chr_open()
666 baum->cellCount_timer = timer_new_ns(QEMU_CLOCK_VIRTUAL, baum_cellCount_timer_cb, baum); in baum_chr_open()
668 qemu_set_fd_handler(baum->brlapi_fd, baum_chr_read, NULL, baum); in baum_chr_open()
675 cc->open = baum_chr_open; in char_braille_class_init()
676 cc->chr_write = baum_chr_write; in char_braille_class_init()
677 cc->chr_accept_input = baum_chr_accept_input; in char_braille_class_init()