aboutsummaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2020-06-24 19:57:29 -0400
committerClyne Sullivan <clyne@bitgloo.com>2020-06-24 19:57:29 -0400
commit875b6a062029f0738ac309ef4a915120aee24ef7 (patch)
tree88f5dcf21e30765cdb6eee760d4956045f11364a /source
parentda8d7ffe8a12c10f819f103de1194511bdb3776e (diff)
GUI reads ADC channel
Diffstat (limited to 'source')
-rw-r--r--source/main.cpp14
1 files changed, 8 insertions, 6 deletions
diff --git a/source/main.cpp b/source/main.cpp
index dc38ddd..b73776a 100644
--- a/source/main.cpp
+++ b/source/main.cpp
@@ -23,7 +23,7 @@ static_assert(sizeof(adcsample_t) == sizeof(uint16_t));
#if CACHE_LINE_SIZE > 0
CC_ALIGN(CACHE_LINE_SIZE)
#endif
-static std::array<adcsample_t, CACHE_SIZE_ALIGN(adcsample_t, 100)> adc_samples;
+static std::array<adcsample_t, CACHE_SIZE_ALIGN(adcsample_t, 2048)> adc_samples;
int main()
{
@@ -49,11 +49,13 @@ int main()
while (true) {
if (usbd.active()) {
// Expect to receive a byte command 'packet'.
- if (char cmd; usbd.read(&cmd) > 0) {
- switch (cmd) {
+ if (char cmd[3]; usbd.read(&cmd, 3) > 0) {
+ switch (cmd[0]) {
case 'r': // Read in analog signal
- adc.getSamples(&adc_samples[0], 100);//adc_samples.size());
- usbd.write(adc_samples.data(), adc_samples.size());
+ if (auto count = std::min(static_cast<unsigned int>(cmd[1] | (cmd[2] << 8)), adc_samples.size()); count > 0) {
+ adc.getSamples(&adc_samples[0], count);
+ usbd.write(adc_samples.data(), count * sizeof(adcsample_t));
+ }
break;
case 'i': // Identify ourself as an stmdsp device
usbd.write("stmdsp", 6);
@@ -64,7 +66,7 @@ int main()
}
}
- chThdSleepMilliseconds(250);
+ chThdSleepMilliseconds(1);
}
}