Skip to content

Commit 3ea2070

Browse files
DO NOT MERGE: Example to replicate issue codal-microbit-v2#377
lancaster-university/codal-microbit-v2#377.
1 parent 0cb9cfe commit 3ea2070

File tree

3 files changed

+81
-8
lines changed

3 files changed

+81
-8
lines changed

codal.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"name": "codal-microbit-v2",
44
"url": "https://github.com/lancaster-university/codal-microbit-v2",
55
"branch": "master",
6+
"dev": "true",
67
"type": "git"
78
},
89
"config":{

source/main.cpp

Lines changed: 78 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,86 @@
11
#include "MicroBit.h"
2-
#include "samples/Tests.h"
32

43
MicroBit uBit;
54

6-
int main()
7-
{
5+
class RawMicAdcSink : public CodalComponent, public DataSink {
6+
public:
7+
DataSource &upstream;
8+
int NrOfPullRequests = 0;
9+
10+
RawMicAdcSink(DataSource &source): upstream(source) {
11+
upstream.connect(*this);
12+
}
13+
14+
virtual int pullRequest() {
15+
ManagedBuffer b = upstream.pull();
16+
17+
uint8_t *data = &b[0];
18+
int SampleArrRaw[128];
19+
int format = upstream.getFormat();
20+
int skip = 2;
21+
int windowSize = 128;
22+
23+
if (format != DATASTREAM_FORMAT_16BIT_SIGNED) {
24+
uBit.serial.printf("Upstream data format enexpected: %d", format);
25+
uBit.sleep(100);
26+
uBit.serial.send("\r\n", SYNC_SPINWAIT);
27+
uBit.panic(123);
28+
}
29+
30+
int samples = b.length() / skip;
31+
32+
while(samples){
33+
// ensure we use at least windowSize number of samples (128)
34+
if (samples < windowSize) {
35+
break;
36+
}
37+
38+
uint8_t *ptr = data;
39+
uint8_t *end = data + windowSize;
40+
41+
bool dumpToSerial = false;
42+
uint8_t SampCntr = 0;
43+
44+
while (ptr < end) {
45+
int TempSample = StreamNormalizer::readSample[format](ptr);
46+
SampleArrRaw[SampCntr] = TempSample;
47+
SampCntr++;
48+
ptr += skip;
49+
50+
if (TempSample == -30584) {
51+
dumpToSerial = true;
52+
}
53+
}
54+
if (dumpToSerial) {
55+
uBit.serial.printf("pullRequest() number %d:\r\n", NrOfPullRequests);
56+
for (int i = 0; i < SampCntr; i++)
57+
uBit.serial.printf("%d\t", SampleArrRaw[i]);
58+
uBit.serial.send("\r\n\r\n");
59+
}
60+
61+
samples -= windowSize;
62+
data += windowSize;
63+
}
64+
65+
NrOfPullRequests++;
66+
67+
return DEVICE_OK;
68+
}
69+
};
70+
71+
72+
int main() {
873
uBit.init();
974

10-
out_of_box_experience();
75+
uBit.serial.send("Start:\r\n");
1176

12-
microbit_panic( 999 );
13-
}
77+
RawMicAdcSink* micAdcSink = new RawMicAdcSink(*(uBit.audio.rawSplitter->createChannel()));
1478

79+
uBit.io.P2.getAnalogValue();
80+
uBit.audio.virtualOutputPin.setAnalogPeriodUs(1000000 / 2600);
81+
uBit.audio.setSpeakerEnabled(false); // This line is just to avoid the annoying tone being played
82+
83+
while (true) {
84+
uBit.sleep(1);
85+
}
86+
}

utils/python/codal_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def build(clean, verbose = False, parallelism = 10):
1717

1818
if use_ninja:
1919
# configure
20-
system("cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Ninja\"")
20+
system("cmake .. -DCMAKE_BUILD_TYPE=Debug -G \"Ninja\"")
2121

2222
if clean:
2323
system("ninja clean")
@@ -29,7 +29,7 @@ def build(clean, verbose = False, parallelism = 10):
2929
system("ninja -j {}".format(parallelism))
3030
else:
3131
# configure
32-
system("cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -G \"Unix Makefiles\"")
32+
system("cmake .. -DCMAKE_BUILD_TYPE=Debug -G \"Unix Makefiles\"")
3333

3434
if clean:
3535
system("make clean")

0 commit comments

Comments
 (0)