static int interpretCharacter (BrailleDisplay *brl, unsigned char dots, KeyTableCommandContext context) { int mask = 0X00; switch (currentKeyboardMode) { case KBM_NAVIGATE: return interpretNavigation(brl, dots, context); case KBM_INPUT: break; case KBM_INPUT_7: mask |= 0X40; break; case KBM_INPUT_78: mask |= 0XC0; break; case KBM_INPUT_8: mask |= 0X80; break; } return BRL_BLK_PASSDOTS + (translateInputCell(dots) | mask); }
static int brl_construct (BrailleDisplay *brl, char **parameters, const char *device) { { static TranslationTable outputTable = { #include "brl-out.h" }; setOutputTable(outputTable); makeInputTable(); { const unsigned char byte = 0XFF; if (memchr(outputTable, byte, sizeof(outputTable))) { outputTable[translateInputCell(byte)] = SUB; } } } if (!isSerialDeviceIdentifier(&device)) { unsupportedDeviceIdentifier(device); return 0; } makeDownloadFifo(); if ((serialDevice = serialOpenDevice(device))) { if (serialRestartDevice(serialDevice, 9600)) { brl->textRows = screenHeight; brl->textColumns = screenWidth; brl->buffer = &sourceImage[0][0]; memset(sourceImage, 0, sizeof(sourceImage)); deviceStatus = DEV_ONLINE; return 1; } serialCloseDevice(serialDevice); serialDevice = NULL; } return 0; }
static wchar_t getCharacter (BrailleDisplay *brl) { for (;;) { switch (getByte()) { default: break; case BNI_CHARACTER: return convertDotsToCharacter(textTable, translateInputCell(getByte())); case BNI_SPACE: switch (getByte()) { default: break; case BNC_SPACE: return WC_C(' '); } break; case BNI_BACKSPACE: switch (getByte() & 0X3F) { default: break; case BNC_SPACE: return WC_C('\b'); } break; case BNI_ENTER: switch (getByte()) { default: break; case BNC_SPACE: return WC_C('\r'); } break; } refreshCells(brl); } }
static int brl_readCommand(BrailleDisplay *brl, KeyTableCommandContext context) { int res = EOF; signed char status; brl_key key; status = braille_read(&key); if(status == -1) { logMessage(LOG_ERR, "error in braille_read: %s", braille_geterror()); res = BRL_CMD_RESTARTBRL; } else if(status) { switch(key.type) { case BRL_NONE: break; case BRL_CURSOR: res = BRL_BLK_ROUTE + key.code; break; case BRL_CMD: switch(key.code) { case BRLK_UP: res = BRL_BLK_PASSKEY + BRL_KEY_CURSOR_UP; break; case BRLK_DOWN: res = BRL_BLK_PASSKEY + BRL_KEY_CURSOR_DOWN; break; case BRLK_RIGHT: res = BRL_BLK_PASSKEY + BRL_KEY_CURSOR_RIGHT; break; case BRLK_LEFT: res = BRL_BLK_PASSKEY + BRL_KEY_CURSOR_LEFT; break; case BRLK_INSERT: res = BRL_BLK_PASSKEY + BRL_KEY_INSERT; break; case BRLK_HOME: res = BRL_BLK_PASSKEY + BRL_KEY_HOME; break; case BRLK_END: res = BRL_BLK_PASSKEY + BRL_KEY_END; break; case BRLK_PAGEUP: res = BRL_BLK_PASSKEY + BRL_KEY_PAGE_UP; break; case BRLK_PAGEDOWN: res = BRL_BLK_PASSKEY + BRL_KEY_PAGE_DOWN; break; case BRLK_BACKWARD: res = BRL_CMD_FWINLT; break; case BRLK_FORWARD: res = BRL_CMD_FWINRT; break; case BRLK_ABOVE: res = BRL_CMD_LNUP; break; case BRLK_BELOW: res = BRL_CMD_LNDN; break; default: break; } break; case BRL_KEY: res = BRL_BLK_PASSDOTS | translateInputCell(key.braille); break; default: break; } } return res; }
static int brl_readCommand (BrailleDisplay *brl, KeyTableCommandContext context) { while (1) { unsigned char packet[3]; int size = readPacket(brl, packet, sizeof(packet)); if (size == 0) break; if (size < 0) return BRL_CMD_RESTARTBRL; switch (packet[1]) { default: break; case 1: return BRL_BLK_PASSDOTS | translateInputCell(packet[2]); case 2: { unsigned char column = packet[2]; if (column && (column <= brl->textColumns)) return BRL_BLK_ROUTE + (column - 1); break; } case 3: switch (packet[2]) { default: break; // left rear: two columns, one row case 0X02: // ESC return BRL_CMD_LEARN; case 0X01: // M return BRL_CMD_PREFMENU; // left middle: cross case 0X06: // up return BRL_CMD_LNUP; case 0X03: // left return BRL_CMD_FWINLT; case 0X05: // right return BRL_CMD_FWINRT; case 0X04: // down return BRL_CMD_LNDN; // left front: two columns, three rows case 0X09: // ins return BRL_CMD_RETURN; case 0X0A: // E return BRL_CMD_TOP; case 0X0B: // supp return BRL_CMD_CSRTRK; case 0X0C: // L return BRL_CMD_BOT; case 0X07: // extra 1 (40s only) return BRL_CMD_CHRLT; case 0X08: // extra 2 (40s only) return BRL_CMD_CHRRT; case 0x0E: // left thumb return BRL_BLK_PASSKEY + BRL_KEY_BACKSPACE; case 0x0F: // right thumb return BRL_BLK_PASSDOTS; case 0x3F: // both thumbs return BRL_BLK_PASSKEY + BRL_KEY_ENTER; case 0X29: // key under dot 7 return BRL_BLK_PASSKEY + BRL_KEY_ESCAPE; case 0X2A: // key under dot 8 return BRL_BLK_PASSKEY + BRL_KEY_TAB; // right rear: one column, one row case 0X19: // extra 3 (40s only) return BRL_CMD_INFO; // right middle: one column, two rows case 0X1B: // extra 4 (40s only) return BRL_CMD_PRDIFLN; case 0X1A: // extra 5 (40s only) return BRL_CMD_NXDIFLN; // right front: one column, four rows case 0X2B: // slash (40s only) return BRL_CMD_FREEZE; case 0X2C: // asterisk (40s only) return BRL_CMD_DISPMD; case 0X2D: // minus (40s only) return BRL_CMD_ATTRVIS; case 0X2E: // plus (40s only) return BRL_CMD_CSRVIS; // first (top) row of numeric pad case 0X37: // seven (40s only) return BRL_BLK_PASSKEY + BRL_KEY_HOME; case 0X38: // eight (40s only) return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_UP; case 0X39: // nine (40s only) return BRL_BLK_PASSKEY + BRL_KEY_PAGE_UP; // second row of numeric pad case 0X34: // four (40s only) return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_LEFT; case 0X35: // five (40s only) return BRL_CMD_CSRJMP_VERT; case 0X36: // six (40s only) return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_RIGHT; // third row of numeric pad case 0X31: // one (40s only) return BRL_BLK_PASSKEY + BRL_KEY_END; case 0X32: // two (40s only) return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_DOWN; case 0X33: // three (40s only) return BRL_BLK_PASSKEY + BRL_KEY_PAGE_DOWN; // fourth (bottom) row of numeric pad case 0X28: // verr num (40s only) return BRL_CMD_SIXDOTS; case 0X30: // zero (40s only) return BRL_BLK_PASSKEY + BRL_KEY_INSERT; case 0X2F: // supp (40s only) return BRL_BLK_PASSKEY + BRL_KEY_DELETE; } break; /* When data is written to the display it acknowledges with: * 0X00 0X04 0Xxx * where xx is the number of bytes written. */ case 4: continue; } logUnexpectedPacket(packet, size); } return EOF; }
static int brl_readCommand (BrailleDisplay *brl, KeyTableCommandContext context) { int key = readKey(); if (context != currentContext) { logMessage(LOG_DEBUG, "Context switch: %d -> %d", currentContext, context); switch (currentContext = context) { case KTB_CTX_DEFAULT: deviceStatus = DEV_ONLINE; break; default: break; } } if (key != EOF) { switch (key) { case KEY_FUNCTION_ENTER: return BRL_CMD_KEY(ENTER); case KEY_FUNCTION_TAB: return BRL_CMD_KEY(TAB); case KEY_FUNCTION_CURSOR_UP: return BRL_CMD_KEY(CURSOR_UP); case KEY_FUNCTION_CURSOR_DOWN: return BRL_CMD_KEY(CURSOR_DOWN); case KEY_FUNCTION_CURSOR_LEFT: return BRL_CMD_KEY(CURSOR_LEFT); case KEY_FUNCTION_CURSOR_RIGHT: return BRL_CMD_KEY(CURSOR_RIGHT); case KEY_FUNCTION_CURSOR_UP_JUMP: return BRL_CMD_KEY(HOME); case KEY_FUNCTION_CURSOR_DOWN_JUMP: return BRL_CMD_KEY(END); case KEY_FUNCTION_CURSOR_LEFT_JUMP: return BRL_CMD_KEY(PAGE_UP); case KEY_FUNCTION_CURSOR_RIGHT_JUMP: return BRL_CMD_KEY(PAGE_DOWN); case KEY_FUNCTION_F1: return BRL_CMD_KFN(1); case KEY_FUNCTION_F2: return BRL_CMD_KFN(2); case KEY_FUNCTION_F3: return BRL_CMD_KFN(3); case KEY_FUNCTION_F4: return BRL_CMD_KFN(4); case KEY_FUNCTION_F5: return BRL_CMD_KFN(5); case KEY_FUNCTION_F6: return BRL_CMD_KFN(6); case KEY_FUNCTION_F7: return BRL_CMD_KFN(7); case KEY_FUNCTION_F9: return BRL_CMD_KFN(9); case KEY_FUNCTION_F10: return BRL_CMD_KFN(10); case KEY_COMMAND: { int command; while ((command = readKey()) == EOF) asyncWait(1); logMessage(LOG_DEBUG, "Received command: (0x%2.2X) 0x%4.4X", KEY_COMMAND, command); switch (command) { case KEY_COMMAND: /* pressing the escape command twice will pass it through */ return BRL_CMD_BLK(PASSDOTS) + translateInputCell(KEY_COMMAND); case KEY_COMMAND_SWITCHVT_PREV: return BRL_CMD_SWITCHVT_PREV; case KEY_COMMAND_SWITCHVT_NEXT: return BRL_CMD_SWITCHVT_NEXT; case KEY_COMMAND_SWITCHVT_1: return BRL_CMD_BLK(SWITCHVT) + 0; case KEY_COMMAND_SWITCHVT_2: return BRL_CMD_BLK(SWITCHVT) + 1; case KEY_COMMAND_SWITCHVT_3: return BRL_CMD_BLK(SWITCHVT) + 2; case KEY_COMMAND_SWITCHVT_4: return BRL_CMD_BLK(SWITCHVT) + 3; case KEY_COMMAND_SWITCHVT_5: return BRL_CMD_BLK(SWITCHVT) + 4; case KEY_COMMAND_SWITCHVT_6: return BRL_CMD_BLK(SWITCHVT) + 5; case KEY_COMMAND_SWITCHVT_7: return BRL_CMD_BLK(SWITCHVT) + 6; case KEY_COMMAND_SWITCHVT_8: return BRL_CMD_BLK(SWITCHVT) + 7; case KEY_COMMAND_SWITCHVT_9: return BRL_CMD_BLK(SWITCHVT) + 8; case KEY_COMMAND_SWITCHVT_10: return BRL_CMD_BLK(SWITCHVT) + 9; case KEY_COMMAND_PAGE_UP: return BRL_CMD_KEY(PAGE_UP); case KEY_COMMAND_PAGE_DOWN: return BRL_CMD_KEY(PAGE_DOWN); case KEY_COMMAND_PREFMENU: currentLine = 0; cursorRow = 0; cursorColumn = 31; sendCursorRow(); return BRL_CMD_PREFMENU; case KEY_COMMAND_PREFSAVE: return BRL_CMD_PREFSAVE; case KEY_COMMAND_PREFLOAD: return BRL_CMD_PREFLOAD; case KEY_COMMAND_FREEZE_ON: return BRL_CMD_FREEZE | BRL_FLG_TOGGLE_ON; case KEY_COMMAND_FREEZE_OFF: return BRL_CMD_FREEZE | BRL_FLG_TOGGLE_OFF; case KEY_COMMAND_RESTARTBRL: return BRL_CMD_RESTARTBRL; case KEY_COMMAND_DOWNLOAD: downloadFile(); break; default: logMessage(LOG_WARNING, "Unknown command: (0X%2.2X) 0X%4.4X", KEY_COMMAND, command); break; } break; } default: switch (key & KEY_MASK) { case KEY_UPDATE: handleUpdate(key >> KEY_SHIFT); break; case KEY_FUNCTION: logMessage(LOG_WARNING, "Unknown function: (0X%2.2X) 0X%4.4X", KEY_COMMAND, key>>KEY_SHIFT); break; default: { unsigned char dots = translateInputCell(key); logMessage(LOG_DEBUG, "Received character: 0X%2.2X dec=%d dots=%2.2X", key, key, dots); return BRL_CMD_BLK(PASSDOTS) + dots; } } break; } } return EOF; }
static int interpretSpaceChord (BrailleDisplay *brl, unsigned char dots, KeyTableCommandContext context) { if (context == KTB_CTX_CHORDS) return BRL_BLK_PASSDOTS | translateInputCell(dots) | BRL_DOTC; switch (dots) { default: /* These are overridden by the Braille Note itself. */ case BNC_E: /* exit current operation */ case BNC_H: /* help for current operation */ case BNC_O: /* go to options menu */ case BNC_R: /* repeat current prompt */ case BNC_U: /* uppercase for computer braille */ case BNC_Z: /* exit current operation */ case BNC_PERCENT: /* acknowledge alarm */ case BNC_6: /* go to task menu */ case (BND_1 | BND_2 | BND_3 | BND_4 | BND_5 | BND_6): /* go to main menu */ break; case BNC_SPACE: return interpretCharacter(brl, dots, context); case BNC_C: return BRL_CMD_PREFMENU; case BNC_D: return BRL_CMD_PREFLOAD; case BNC_F: return getFunctionKey(brl); case BNC_L: temporaryRoutingOperation = BRL_BLK_SETLEFT; return BRL_CMD_NOOP; case BNC_M: return BRL_CMD_MUTE; case BNC_N: persistentKeyboardMode = KBM_NAVIGATE; temporaryKeyboardMode = persistentKeyboardMode; return BRL_CMD_NOOP; case BNC_P: return BRL_CMD_PASTE; case BNC_S: return BRL_CMD_SAY_LINE; case BNC_V: { unsigned int vt; if (getDecimalInteger(brl, &vt, 2, "virt term num")) { if (!vt) vt = 0X100; return BRL_BLK_SWITCHVT + (vt - 1); } return EOF; } case BNC_W: return BRL_CMD_PREFSAVE; case BNC_X: { unsigned char character; if (!getHexadecimalCharacter(brl, &character)) return EOF; return BRL_BLK_PASSCHAR + character; } case BNC_LPAREN: temporaryRoutingOperation = BRL_BLK_CLIP_NEW; return BRL_CMD_NOOP; case BNC_LBRACE: temporaryRoutingOperation = BRL_BLK_CLIP_ADD; return BRL_CMD_NOOP; case BNC_RPAREN: temporaryRoutingOperation = BRL_BLK_COPY_RECT; return BRL_CMD_NOOP; case BNC_RBRACE: temporaryRoutingOperation = BRL_BLK_COPY_LINE; return BRL_CMD_NOOP; case BNC_BAR: return BRL_CMD_CSRJMP_VERT; case BNC_QUESTION: return BRL_CMD_LEARN; case (BND_2 | BND_3 | BND_5 | BND_6): return BRL_BLK_PASSKEY + BRL_KEY_TAB; case (BND_2 | BND_3): return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_LEFT; case (BND_5 | BND_6): return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_RIGHT; case (BND_2 | BND_5): return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_UP; case (BND_3 | BND_6): return BRL_BLK_PASSKEY + BRL_KEY_CURSOR_DOWN; case (BND_2): return BRL_BLK_PASSKEY + BRL_KEY_HOME; case (BND_3): return BRL_BLK_PASSKEY + BRL_KEY_END; case (BND_5): return BRL_BLK_PASSKEY + BRL_KEY_PAGE_UP; case (BND_6): return BRL_BLK_PASSKEY + BRL_KEY_PAGE_DOWN; case (BND_3 | BND_5): return BRL_BLK_PASSKEY + BRL_KEY_INSERT; case (BND_2 | BND_5 | BND_6): return BRL_BLK_PASSKEY + BRL_KEY_DELETE; case (BND_2 | BND_6): return BRL_BLK_PASSKEY + BRL_KEY_ESCAPE; case (BND_4): case (BND_4 | BND_5): temporaryKeyboardMode = KBM_INPUT; goto kbmFinish; case (BND_4 | BND_3): case (BND_4 | BND_5 | BND_3): temporaryKeyboardMode = KBM_INPUT_7; goto kbmFinish; case (BND_4 | BND_3 | BND_6): case (BND_4 | BND_5 | BND_3 | BND_6): temporaryKeyboardMode = KBM_INPUT_78; goto kbmFinish; case (BND_4 | BND_6): case (BND_4 | BND_5 | BND_6): temporaryKeyboardMode = KBM_INPUT_8; kbmFinish: if (dots & BND_5) persistentKeyboardMode = temporaryKeyboardMode; return BRL_CMD_NOOP; } return EOF; }