Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: BLE_API BLE_HID mbed nRF51822
Fork of BLENano_HID by
Revision 2:0218f7d82bfa, committed 2018-08-26
- Comitter:
- shervinemami
- Date:
- Sun Aug 26 11:18:26 2018 +0000
- Parent:
- 1:2749e6ff50ce
- Commit message:
- Change the finger behaviours back to regular behaviour
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Sun Aug 26 10:51:20 2018 +0000
+++ b/main.cpp Sun Aug 26 11:18:26 2018 +0000
@@ -220,32 +220,32 @@
float fing4 = finger4.read();
float batt = battery.read();
- // If a finger was pressed and now has been released, send the keyUp event soon after.
+ // If a finger was pressed and now has been released, possibly send another event.
if (press_keyup[1] && fing1 < FINGER1_RELEASE) {
press_keyup[1] = false; // Clear the flag
- //kbdServicePtr->keyUpCode();
- HID_DEBUG("sent key up for 1.\n\r");
+ LOG("key up for 1.\n\r");
+
+ // Nothing needs to be done for releasing a mouse click.
}
if (press_keyup[2] && fing2 < FINGER2_RELEASE) {
press_keyup[2] = false; // Clear the flag
- //send_keypress(FING2UP_KEYCODE, 2);
- HID_DEBUG("sent final key down for 2.\n\r");
- ble.waitForEvent(); // Add a slight delay
- //wait(0.1); // Add a slight delay
- //ble.waitForEvent(); // Add a slight delay
- //kbdServicePtr->keyUpCode();
- HID_DEBUG("sent final key up for 2.\n\r");
- press_keyup[2] = false; // Clear the flag
+ LOG("key up for 2.\n\r");
+
+ // Nothing needs to be done for releasing a mouse click.
}
if (press_keyup[3] && fing3 < FINGER3_RELEASE) {
press_keyup[3] = false; // Clear the flag
- //kbdServicePtr->keyUpCode();
- HID_DEBUG("sent key up for 3.\n\r");
+ LOG("key up for 3.\n\r");
+
+ // Stop the scrolling.
+ mouseServicePtr->setSpeed(0, 0, 0);
}
if (press_keyup[4] && fing4 < FINGER4_RELEASE) {
press_keyup[4] = false; // Clear the flag
- //kbdServicePtr->keyUpCode();
- HID_DEBUG("sent key up for 4.\n\r");
+ LOG("key up for 4.\n\r");
+
+ // Stop the scrolling.
+ mouseServicePtr->setSpeed(0, 0, 0);
}
@@ -288,47 +288,36 @@
// Check if a finger was pressed
if (fing1 > FINGER1_PRESS && !press_keyup[1]) {
- //send_keypress(FING1_KEYCODE, 1);
- HID_DEBUG("sent keypress %d for 1.\n\r");
- //counter2+=20;
- //LOG("%d\n\r", counter2);
+ LOG("finger 1.\n\r");
+ press_keyup[1] = true; // Don't trigger this event again until the finger has been released.
+
+ mouseServicePtr->setButton(MOUSE_BUTTON_LEFT, BUTTON_DOWN);
+ wait(0.05); // Add a slight delay
+ ble.waitForEvent(); // Add a slight delay
+ mouseServicePtr->setButton(MOUSE_BUTTON_LEFT, BUTTON_UP);
}
if (fing2 > FINGER2_PRESS && !press_keyup[2]) {
- //send_keypress(FING2DOWN_KEYCODE, 2);
- HID_DEBUG("sent keypress %d for 2.\n\r");
- // Finger 2 is treated differently. We want to be able to hold down finger 2
- // Without causing repeated keystrokes, so we will send an up press straight after the down press,
- // and a different key down and up when the fingure is released, so the client software can
- // figure out the duration that it was held for.
+ LOG("finger 2.\n\r");
+ press_keyup[2] = true; // Don't trigger this event again until the finger has been released.
+
+ mouseServicePtr->setButton(MOUSE_BUTTON_RIGHT, BUTTON_DOWN);
+ wait(0.05); // Add a slight delay
ble.waitForEvent(); // Add a slight delay
- //wait(0.1); // Add a slight delay
- //ble.waitForEvent(); // Add a slight delay
- //kbdServicePtr->keyUpCode();
- HID_DEBUG("sent initial key up for 2.\n\r");
+ mouseServicePtr->setButton(MOUSE_BUTTON_RIGHT, BUTTON_UP);
}
if (fing3 > FINGER3_PRESS && !press_keyup[3]) {
- //send_keypress(FING3_KEYCODE, 3);
- HID_DEBUG("sent keypress %d for 3.\n\r");
- //counter2++;
- //send_keypress(counter2, 3);
- //LOG("%d\n\r", counter2);
+ LOG("finger 3.\n\r");
+ press_keyup[3] = true; // Don't trigger this event again until the finger has been released.
- LOG("send scroll down\n\r");
+ // Start scrolling down, until the user releases this finger.
mouseServicePtr->setSpeed(0, 0, 1);
-
- wait(0.05); // Add a slight delay
- ble.waitForEvent(); // Add a slight delay
-
- mouseServicePtr->setSpeed(0, 0, 0);
-
}
if (fing4 > FINGER4_PRESS && !press_keyup[4]) {
- //send_keypress(FING4_KEYCODE, 4);
- HID_DEBUG("sent keypress %d for 4.\n\r");
- //counter2--;
- //send_keypress(counter2, 4);
- //LOG("%d\n\r", counter2);
-
+ LOG("finger 4.\n\r");
+ press_keyup[4] = true; // Don't trigger this event again until the finger has been released.
+
+ // Start scrolling up, until the user releases this finger.
+ mouseServicePtr->setSpeed(0, 0, -1);
}
}
}
