mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-26 14:23:09 +00:00
40 lines
849 B
C++
40 lines
849 B
C++
|
|
/*
|
||
|
|
* SPDX-FileCopyrightText: 2022 by Devin Lin <devin@kde.org>
|
||
|
|
*
|
||
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include "flashlightutil.h"
|
||
|
|
|
||
|
|
#include <fcntl.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
|
||
|
|
#include <QDebug>
|
||
|
|
|
||
|
|
FlashlightUtil::FlashlightUtil(QObject *parent)
|
||
|
|
: QObject{parent}
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
void FlashlightUtil::toggleTorch()
|
||
|
|
{
|
||
|
|
// FIXME this is hardcoded to the PinePhone for now
|
||
|
|
static auto FLASH_SYSFS_PATH = "/sys/devices/platform/led-controller/leds/white:flash/brightness";
|
||
|
|
int fd = open(FLASH_SYSFS_PATH, O_WRONLY);
|
||
|
|
|
||
|
|
if (fd < 0) {
|
||
|
|
qWarning() << "Unable to open file %s" << FLASH_SYSFS_PATH;
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
write(fd, m_torchEnabled ? "0" : "1", 1);
|
||
|
|
close(fd);
|
||
|
|
m_torchEnabled = !m_torchEnabled;
|
||
|
|
Q_EMIT torchChanged(m_torchEnabled);
|
||
|
|
}
|
||
|
|
|
||
|
|
bool FlashlightUtil::torchEnabled() const
|
||
|
|
{
|
||
|
|
return m_torchEnabled;
|
||
|
|
}
|