Example #1
0
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  if ((brl->data = malloc(sizeof(*brl->data)))) {
    memset(brl->data, 0, sizeof(*brl->data));
    brl->data->brailleDevice = -1;

#ifdef KEYBOARD_DEVICE_NAME
    brl->data->keyboardDevice = -1;
#endif /* KEYBOARD_DEVICE_NAME */

    if (openBrailleDevice(brl, device)) {
      logBrailleVersion(brl);

#ifdef KEYBOARD_DEVICE_NAME
      if (openKeyboardDevice(brl)) {
#endif /* KEYBOARD_DEVICE_NAME */
        if (clearBrailleCells(brl)) {
#ifdef KEYBOARD_DEVICE_NAME
          {
            const KeyTableDefinition *ktd = &KEY_TABLE_DEFINITION(all);

            brl->keyBindings = ktd->bindings;
            brl->keyNames = ktd->names;
          }
#endif /* KEYBOARD_DEVICE_NAME */

          brl->textColumns = BRAILLE_CELL_COUNT;
          makeOutputTable(dotsTable_ISO11548_1);
          brl->data->forceRewrite = 1;
          return 1;
        }

#ifdef KEYBOARD_DEVICE_NAME
        closeKeyboardDevice(brl);
      }
#endif /* KEYBOARD_DEVICE_NAME */

      closeBrailleDevice(brl);
    }

    free(brl->data);
  } else {
    logMallocError();
  }

  return 0;
}
Example #2
0
static int
brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
  if (!isSerialDevice(&device)) {
    unsupportedDevice(device);
    return 0;
  }

  if ((serialDevice = serialOpenDevice(device))) {
    unsigned int baud = 19200;
    charactersPerSecond = baud / 11;

    if (serialRestartDevice(serialDevice, baud)) {
      if (serialSetParity(serialDevice, SERIAL_PARITY_EVEN)) {
        if (writePacket(brl, 4, NULL, 0)) {
          while (serialAwaitInput(serialDevice, 500)) {
            unsigned char response[3];
            int size = readPacket(brl, response, sizeof(response));
            if (size <= 0) break;

            if (response[1] == 4) {
              brl->textColumns = response[2];
              brl->textRows = 1;

              makeOutputTable(dotsTable_ISO11548_1);
              makeInputTable();

              if (!clearBrailleCells(brl)) break;
              if (!clearVisualText(brl)) break;
              if (!writeBrailleCells(brl)) break;

              return 1;
            }
          }
        }
      }
    }

    serialCloseDevice(serialDevice);
    serialDevice = NULL;
  }
  
  return 0;
}