예제 #1
0
파일: braille.c 프로젝트: plundblad/brltty
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  if (!isSerialDevice(&device)) {
    unsupportedDevice(device);
    return 0;
  }

  if ((serialDevice = serialOpenDevice(device))) {
    if (serialRestartDevice(serialDevice, serialBaud)) {
      serialCharactersPerSecond = serialBaud / serialGetCharacterBits(serialDevice);

      /* hm, how to switch to 38400 ? 
      static const unsigned char sequence[] = {ESC, 'V', CR};
      writeData(brl, sequence, sizeof(sequence));
      serialDiscardInput(serialDevice);
      serialSetBaud(serialDevice, 38400);
      */

      {
        static const DotsTable dots = {
          0X01, 0X02, 0X04, 0X80, 0X40, 0X20, 0X08, 0X10
        };
        makeOutputTable(dots);
      }

      clearCells(textCells,  sizeof(textCells));
      clearCells(statusCells,  sizeof(statusCells));
      resetInputMode();

      cursorDots = 0XFF;
      cursorOffset = sizeof(textCells) / 2;

      brl->textColumns = sizeof(textCells);
      brl->textRows = 1;
      brl->statusColumns = sizeof(statusCells);
      brl->statusRows = 1;

      beep(brl);
      return 1;
    }

    serialCloseDevice(serialDevice);
    serialDevice = NULL;
  }

  return 0;
}
예제 #2
0
파일: braille.c 프로젝트: plundblad/brltty
static int
brl_readCommand (BrailleDisplay *brl, KeyTableCommandContext context) {
  unsigned char byte;
  const InputMode *mode;
  const InputBinding *binding;

  {
    int result = serialReadData(serialDevice, &byte, 1, 0, 0);

    if (result == 0) {
      if (inputMode->temporary)
        if (afterTimePeriod(&inputPeriod, NULL))
          resetInputMode();

      return EOF;
    }

    if (result == -1) {
      logSystemError("read");
      return BRL_CMD_RESTARTBRL;
    }
  }

  mode = inputMode;
  if (mode->temporary) resetInputMode();

  switch (byte) {
    case KEY_F1:     binding = &mode->keyF1;     break;
    case KEY_F2:     binding = &mode->keyF2;     break;
    case KEY_LEFT:   binding = &mode->keyLeft;   break;
    case KEY_RIGHT:  binding = &mode->keyRight;  break;
    case KEY_UP:     binding = &mode->keyUp;     break;
    case KEY_DOWN:   binding = &mode->keyDown;   break;
    case KEY_CENTER: binding = &mode->keyCenter; break;

    default:
      logMessage(LOG_WARNING, "unhandled key: %s -> %02X", mode->name, byte);
      beep(brl);
      return EOF;
  }

  switch (binding->type) {
    case IBT_unbound:
      logMessage(LOG_WARNING, "unbound key: %s -> %02X", mode->name, byte);
      beep(brl);
      break;

    case IBT_command:
      return binding->value.command;

    case IBT_block:
      return binding->value.block + cursorOffset;

    case IBT_function:
      return binding->value.function(brl);

    case IBT_submode: {
      setInputMode(binding->value.submode);
      break;
    }

    default:
      logMessage(LOG_WARNING, "unhandled input binding type: %02X", binding->type);
      break;
  }

  return BRL_CMD_NOOP;
}
예제 #3
0
void resetEnvironment() {
	resetInputMode();
	enableRepeatAndCursor();
	resetConsole();
}