コード例 #1
0
ファイル: paddles.cpp プロジェクト: cmosher01/Epple-II
void Paddles::tryStartPaddleTimers()
{
	int x, y;
	SDL_GetMouseState(&x,&y);

	double pMin = 0;
	double pMax = 500;
	x = (int)((x-pMin)/(pMax-pMin)*PADDLE_CYCLES+.5);
	y = (int)((y-pMin)/(pMax-pMin)*PADDLE_CYCLES+.5);

	if (isTimedOut(0))
		this->rTick[0] = x;
	if (isTimedOut(1))
		this->rTick[1] = y;

	/*
		Here we emulate having 4700 ohm across pins 7 and 1
		of the game controller, and a 47Kohm resistor acros
		pins 11 and 1, to give cheap real-time clocks at
		paddles 2 and 3. Paddle 2 is the 100 microsecond reference,
		and paddle 3 is the 1 millisecond reference. This is
		described in U.A.2, p. 7-33.
	*/
	if (isTimedOut(2))
		this->rTick[2] = E2Const::AVG_CPU_HZ/10000; // was 90, but why?
	if (isTimedOut(3))
		this->rTick[3] = E2Const::AVG_CPU_HZ/1000;
}
コード例 #2
0
//------------------------------------------------------------------------------
// wait for card to go not busy
bool SdSpiCard::waitNotBusy(uint16_t timeoutMS) {
  uint16_t t0 = curTimeMS();
#if WDT_YIELD_TIME_MICROS
  // Call isTimedOut first to insure yield is called.
  while (!isTimedOut(t0, timeoutMS)) {
    if (spiReceive() == 0XFF) {
      return true;
    }
  }
  return false;
#else  // WDT_YIELD_TIME_MICROS
  // Check not busy first since yield is not called in isTimedOut.
  while (spiReceive() != 0XFF) {
    if (isTimedOut(t0, timeoutMS)) {
      return false;
    }
  }
  return true;
#endif  // WDT_YIELD_TIME_MICROS
}
コード例 #3
0
TransferReceiver::ResultCode TransferReceiver::addFrame(const RxFrame& frame, TransferBufferAccessor& tba)
{
    if ((frame.getMonotonicTimestamp().isZero()) ||
        (frame.getMonotonicTimestamp() < prev_transfer_ts_) ||
        (frame.getMonotonicTimestamp() < this_transfer_ts_))
    {
        return ResultNotComplete;
    }

    const bool not_initialized = !isInitialized();
    const bool receiver_timed_out = isTimedOut(frame.getMonotonicTimestamp());
    const bool same_iface = frame.getIfaceIndex() == iface_index_;
    const bool first_fame = frame.isFirst();
    const TidRelation tid_rel = getTidRelation(frame);
    const bool iface_timed_out =
        (frame.getMonotonicTimestamp() - this_transfer_ts_).toUSec() > (int64_t(transfer_interval_usec_) * 2);

    // FSM, the hard way
    const bool need_restart =
        (not_initialized) ||
        (receiver_timed_out) ||
        (same_iface && first_fame && (tid_rel == TidFuture)) ||
        (iface_timed_out && first_fame && (tid_rel == TidFuture));

    if (need_restart)
    {
        const bool error = !not_initialized && !receiver_timed_out;
        if (error)
        {
            registerError();
        }
        UAVCAN_TRACE("TransferReceiver",
                     "Restart [not_inited=%i, iface_timeout=%i, recv_timeout=%i, same_iface=%i, first_frame=%i, tid_rel=%i], %s",
                     int(not_initialized), int(iface_timed_out), int(receiver_timed_out), int(same_iface),
                     int(first_fame), int(tid_rel), frame.toString().c_str());
        tba.remove();
        iface_index_ = frame.getIfaceIndex();
        tid_ = frame.getTransferID();
        next_frame_index_ = 0;
        buffer_write_pos_ = 0;
        this_transfer_crc_ = 0;
        if (!first_fame)
        {
            tid_.increment();
            return ResultNotComplete;
        }
    }

    if (!validate(frame))
    {
        return ResultNotComplete;
    }
    return receive(frame, tba);
}
コード例 #4
0
ファイル: LEDSensor.cpp プロジェクト: canadaduane/LEDSensor
void LEDSensor::measure() {
  if (mStartTime == -1 || isTimedOut()) {
    charge();
    delay(1); // charge it up
    discharge();

    mStartTime = millis();
  } else if (isDischarged()) {
    mTimeDelta = millis() - mStartTime;
    mStartTime = -1;
  }
}
コード例 #5
0
ファイル: UDPInternalConnection.cpp プロジェクト: SX91/NetMan
ByteArray UDPInternalConnection::receiveImpl(unsigned long size)
{
  if (readyForRead() == 0) {

    if (!isPending())
      setPending();
    else
      throw netman::SockConnectionError("Already pending");

    std::unique_lock<std::mutex> lock(syncMutex);
    waitVar.wait(lock, [&] {return !isPending();});

    if (isTimedOut()) {
      setIdle();
      throw netman::SockRecieveFailed("Operation timeout");
    } else
      setIdle();
  }

  return readBuffer();
}
コード例 #6
0
//------------------------------------------------------------------------------
bool SdSpiCard::readData(uint8_t* dst, size_t count) {
#if USE_SD_CRC
  uint16_t crc;
#endif  // USE_SD_CRC
  // wait for start block token
  uint16_t t0 = curTimeMS();
  while ((m_status = spiReceive()) == 0XFF) {
    if (isTimedOut(t0, SD_READ_TIMEOUT)) {
      error(SD_CARD_ERROR_READ_TIMEOUT);
      goto fail;
    }
  }
  if (m_status != DATA_START_BLOCK) {
    error(SD_CARD_ERROR_READ);
    goto fail;
  }
  // transfer data
  if ((m_status = spiReceive(dst, count))) {
    error(SD_CARD_ERROR_DMA);
    goto fail;
  }

#if USE_SD_CRC
  // get crc
  crc = (spiReceive() << 8) | spiReceive();
  if (crc != CRC_CCITT(dst, count)) {
    error(SD_CARD_ERROR_READ_CRC);
    goto fail;
  }
#else
  // discard crc
  spiReceive();
  spiReceive();
#endif  // USE_SD_CRC
  return true;

fail:
  spiStop();
  return false;
}
コード例 #7
0
bool EnumerationContext::isTimedOut()
{
    Uint64 currentTime = System::getCurrentTimeUsec();
    return isTimedOut(currentTime);
}
コード例 #8
0
//==============================================================================
// SdSpiCard member functions
//------------------------------------------------------------------------------
bool SdSpiCard::begin(SdSpiDriver* spi, uint8_t csPin, SPISettings settings) {
  m_spiActive = false;
  m_errorCode = SD_CARD_ERROR_NONE;
  m_type = 0;
  m_spiDriver = spi;
  uint16_t t0 = curTimeMS();
  uint32_t arg;

  m_spiDriver->begin(csPin);
  m_spiDriver->setSpiSettings(SD_SCK_HZ(250000));
  spiStart();

  // must supply min of 74 clock cycles with CS high.
  spiUnselect();
  for (uint8_t i = 0; i < 10; i++) {
    spiSend(0XFF);
  }
  spiSelect();
  // command to go idle in SPI mode
  while (cardCommand(CMD0, 0) != R1_IDLE_STATE) {
    if (isTimedOut(t0, SD_INIT_TIMEOUT)) {
      error(SD_CARD_ERROR_CMD0);
      goto fail;
    }
  }
#if USE_SD_CRC
  if (cardCommand(CMD59, 1) != R1_IDLE_STATE) {
    error(SD_CARD_ERROR_CMD59);
    goto fail;
  }
#endif  // USE_SD_CRC
  // check SD version
  while (1) {
    if (cardCommand(CMD8, 0x1AA) == (R1_ILLEGAL_COMMAND | R1_IDLE_STATE)) {
      type(SD_CARD_TYPE_SD1);
      break;
    }
    for (uint8_t i = 0; i < 4; i++) {
      m_status = spiReceive();
    }
    if (m_status == 0XAA) {
      type(SD_CARD_TYPE_SD2);
      break;
    }
    if (isTimedOut(t0, SD_INIT_TIMEOUT)) {
      error(SD_CARD_ERROR_CMD8);
      goto fail;
    }
  }
  // initialize card and send host supports SDHC if SD2
  arg = type() == SD_CARD_TYPE_SD2 ? 0X40000000 : 0;

  while (cardAcmd(ACMD41, arg) != R1_READY_STATE) {
    // check for timeout
    if (isTimedOut(t0, SD_INIT_TIMEOUT)) {
      error(SD_CARD_ERROR_ACMD41);
      goto fail;
    }
  }
  // if SD2 read OCR register to check for SDHC card
  if (type() == SD_CARD_TYPE_SD2) {
    if (cardCommand(CMD58, 0)) {
      error(SD_CARD_ERROR_CMD58);
      goto fail;
    }
    if ((spiReceive() & 0XC0) == 0XC0) {
      type(SD_CARD_TYPE_SDHC);
    }
    // Discard rest of ocr - contains allowed voltage range.
    for (uint8_t i = 0; i < 3; i++) {
      spiReceive();
    }
  }
  spiStop();
  m_spiDriver->setSpiSettings(settings);
  return true;

fail:
  spiStop();
  return false;
}
コード例 #9
0
ファイル: TurnLeft.cpp プロジェクト: PeterMitrano/CommanDuino
bool TurnLeft::isFinished(){
  return isTimedOut();
}
コード例 #10
0
ファイル: Blink.cpp プロジェクト: PeterMitrano/CommanDuino
bool Blink::isFinished(){
  return isTimedOut();
}