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: SmartSwitch TMRh20 mbed
Diff: main.cpp
- Revision:
- 2:5d075b76930a
- Parent:
- 1:2b938172cef5
- Child:
- 3:f76bcafbbdd0
--- a/main.cpp Fri Mar 18 21:34:01 2016 +0000
+++ b/main.cpp Mon Mar 21 12:06:25 2016 +0000
@@ -10,7 +10,7 @@
DeafNode *deafNode;
Serial pc(USBTX, USBRX);
-#define SAMPLE_SIZE 240
+#define SAMPLE_SIZE 720
#define PRESAMPLE_SIZE 60
// Buffers to store the samples of the 4 channels
uint8_t buffer0[SAMPLE_SIZE];
@@ -55,18 +55,24 @@
void sendSamples(uint8_t id, uint8_t *samples, int length, int pointer)
{
- datapacket[0] = id;
+ datapacket[0] = 0x00;
+ datapacket[1] = 0x10;
+ datapacket[2] = id;
+
int c = 0;
while (c < length) {
int j;
- for (j = 0; j < 24; j++) {
- datapacket[1 + j] = samples[pointer];
+ //datapacket[3] = (uint8_t)(c & 0xff);
+ //datapacket[4] = (uint8_t)(c >> 8);
+ datapacket[3] = c;
+ for (j = 0; j < 20; j++) {
+ datapacket[4 + j] = samples[pointer];
pointer++;
- if (pointer > length) pointer = 0;
+ if (pointer >= SAMPLE_SIZE) pointer = 0;
c++;
if (c > length) break;
}
- deafNode->sendData(0, datapacket, j + 1);
+ deafNode->sendData(0, datapacket, j + 4);
}
}
@@ -114,21 +120,35 @@
if (sample_start < 0) sample_start += SAMPLE_SIZE;
}
sample_pointer++;
- if (sample_pointer > SAMPLE_SIZE) sample_pointer = 0;
+ if (sample_pointer >= SAMPLE_SIZE) sample_pointer = 0;
if (sample_size < SAMPLE_SIZE) sample_size++;
} else {
// In action, collecting
sample_pointer++;
- if (sample_pointer > SAMPLE_SIZE) sample_pointer = 0;
+ if (sample_pointer >= SAMPLE_SIZE) sample_pointer = 0;
sample_size++;
if (sample_size == SAMPLE_SIZE) {
// Stop collecting, send samples
action = false;
- sendSamples(0, buffer0, SAMPLE_SIZE, sample_start);
- sendSamples(1, buffer1, SAMPLE_SIZE, sample_start);
- sendSamples(2, buffer2, SAMPLE_SIZE, sample_start);
- sendSamples(3, buffer3, SAMPLE_SIZE, sample_start);
- printf("\nSamples were sent.\n");
+ for (int r = 1; r <= 2; r++) {
+ int sample_start2 = sample_start + SAMPLE_SIZE / 3;
+ if (sample_start2 >= SAMPLE_SIZE) sample_start2 -= SAMPLE_SIZE;
+ int sample_start3 = sample_start + 2* SAMPLE_SIZE / 3;
+ if (sample_start3 >= SAMPLE_SIZE) sample_start3 -= SAMPLE_SIZE;
+ sendSamples(0x00, buffer0, SAMPLE_SIZE / 3, sample_start);
+ sendSamples(0x10, buffer0, SAMPLE_SIZE / 3, sample_start2);
+ sendSamples(0x20, buffer0, SAMPLE_SIZE / 3, sample_start3);
+ sendSamples(0x01, buffer1, SAMPLE_SIZE / 3, sample_start);
+ sendSamples(0x11, buffer1, SAMPLE_SIZE / 3, sample_start2);
+ sendSamples(0x21, buffer1, SAMPLE_SIZE / 3, sample_start3);
+ sendSamples(0x02, buffer2, SAMPLE_SIZE / 3, sample_start);
+ sendSamples(0x12, buffer2, SAMPLE_SIZE / 3, sample_start2);
+ sendSamples(0x22, buffer2, SAMPLE_SIZE / 3, sample_start3);
+ sendSamples(0x03, buffer3, SAMPLE_SIZE / 3, sample_start);
+ sendSamples(0x13, buffer3, SAMPLE_SIZE / 3, sample_start2);
+ sendSamples(0x23, buffer3, SAMPLE_SIZE / 3, sample_start3);
+ printf("\nSamples were sent (%d).\n", r);
+ }
sample_size = 0;
sample_pointer = 0;
}