예제 #1
0
bool CameraOutV4L2::init(int streamIndex, const AkCaps &caps)
{
    if (!caps)
        return false;

    this->m_deviceFile.setFileName(this->m_device);

    if (!this->m_deviceFile.open(QIODevice::WriteOnly)) {
        emit this->error(QString("Unable to open V4L2 device %1").arg(this->m_device));

        return false;
    }

    if (fcntl(this->m_deviceFile.handle(), F_SETFL, O_NONBLOCK) < 0) {
        emit this->error(QString("Can't set V4L2 device %1 in blocking mode").arg(this->m_device));

        return false;
    }

    v4l2_format fmt;
    memset(&fmt, 0, sizeof(v4l2_format));
    fmt.type = V4L2_BUF_TYPE_VIDEO_OUTPUT;

    if (this->xioctl(this->m_deviceFile.handle(), VIDIOC_G_FMT, &fmt) < 0) {
        emit this->error("Can't read default format");
        this->m_deviceFile.close();

        return false;
    }

    AkVideoCaps videoCaps(caps);
    fmt.fmt.pix.width = __u32(videoCaps.width());
    fmt.fmt.pix.height = __u32(videoCaps.height());
    fmt.fmt.pix.pixelformat = ffToV4L2->value(videoCaps.format());
    fmt.fmt.pix.sizeimage = __u32(videoCaps.pictureSize());

    if (this->xioctl(this->m_deviceFile.handle(), VIDIOC_S_FMT, &fmt) < 0) {
        emit this->error("Can't set format");
        this->m_deviceFile.close();

        return false;
    }

    this->m_streamIndex = streamIndex;
    this->m_caps = caps;

    return true;
}
예제 #2
0
int LedSpiDevice::writeBytes(const unsigned size, const uint8_t * data)
{
	if (mFid < 0)
	{
		return -1;
	}

	spi.tx_buf = __u64(data);
	spi.len    = __u32(size);

	int retVal = ioctl(mFid, SPI_IOC_MESSAGE(1), &spi);

	if (retVal == 0 && mLatchTime_ns > 0)
	{
		// The 'latch' time for latching the shifted-value into the leds
		timespec latchTime;
		latchTime.tv_sec  = 0;
		latchTime.tv_nsec = mLatchTime_ns;

		// Sleep to latch the leds (only if write succesfull)
		nanosleep(&latchTime, NULL);
	}

	return retVal;
}
예제 #3
0
int ProviderSpi::writeBytes(const unsigned size, const uint8_t * data)
{
	if (_fid < 0)
	{
		return -1;
	}

	_spi.tx_buf = __u64(data);
	_spi.len    = __u32(size);

	if (_spiDataInvert)
	{
		uint8_t * newdata = (uint8_t *)malloc(size);
		for (unsigned i = 0; i<size; i++) {
			newdata[i] = data[i] ^ 0xff;
		}
		_spi.tx_buf = __u64(newdata);
	}

	int retVal = ioctl(_fid, SPI_IOC_MESSAGE(1), &_spi);
	ErrorIf((retVal < 0), _log, "SPI failed to write. errno: %d, %s", errno,  strerror(errno) );

	return retVal;
}