lib/keypad/Keypad.cpp

changeset 26
86f099bda525
parent 24
b43536c064f6
child 28
424d792fea4f
--- a/lib/keypad/Keypad.cpp	Sun Aug 30 22:53:15 2020 +0200
+++ b/lib/keypad/Keypad.cpp	Thu Oct 15 01:11:03 2020 +0200
@@ -2,9 +2,12 @@
 #include "Keypad.h"
 
 
-Keypad::Keypad(uint8_t nRows, DigitalIn rows[],
-	       uint8_t nColumns, DigitalOut cols[],
-	       int debounce_ms):
+Keypad::Keypad(
+    uint8_t nRows,
+    DigitalIn rows[],
+    uint8_t nColumns,
+    DigitalOut cols[],
+    int debounce_ms):
   _rows(),
   _columns(),
   _debounce(debounce_ms),
@@ -13,12 +16,14 @@
   _ncols(nColumns)
 {
   printf("Setup Keypad: %dx%d\r\n", nColumns, nRows);
-  for(uint8_t c=0; c<nColumns; c++) {
+  for(uint8_t c=0; c<nColumns; c++)
+	{
     _columns.push_back(cols[c]);
     _columns[c].write(0);
   }
 
-  for(uint8_t r=0; r<nRows; r++) {
+  for(uint8_t r=0; r<nRows; r++)
+	{
     _rows.push_back(rows[r]);
     _rows[r].mode(PullDown);
   }
@@ -37,29 +42,31 @@
 
   for (row=0; row<(_ncols*_nrows); row++)
     _keys[row] = 0;
-  while(_started) {
+
+  while(_started)
+  {
     _columns[col].write(1);
     Thread::wait(5);
     for(row=0; row<_nrows; row++)
+    {
+      if (_rows[row].read())
       {
-	if (_rows[row].read())
-	  {
-	    if (_keys[row + _nrows*col] < 2)
-	      {
-		_keys[row + _nrows*col]++;
-		if ((_keys[row + _nrows*col] == 2) && _kp_callback)
-		  _kp_callback.call(row, col);
-	      }
-	  }
-	else
-	  {
-	    if (_keys[row + _nrows*col] > 0)
-	      {
-		_keys[row + _nrows*col]--;
-		if ((_keys[row + _nrows*col] == 0) && _kr_callback)
-		  _kr_callback.call(row, col);
-	      }
-	  }
+        if (_keys[row + _nrows*col] < 2)
+        {
+          _keys[row + _nrows*col]++;
+          if ((_keys[row + _nrows*col] == 2) && _kp_callback)
+            _kp_callback.call(row, col);
+        }
+      }
+      else
+      {
+        if (_keys[row + _nrows*col] > 0)
+        {
+          _keys[row + _nrows*col]--;
+          if ((_keys[row + _nrows*col] == 0) && _kr_callback)
+            _kr_callback.call(row, col);
+        }
+      }
       }
     _columns[col].write(0);
     col = (col+1) % _ncols;
@@ -68,7 +75,7 @@
 }
 
 void Keypad::attach(const keyevent_callback_t& kp_callback,
-		      const keyevent_callback_t& kr_callback)
+										const keyevent_callback_t& kr_callback)
 {
   _kp_callback = kp_callback;
   _kr_callback = kr_callback;

mercurial