Browse Source

Implemented basic key rate each 660ms

Dashie der otter 1 year ago
parent
commit
3296d53d20
Signed by: Dashie <dashie@sigpipe.me> GPG Key ID: C2D57B325840B755
2 changed files with 27 additions and 2 deletions
  1. 20
    2
      GNS1000_ui/workerkeyboard.cpp
  2. 7
    0
      GNS1000_ui/workerkeyboard.h

+ 20
- 2
GNS1000_ui/workerkeyboard.cpp View File

@@ -40,8 +40,26 @@ void WorkerKeyboard::doLoop() {
40 40
 
41 41
                 int state = digitalRead(mcpRowsPinBase + pinRow); // read state of row
42 42
                 if (state == 0) {
43
-                    qDebug() << "triggered row,col" << pinRow << pinCol << hexaKeys[pinCol][pinRow];
44
-                    emit keyPressed(key(hexaKeys[pinCol][pinRow]));
43
+                    char curKey = hexaKeys[pinCol][pinRow];
44
+
45
+                    if (curKey == lastKey && !keyRepeatDelayTimer->isValid()) {
46
+                        keyRepeatDelayTimer->restart();
47
+                        qDebug() << "restarted keyRepeatDelayTimer";
48
+                    } else if (curKey != lastKey) {
49
+                        qDebug() << "triggered row,col" << pinRow << pinCol << curKey;
50
+                        emit keyPressed(key(curKey));
51
+                        lastKey = curKey;
52
+                        keyRepeatDelayTimer->invalidate(); // invalidate timer, restarting cycle
53
+                    } else {
54
+                        if (keyRepeatDelayTimer->elapsed() >= keyRepeatDelay) {
55
+                            qDebug() << "triggered row,col" << pinRow << pinCol << curKey;
56
+                            emit keyPressed(key(curKey));
57
+                            lastKey = curKey;
58
+                            keyRepeatDelayTimer->invalidate(); // invalidate timer, restarting cycle
59
+                        } else {
60
+                            qDebug() << "supposed to wait" << keyRepeatDelayTimer->isValid() << keyRepeatDelayTimer->elapsed();
61
+                        }
62
+                    }
45 63
                 }
46 64
 
47 65
                 digitalWrite(mcpColsPinBase + pinCol, HIGH); // set HIGH after reading

+ 7
- 0
GNS1000_ui/workerkeyboard.h View File

@@ -3,6 +3,8 @@
3 3
 
4 4
 #include <QObject>
5 5
 #include <QDebug>
6
+#include <QElapsedTimer>
7
+
6 8
 #include <wiringPi.h>
7 9
 #include <mcp23017.h>
8 10
 
@@ -17,6 +19,11 @@ private:
17 19
     void doLoop();
18 20
     QString key(char);
19 21
 
22
+    char lastKey;
23
+
24
+    int keyRepeatDelay = 660;
25
+    QElapsedTimer *keyRepeatDelayTimer = new QElapsedTimer();
26
+
20 27
 protected:
21 28
     const int mcpRowsPinBase = 100;
22 29
     const int mcpRowsAddress = 0x20;

Loading…
Cancel
Save