Flashlight.cpp Example File
SensorDemo/src/Flashlight.cpp
#include "Flashlight.hpp"
#include <QDebug>
Flashlight::Flashlight(QObject * parent)
: QObject(parent)
, m_enabled(false)
{
const camera_error_t error = camera_open(CAMERA_UNIT_REAR, CAMERA_MODE_PREAD | CAMERA_MODE_PWRITE, &m_camera);
if (CAMERA_EOK != error) {
qDebug() << "Failed to open camera";
}
}
Flashlight::~Flashlight()
{
camera_close(m_camera);
}
void Flashlight::setEnabled(bool enabled)
{
if (m_enabled == enabled)
return;
m_enabled = enabled;
const camera_videolightmode_t mode = (m_enabled ? CAMERA_VIDEOLIGHT_ON : CAMERA_VIDEOLIGHT_OFF);
const camera_error_t error = camera_config_videolight(m_camera, mode);
if (CAMERA_EOK != error) {
qDebug() << "Failed to toggle the front camera video light";
}
emit enabledChanged(m_enabled);
}
bool Flashlight::enabled() const
{
return m_enabled;
}