Hiroh Satoh / keyboard Featured

Dependencies:   BLE_API mbed-dev nRF51822

Revision:
9:d1daefbf1fbd
Parent:
8:d684faf04c9a
Child:
10:1aed2481a743
--- a/main.cpp	Thu Jul 21 08:45:27 2016 +0900
+++ b/main.cpp	Thu Jul 21 21:33:56 2016 +0900
@@ -157,9 +157,12 @@
 static uint8_t keysA[COLS];
 static uint8_t keysB[COLS];
 static bool state = 0;
+// delay for interrupt
+static int8_t pollCount = 0;
 
 void buttonIntCallback() {
 	// just for wakeup
+	pollCount = 100;
 }
 
 int main(void) {
@@ -181,15 +184,17 @@
 
 	HIDController::init();
 	while (1) {
-		if (!buttonIntIn.read()) {
+		if (pollCount-- > 0) {
 			uint8_t (&keysCurr)[COLS] = state ? keysA : keysB;
 			uint8_t (&keysPrev)[COLS] = state ? keysB : keysA;
 
-			keyboardMatrixController.disableInterrupt();
 			keyboardMatrixController.scanKeyboard(keysCurr);
 
+			bool queue = false;
+
 			for (int col = 0; col < COLS; col++) {
 				uint8_t changed = keysPrev[col] ^ keysCurr[col];
+				if (changed) queue = true;
 				for (int row = 0; row < ROWS; row++) {
 					if (changed & (1<<row)) {
 						bool pressed = keysCurr[col] & (1<<row);
@@ -200,8 +205,8 @@
 			}
 			state = !state;
 
-			// XXX
-			keyboardMatrixController.enableInterrupt();
+			if (queue) HIDController::queueCurrentReportData();
+
 			wait_ms(5);
 		} else {
 			HIDController::process();