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 mbed nRF51822
Fork of zach_thresholding by
Revision 17:bd261621151f, committed 2017-05-04
- Comitter:
- znew711
- Date:
- Thu May 04 00:55:34 2017 +0000
- Parent:
- 16:799397f0d3a8
- Commit message:
- pls work;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue May 02 23:42:04 2017 +0000
+++ b/main.cpp Thu May 04 00:55:34 2017 +0000
@@ -95,7 +95,11 @@
#define PACKET_SIZE 20
#define QUEUE_SIZE 20
-#define Z_THRESHOLD 5000
+#define Z_THRESHOLD 5650
+#define ACCEL_ONE_RESTING 5550
+#define ACCEL_TWO_RESTING 5135
+#define ACCEL_ONE_EPSILON 336
+#define ACCEL_TWO_EPSILON 369
const static char DEVICE_NAME[] = "LUMBERJACK_NANO";
static const uint16_t uuid16_list[] = {ButtonService::BUTTON_SERVICE_UUID};
@@ -164,13 +168,17 @@
void startTransmission() {
uint8_t* nextPacket = removeFromQueue();
- buttonServicePtr->updateButtonState(nextPacket);
+ if (nextPacket != NULL) {
+ buttonServicePtr->updateButtonState(nextPacket);
+ }
}
void dataSentCallback(unsigned count) {
//pc.printf("dataSent!!\r\n");
uint8_t* nextPacket = removeFromQueue();
- buttonServicePtr->updateButtonState(nextPacket);
+ if (nextPacket != NULL) {
+ buttonServicePtr->updateButtonState(nextPacket);
+ }
}
/**
@@ -445,6 +453,7 @@
uint8_t lastThreeIndex = 0;
uint8_t underThresholdCount = 0;
bool inAKeyStroke = false;
+ uint16_t counter = 0;
while(1)
{
@@ -461,32 +470,9 @@
//pc.printf("Accel two: x %d y %d z %d\r\n", (int16_t)x2, (int16_t)y2, (int16_t)z2);
uint8_t values[20] = {(uint8_t)(x1 >> 8), (uint8_t)x1, (uint8_t)(y1 >> 8), (uint8_t)y1, (uint8_t)(z1 >> 8), (uint8_t)z1,
(uint8_t)(x2 >> 8), (uint8_t)x2, (uint8_t)(y2 >> 8), (uint8_t)y2, (uint8_t)(z2 >> 8), (uint8_t)z2,
- 0, 0, 0, 0, 0, 0, 0, 0};
- //TODO: handle negative accels
- if (z1 > Z_THRESHOLD || z2 > Z_THRESHOLD) {
- underThresholdCount = 0;
- if (!inAKeyStroke) {
- //start transmitting
- inAKeyStroke = true;
- for (int i = 0; i < 3; i++) {
- addToQueue(lastThreePackets[(lastThreeIndex - 1 - i) % 3]);
- }
- addToQueue(values);
- startTransmission();
- } else {
- addToQueue(values);
- }
- } else if (underThresholdCount < 3 && inAKeyStroke) {
- underThresholdCount++;
- addToQueue(values);
- } else {
- for (int i = 0; i < 20; i++) {
- lastThreePackets[lastThreeIndex][i] = values[i];
- }
- lastThreeIndex = (lastThreeIndex + 1) % 3;
- inAKeyStroke = false;
- }
-
+ (uint8_t)(counter >> 8), (uint8_t) counter, 0, 0, 0, 0, 0, 0};
+ buttonServicePtr->updateButtonState(values);
+ counter++;
wait_ms(50);
}
