mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-03 18:24:46 +00:00
Hardcoded pinephone torch
The current code use gstreamer to toggle flashlight, however gstreamer doesn't work in pinephone for now. this MR hardcode pinephone sysfs path for flashlight as a temporary workaround
This commit is contained in:
parent
6097c084f5
commit
407ffc0f4c
1 changed files with 13 additions and 28 deletions
|
|
@ -21,6 +21,9 @@
|
||||||
#include "phonepanel.h"
|
#include "phonepanel.h"
|
||||||
|
|
||||||
#include <qplatformdefs.h>
|
#include <qplatformdefs.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
#include <QDBusPendingReply>
|
#include <QDBusPendingReply>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
|
@ -92,35 +95,17 @@ void PhonePanel::executeCommand(const QString &command)
|
||||||
|
|
||||||
void PhonePanel::toggleTorch()
|
void PhonePanel::toggleTorch()
|
||||||
{
|
{
|
||||||
if (!m_running) {
|
static auto FLASH_SYSFS_PATH = "/sys/devices/platform/led-controller/leds/white:flash/brightness";
|
||||||
gst_init(nullptr, nullptr);
|
int fd = open(FLASH_SYSFS_PATH, O_WRONLY);
|
||||||
// create elements
|
|
||||||
m_source = gst_element_factory_make("droidcamsrc", "source");
|
if (fd < 0) {
|
||||||
m_sink = gst_element_factory_make("fakesink", "sink");
|
qWarning() << "Unable to open file %s" << FLASH_SYSFS_PATH;
|
||||||
m_pipeline = gst_pipeline_new("torch-pipeline");
|
|
||||||
if (!m_pipeline || !m_source || !m_sink) {
|
|
||||||
qDebug() << "Failed to turn on torch: failed to create elements";
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
gst_bin_add_many(GST_BIN(m_pipeline), m_source, m_sink, NULL);
|
|
||||||
if (gst_element_link(m_source, m_sink) != TRUE) {
|
write(fd, m_running ? "0" : "1", 1);
|
||||||
qDebug() << "Failed to turn on torch: failed to link source and sink";
|
close(fd);
|
||||||
g_object_unref(m_pipeline);
|
m_running = !m_running;
|
||||||
return;
|
|
||||||
}
|
|
||||||
g_object_set(m_source, "mode", 2, NULL);
|
|
||||||
g_object_set(m_source, "video-torch", TRUE, NULL);
|
|
||||||
if (gst_element_set_state(m_pipeline, GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE) {
|
|
||||||
qDebug() << "Failed to turn on torch: failed to start pipeline";
|
|
||||||
g_object_unref(m_pipeline);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
m_running = true;
|
|
||||||
} else {
|
|
||||||
gst_element_set_state(m_pipeline, GST_STATE_NULL);
|
|
||||||
gst_object_unref(m_pipeline);
|
|
||||||
m_running = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhonePanel::autoRotate()
|
bool PhonePanel::autoRotate()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue