示例#1
0
static void
setInputMode (const InputMode *mode) {
  if (mode->temporary) {
    char title[sizeof(textCells) + 1];
    snprintf(title, sizeof(title), "%s Mode", mode->name);
    message(NULL, title, MSG_NODELAY|MSG_SILENT);
  }

  inputMode = mode;
  startTimePeriod(&inputPeriod, 3000);
}
示例#2
0
文件: cap.c 项目: 286897655/clumsy
static void capStartUp() {
    if (bufHead->next == NULL && bufTail->next == NULL) {
        bufHead->next = bufTail;
        bufTail->prev = bufHead;
        bufSize = 0;
    } else {
        assert(isBufEmpty());
    }

    startTimePeriod();
    capLastTick = timeGetTime();
}
示例#3
0
static void BWLimiterStartUp() 
{
	if (bufHead->next == NULL && bufTail->next == NULL) {
		bufHead->next = bufTail;
		bufTail->prev = bufHead;
		bufSize = 0;
	} else {
		assert(isBufEmpty());
	}
	BWLimiterStartTick = 0;
	startTimePeriod();
}
示例#4
0
int
asyncAwaitCondition (int timeout, AsyncConditionTester *testCondition, void *data) {
  TimePeriod period;
  startTimePeriod(&period, timeout);

  while (!(testCondition && testCondition(data))) {
    long int elapsed;

    if (afterTimePeriod(&period, &elapsed)) return 0;
    awaitAction(timeout - elapsed);
  }

  return 1;
}
示例#5
0
int
serialPollInput (SerialDevice *serial, int timeout) {
  TimePeriod period;

  if (timeout) startTimePeriod(&period, timeout);

  while (1) {
    if (serialTestInput(serial)) return 1;
    if (!timeout) break;
    if (afterTimePeriod(&period, NULL)) break;
    asyncWait(1);
  }

  errno = EAGAIN;
  return 0;
}
示例#6
0
int
enqueueKeyEvent (unsigned char set, unsigned char key, int press) {
  if (keyReleaseEvent) {
    if (press && (set == keyReleaseEvent->set) && (key == keyReleaseEvent->key)) {
      if (!afterTimePeriod(&keyReleasePeriod, NULL)) {
        deallocateKeyEvent(keyReleaseEvent);
        keyReleaseEvent = NULL;
        return 1;
      }
    }

    {
      KeyEvent *event = keyReleaseEvent;
      keyReleaseEvent = NULL;

      if (!addKeyEvent(event)) {
        deallocateKeyEvent(event);
        return 0;
      }
    }
  }

  {
    KeyEvent *event;

    if ((event = malloc(sizeof(*event)))) {
      event->set = set;
      event->key = key;
      event->press = press;

      if (keyReleaseTimeout && !press) {
        keyReleaseEvent = event;
        startTimePeriod(&keyReleasePeriod, keyReleaseTimeout);
        return 1;
      }

      if (addKeyEvent(event)) return 1;
      deallocateKeyEvent(event);
    } else {
      logMallocError();
    }
  }

  return 0;
}
示例#7
0
int
serialPollInput (SerialDevice *serial, int timeout) {
  if (serial->package.byte == SERIAL_NO_BYTE) {
    TimePeriod period;
    startTimePeriod(&period, timeout);

    while ((serial->package.byte = serial->package.port->driver->fetch(serial->package.port)) == SERIAL_NO_BYTE) {
      if (afterTimePeriod(&period, NULL)) {
        errno = EAGAIN;
        return 0;
      }

      approximateDelay(1);
    }
  }

  return 1;
}
示例#8
0
文件: bluetooth.c 项目: BaJIeK/brltty
BluetoothConnection *
bthOpenConnection (const char *address, uint8_t channel, int force) {
  BluetoothConnection *connection;

  if ((connection = malloc(sizeof(*connection)))) {
    memset(connection, 0, sizeof(*connection));
    connection->channel = channel;

    if (bthParseAddress(&connection->address, address)) {
      int alreadyTried = 0;

      if (force) {
        bthForgetConnectError(connection->address);
      } else {
        int value;

        if (bthRecallConnectError(connection->address, &value)) {
          errno = value;
          alreadyTried = 1;
        }
      }

      if (!alreadyTried) {
        TimePeriod period;
        startTimePeriod(&period, 2000);

	while (1) {
          if ((connection->extension = bthConnect(connection->address, connection->channel, 15000))) return connection;
	  if (afterTimePeriod(&period, NULL)) break;
	  if (errno != EBUSY) break;
	  approximateDelay(100);
	}

        bthRememberConnectError(connection->address, errno);
      }
    }

    free(connection);
  } else {
    logMallocError();
  }

  return NULL;
}
示例#9
0
文件: speech.c 项目: junwuwei/brltty
static void mywrite(volatile SpeechSynthesizer *spk, int fd, const void *buf, int len)
{
  char *pos = (char *)buf;
  int w;
  TimePeriod period;
  if(fd<0) return;
  startTimePeriod(&period, 2000);
  do {
    if((w = write(fd, pos, len)) < 0) {
      if(errno == EINTR || errno == EAGAIN) continue;
      else if(errno == EPIPE)
	myerror(spk, "ExternalSpeech: pipe to helper program was broken");
         /* try to reinit may be ??? */
      else myperror(spk, "ExternalSpeech: pipe to helper program: write");
      return;
    }
    pos += w; len -= w;
  } while(len && !afterTimePeriod(&period, NULL));
  if(len)
    myerror(spk, "ExternalSpeech: pipe to helper program: write timed out");
}
示例#10
0
static struct usbdevfs_urb *
usbInterruptTransfer (
  UsbEndpoint *endpoint,
  void *buffer,
  int length,
  int timeout
) {
  UsbDevice *device = endpoint->device;
  struct usbdevfs_urb *urb = usbSubmitRequest(device,
                                              endpoint->descriptor->bEndpointAddress,
                                              buffer, length, NULL);

  if (urb) {
    UsbEndpointExtension *eptx = endpoint->extension;
    int interval = endpoint->descriptor->bInterval + 1;
    TimePeriod period;

    if (timeout) startTimePeriod(&period, timeout);

    do {
      if (usbReapUrb(device, 0) &&
          deleteItem(eptx->completedRequests, urb)) {
        if (!urb->status) return urb;
        if ((errno = urb->status) < 0) errno = -errno;
        free(urb);
        break;
      }

      if (!timeout || afterTimePeriod(&period, NULL)) {
        usbCancelRequest(device, urb);
        errno = ETIMEDOUT;
        break;
      }

      approximateDelay(interval);
    } while (1);
  }

  return NULL;
}
示例#11
0
文件: braille.c 项目: BaJIeK/brltty
static int brl_construct (BrailleDisplay *brl, char **parameters, const char *device) {
	short n, success;		/* loop counters, flags, etc. */
	unsigned char *init_seq = (unsigned char *)"\002\0330";	/* string to send to Braille to initialise: [ESC][0] */
	unsigned char *init_ack = (unsigned char *)"\002\033V";	/* string to expect as acknowledgement: [ESC][V]... */
	unsigned char c;
	TimePeriod period;

	if (!isSerialDevice(&device)) {
		unsupportedDevice(device);
		return 0;
	}

	brlcols = -1;		/* length of braille display (auto-detected) */
	prevdata = rawdata = NULL;		/* clear pointers */

	/* No need to load translation tables, as these are now
	 * defined in tables.h
	 */

	/* Now open the Braille display device for random access */
	if (!(MB_serialDevice = serialOpenDevice(device))) goto failure;
	if (!serialRestartDevice(MB_serialDevice, BAUDRATE)) goto failure;
	if (!serialSetFlowControl(MB_serialDevice, SERIAL_FLOW_HARDWARE)) goto failure;

	/* MultiBraille initialisation procedure:
	 * [ESC][V][Braillelength][Software Version][CR]
	 * I guess, they mean firmware version with software version :*}
	 * firmware version == [Software Version] / 10.0
         */
	success = 0;
	if (init_seq[0])
		if (serialWriteData (MB_serialDevice, init_seq + 1, init_seq[0]) != init_seq[0])
			goto failure;
	startTimePeriod (&period, ACK_TIMEOUT);		/* initialise timeout testing */
	n = 0;
	do {
		approximateDelay (20);
		if (serialReadData (MB_serialDevice, &c, 1, 0, 0) == 0)
			continue;
		if (n < init_ack[0] && c != init_ack[1 + n])
			continue;
		if (n == init_ack[0]) {
			brlcols = c, success = 1;

			/* reading version-info */
			/* firmware version == [Software Version] / 10.0 */
			serialReadData (MB_serialDevice, &c, 1, 0, 0);
			logMessage (LOG_INFO, "MultiBraille: Version: %2.1f", c/10.0);

			/* read trailing [CR] */
			serialReadData (MB_serialDevice, &c, 1, 0, 0);
		}
		n++;
	}
	while (!afterTimePeriod (&period, NULL) && n <= init_ack[0]);

	if (success && (brlcols != 25)) {
          if ((prevdata = malloc(brl->textColumns * brl->textRows))) {
            if ((rawdata = malloc(20 + (brl->textColumns * brl->textRows * 2)))) {
              brl->textColumns = brlcols;
              brl->textRows = BRLROWS;

              brl->statusColumns = 5;
              brl->statusRows = 1;

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

                makeOutputTable(dots);
              }

              return 1;
            } else {
              logMallocError();
            }

            free(prevdata);
          } else {
            logMallocError();
          }
        }

      failure:
	if (MB_serialDevice) {
           serialCloseDevice(MB_serialDevice);
           MB_serialDevice = NULL;
        }
	return 0;
}
示例#12
0
static void
setAcknowledgementHandler (BrailleDisplay *brl, AcknowledgementHandler handler) {
  brl->data->acknowledgementHandler = handler;
  startTimePeriod(&brl->data->acknowledgementPeriod, 500);
}