Skip to content

Commit

Permalink
src: Use GESTURE_enable touchpanel sysfs entries instead of bitmask
Browse files Browse the repository at this point in the history
  • Loading branch information
JamiKettunen committed Nov 26, 2019
1 parent aac5f6b commit 03a4a88
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 31 deletions.
73 changes: 44 additions & 29 deletions src/gesture-enabler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,6 @@ GestureEnabler::GestureEnabler(QObject *parent) : QObject(parent)
{
dconfGestures = new MGConfItem("/apps/onyxgestures/enabled-gestures"); // e.g. ['double_tap', 'flashlight', 'music', 'camera', 'voicecall']

/*
* UpVee_gesture = (buf[0] & BIT0)?1:0; //"V" -- flashlight
* DouSwip_gesture = (buf[0] & BIT1)?1:0;//"||" -- music
* DownVee_gesture = (buf[0] & BIT2)?1:0;//"^" -- voicecall
* LeftVee_gesture = (buf[0] & BIT3)?1:0; //">" -- music
* RightVee_gesture = (buf[0] & BIT4)?1:0;//"<" -- music
* Circle_gesture = (buf[0] & BIT6)?1:0; //"O" -- camera
* DouTap_gesture = (buf[0] & BIT7)?1:0; //double tap
*/

gestureMasks.insert("camera", 0x40);
gestureMasks.insert("music",0x1A);
gestureMasks.insert("flashlight", 0x01);
gestureMasks.insert("double_tap", 0x80);
gestureMasks.insert("voicecall", 0x04);

// Restore previously enabled gestures on daemon startup
handleEnabledGestureChanged();

Expand All @@ -45,26 +29,57 @@ GestureEnabler::GestureEnabler(QObject *parent) : QObject(parent)

void GestureEnabler::handleEnabledGestureChanged()
{
QStringList eg = dconfGestures->value(defGestures).toStringList();
unsigned char mask = 0;
QMap<QString, char>::iterator i;
QStringList enabledGestures = dconfGestures->value(defGestures).toStringList();

qDebug() << "Currently enabled gestures:" << enabledGestures;

QMap<QStringList, QString> newGestureStates;

// Build a list of which gestures to enable/disable in sysfs
for (const auto& gesture : defGestures)
{
QStringList items;
if (gesture.compare("voicecall") == 0)
items << "up_arrow_enable";
else if (gesture.compare("flashlight") == 0)
items << "down_arrow_enable";
else if (gesture.compare("camera") == 0)
items << "letter_o_enable";
else if (gesture.compare("music") == 0)
items << "double_swipe_enable" << "left_arrow_enable" << "right_arrow_enable";
else
items << gesture + "_enable";

bool state = enabledGestures.contains(gesture);

qDebug() << "Currently enabled gestures:" << eg;
newGestureStates.insert(items, (state ? "1" : "0"));
}

for (i = gestureMasks.begin(); i != gestureMasks.end(); ++i)
// Enable/disable all gestures as approperiate
for(auto gestures : newGestureStates.keys())
{
if (eg.contains(i.key()))
mask |= i.value();
// Value to write
QString enabled_value = newGestureStates.value(gestures);

// Go thru all grouped gestures
for (const auto& gesture : gestures)
writeGestureState(gesture, enabled_value);
}
}

QFile outputFile( "/proc/touchpanel/gesture_enable" );
//
// Enable / disable a specific gesture
//

if (outputFile.open(QIODevice::WriteOnly))
void GestureEnabler::writeGestureState(QString gesture_enable, QString enabled_value)
{
QString filePath = "/proc/touchpanel/" + gesture_enable; // e.g. "/proc/touchpanel/double_tap_enable"
QFile outFile(filePath);
if (outFile.open(QIODevice::WriteOnly))
{
QDataStream out(&outputFile);
out << mask;
outputFile.close();
QTextStream stream(&outFile);
stream << enabled_value; // "1" / "0"
}
else
qWarning() << "Failed to write";
qWarning() << ("Failed to write '" + enabled_value + "' to " + filePath + "...");
}
5 changes: 3 additions & 2 deletions src/gesture-enabler.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include <QDebug>
#include <QObject>
#include <QFile>
#include <QDataStream>
#include <QTextStream>
#include <mlite5/MGConfItem>

class GestureEnabler : public QObject
Expand All @@ -25,9 +25,10 @@ public slots:
void handleEnabledGestureChanged();

private:
void writeGestureState(QString gesture_enable, QString enabled_value);

MGConfItem *dconfGestures;
QStringList defGestures = { "double_tap", "voicecall", "camera", "music", "flashlight" };
QMap<QString, char> gestureMasks;
};

#endif // GESTUREENABLER_H

0 comments on commit 03a4a88

Please sign in to comment.