uint8_t I2C_Write_Bytes(I2C_t device, uint8_t address, uint8_t *data, uint8_t length) { _send_start(device.port); _send_address(device.port, address, 0); int i = 0; for (; i < length; i++) { _send_byte(device.port, data[i]); } return i; }
uint8_t I2C_Read_Bytes(I2C_t device, uint8_t address, uint8_t *data, uint8_t length) { _send_start(device.port); _send_address(device.port, address, 0x01); int i = 0; for (; i < length; i++) { data[i] = _recv_byte(device.port); } return i; }
std::function<void(void)> Sender::Impl::_make_worker() { return [&]() { if (!m_nSockWorker) return; m_pPlug->log.info("Starting sender thread"); m_bStarted = true; Status prev = m_status; const int nSendThresholdFrames = (m_pPlug->nMTU - 100)/get_bytes_per_frame(); while (m_status & Sender::usRunning) { { std::lock_guard<std::mutex> lock(m_mutex); try { if (prev == Sender::usRunning && (m_status == Sender::usPaused || m_status == Sender::usUnderrun)) _send_pause(); else if ((prev == Sender::usPaused || prev == Sender::usUnderrun) && m_status == Sender::usRunning) _send_start(); if (!m_queue.empty()) { while (!m_queue.empty() && ( m_status != Sender::usRunning || m_nFramesQueued >= nSendThresholdFrames)) _send_data(); } else if (m_bPrepared && m_status == Sender::usStopping && _estimate_frames() >= m_nPointer) { _send_stop(); m_status = Sender::usStopped; continue; } if (_get_delay() < (snd_pcm_sframes_t)m_pPlug->get_buffer_size()) { // Don't wake up the other party unless there is buffer space available. char buf[1] = {0}; write(m_nSockWorker, buf, 1); } else if (m_status == Sender::usUnderrun) { // Resume if buffer filled up after underrun. m_pPlug->log.info("Resuming after XRUN"); m_status = Sender::usRunning; m_startTime = Clock::now(); } } catch (std::exception &e) { m_pPlug->log.error(e.what()); } prev = m_status; } std::this_thread::sleep_for(std::chrono::milliseconds(m_pPlug->nSendPeriod)); } }; }
void I2C_Start(I2C_t device) { _send_start(device.port); }
uint8_t I2C_Write_Byte(I2C_t device, uint8_t address, uint8_t data) { _send_start(device.port); _send_address(device.port, address, 0); return _send_byte(device.port, data); }
uint8_t I2C_Read_Byte(I2C_t device, uint8_t address) { _send_start(device.port); _send_address(device.port, address, 0x01); return _recv_byte(device.port); }