예제 #1
0
void BbCameraFlashControl::setFlashMode(QCameraExposure::FlashModes mode)
{
    if (m_flashMode == mode)
        return;

    if (m_session->status() != QCamera::ActiveStatus) // can only be changed when viewfinder is active
        return;

    if (m_flashMode == QCameraExposure::FlashVideoLight) {
        const camera_error_t result = camera_config_videolight(m_session->handle(), CAMERA_VIDEOLIGHT_OFF);
        if (result != CAMERA_EOK)
            qWarning() << "Unable to switch off video light:" << result;
    }

    m_flashMode = mode;

    if (m_flashMode == QCameraExposure::FlashVideoLight) {
        const camera_error_t result = camera_config_videolight(m_session->handle(), CAMERA_VIDEOLIGHT_ON);
        if (result != CAMERA_EOK)
            qWarning() << "Unable to switch on video light:" << result;
    } else {
        camera_flashmode_t flashMode = CAMERA_FLASH_AUTO;

        if (m_flashMode.testFlag(QCameraExposure::FlashAuto)) flashMode = CAMERA_FLASH_AUTO;
        else if (mode.testFlag(QCameraExposure::FlashOff)) flashMode = CAMERA_FLASH_OFF;
        else if (mode.testFlag(QCameraExposure::FlashOn)) flashMode = CAMERA_FLASH_ON;

        const camera_error_t result = camera_config_flash(m_session->handle(), flashMode);
        if (result != CAMERA_EOK)
            qWarning() << "Unable to configure flash:" << result;
    }
}
예제 #2
0
void Flashlight::setEnabled(bool newState)
{
    Q_D(Flashlight);

    if (d->camHandle == CAMERA_HANDLE_INVALID) {
        qDebug("Flashlight error: invalid camera handle");
        return;
    }

    auto lightMode = CAMERA_VIDEOLIGHT_OFF;

    if (newState) {
        lightMode = CAMERA_VIDEOLIGHT_ON;
    }

    auto err = camera_config_videolight(d->camHandle, lightMode);

    d->lightOn = !d->lightOn;
    if (err != CAMERA_EOK) {
        auto action = "disabling";

        if (newState) {
            action = "enabling";
        }
        qDebug("Flashlight error: failed to %s flashlight: %s", action, errorStr(err).c_str());
    }
}