[-]
[+]
|
Changed |
_service:tar_git:onyx-flashlight.spec
|
|
[-]
[+]
|
Changed |
_service
^
|
@@ -6,7 +6,7 @@
<service name="tar_git">
<param name="url">https://github.com/kimmoli/onyx-flashlight.git</param>
<param name="branch">master</param>
- <param name="revision">8183ae5c19961cf723ba75796134050da49998cf</param>
+ <param name="revision">78193902327b4811692fc6abdc930c1b8ae79146</param>
<param name="token"/>
<param name="debian">N</param>
<param name="dumb">N</param>
|
[-]
[+]
|
Changed |
_service:tar_git:onyx-flashlight-0.0.5.tar.bz2/onyx-flashlight.pro
^
|
@@ -5,6 +5,7 @@
TARGET = onyx-flashlight
CONFIG += sailfishapp
+QT += dbus
DEFINES += "APPVERSION=\\\"$${SPECVERSION}\\\""
|
[-]
[+]
|
Changed |
_service:tar_git:onyx-flashlight-0.0.5.tar.bz2/qml/pages/Flashlight.qml
^
|
@@ -50,6 +50,7 @@
}
Slider
{
+ visible: Torch.hasBrightness
width: parent.width - 2*Theme.paddingLarge
anchors.horizontalCenter: parent.horizontalCenter
label: "Brightness"
@@ -72,6 +73,14 @@
stepSize: 1
onValueChanged: Torch.interval = value
}
+ Label
+ {
+ visible: !Torch.deviceSupported
+ width: parent.width - Theme.paddingLarge
+ anchors.horizontalCenter: parent.horizontalCenter
+ wrapMode: Text.Wrap
+ text: "Your device " + Torch.deviceName + " might not be supported."
+ }
}
}
}
|
[-]
[+]
|
Changed |
_service:tar_git:onyx-flashlight-0.0.5.tar.bz2/src/torch.cpp
^
|
@@ -2,10 +2,17 @@
#include <sys/ioctl.h>
#include <fcntl.h>
#include <unistd.h>
+#include <QDebug>
Torch::Torch(QObject *parent) :
QObject(parent)
{
+ m_deviceName = "";
+ m_deviceSupported = false;
+ m_hasBrightness = true;
+ m_controlPath = "/sys/class/leds/led:flash_torch/brightness";
+
+ checkDevice();
strobotimer = new QTimer();
strobotimer->setSingleShot(false);
@@ -75,6 +82,36 @@
return m_stroboisOn;
}
+void Torch::setHasBrightness(bool has)
+{
+ m_hasBrightness = has;
+}
+
+bool Torch::getHasBrightness()
+{
+ return m_hasBrightness;
+}
+
+bool Torch::getDeviceSupported()
+{
+ return m_deviceSupported;
+}
+
+void Torch::setDeviceSupported(bool supported)
+{
+ m_deviceSupported = supported;
+}
+
+QString Torch::getDeviceName()
+{
+ return m_deviceName;
+}
+
+void Torch::setDeviceName(QString name)
+{
+ m_deviceName = name;
+}
+
void Torch::setBrightness(int val)
{
m_brightness = val;
@@ -106,7 +143,7 @@
void Torch::p_brightness(int level)
{
- int fd = open("/sys/class/leds/led:flash_torch/brightness", O_WRONLY);
+ int fd = open(m_controlPath.toLocal8Bit().constData(), O_WRONLY);
int tmp;
Q_UNUSED(tmp)
@@ -122,3 +159,76 @@
}
QThread::msleep(10);
}
+
+void Torch::checkDevice()
+{
+ int res = false;
+
+ if (!QDBusConnection::systemBus().isConnected())
+ {
+ qDebug() << "Cannot connect to the D-Bus systemBus" << QDBusConnection::systemBus().lastError().message();
+ return;
+ }
+
+
+ QDBusInterface ssuCall("org.nemo.ssu", "/org/nemo/ssu", "org.nemo.ssu", QDBusConnection::systemBus());
+ ssuCall.setTimeout(1000);
+
+ QList<QVariant> args;
+ args.append(2);
+
+ QDBusMessage ssuCallReply = ssuCall.callWithArgumentList(QDBus::Block, "displayName", args);
+
+ if (ssuCallReply.type() == QDBusMessage::ErrorMessage)
+ {
+ qDebug() << "Error" << ssuCallReply.errorMessage();
+ return;
+ }
+
+ QList<QVariant> outArgs = ssuCallReply.arguments();
+ if (outArgs.count() == 0)
+ {
+ qDebug() << "Reply is epmty";
+ return;
+ }
+
+ qDebug() << "device name is" << outArgs.at(0).toString();
+
+ m_deviceName = outArgs.at(0).toString();
+
+ if (m_deviceName == "JP-1301") /* The one and only original Jolla phone */
+ {
+ m_hasBrightness = false;
+ m_controlPath = "/sys/kernel/debug/flash_adp1650/mode";
+
+ res = true;
+ }
+ else if (m_deviceName == "onyx") /* OneplusX */
+ {
+ m_hasBrightness = true;
+ m_controlPath = "/sys/class/leds/led:flash_torch/brightness";
+
+ res = true;
+ }
+ else if (m_deviceName == "fp2-sibon") /* Fairphone 2 */
+ {
+ m_hasBrightness = true;
+ m_controlPath = "/sys/class/leds/led:flash_torch/brightness";
+
+ res = true;
+ }
+ else if (m_deviceName == "JP-1601") /* Jolla C */
+ {
+ m_hasBrightness = true;
+ m_controlPath = "/sys/class/leds/torch-light0/brightness";
+
+ res = true;
+ }
+
+ emit deviceNameChanged(m_deviceName);
+
+ m_deviceSupported = res;
+ emit deviceSupportedChanged(m_deviceSupported);
+
+ emit hasBrightnessChanged(m_hasBrightness);
+}
|
[-]
[+]
|
Changed |
_service:tar_git:onyx-flashlight-0.0.5.tar.bz2/src/torch.h
^
|
@@ -4,6 +4,8 @@
#include <QObject>
#include <QTimer>
#include <QThread>
+#include <QDBusConnection>
+#include <QDBusInterface>
class Torch : public QObject
{
@@ -12,6 +14,10 @@
Q_PROPERTY(int interval MEMBER m_interval WRITE setIntervall NOTIFY intervalChanged)
Q_PROPERTY(bool torchState READ getTorchState WRITE setTorchState NOTIFY torchStateChanged)
Q_PROPERTY(bool stroboState READ getStroboState WRITE setStroboState NOTIFY stroboStateChanged)
+ Q_PROPERTY(bool hasBrightness READ getHasBrightness WRITE setHasBrightness NOTIFY hasBrightnessChanged)
+ Q_PROPERTY(bool deviceSupported READ getDeviceSupported WRITE setDeviceSupported NOTIFY deviceSupportedChanged)
+ Q_PROPERTY(QString deviceName READ getDeviceName WRITE setDeviceName NOTIFY deviceNameChanged)
+
public:
explicit Torch(QObject *parent = 0);
@@ -21,12 +27,23 @@
bool getStroboState();
void setBrightness(int);
void setIntervall(int);
+ bool getHasBrightness();
+ void setHasBrightness(bool);
+ QString getDeviceName();
+ void setDeviceName(QString);
+ bool getDeviceSupported();
+ void setDeviceSupported(bool);
+
+ void checkDevice();
signals:
void brightnessChanged(int nBrightness);
void intervalChanged(int nInterval);
void stroboStateChanged(bool state);
void torchStateChanged(bool state);
+ void hasBrightnessChanged(bool state);
+ void deviceSupportedChanged(bool state);
+ void deviceNameChanged(QString name);
private slots:
void p_strobotimerTimeout();
@@ -37,11 +54,15 @@
int m_interval;
bool m_stroboisOn;
int m_brightness;
-
+ bool m_hasBrightness;
+ QString m_controlPath;
QTimer *strobotimer;
bool strobostate;
int lastBrightness;
+
+ bool m_deviceSupported;
+ QString m_deviceName;
};
#endif // TORCH_H
|