electro-smith / libDaisy

Hardware Library for the Daisy Audio Platform
https://www.electro-smith.com/daisy
MIT License
314 stars 131 forks source link

Bug Fix - USB Logger missing messages with wait_for_pc set to true #463

Closed stephenhensley closed 2 years ago

stephenhensley commented 2 years ago

Applied short delay to Logger<>::StartLog function to prevent missed messages.

I can't really explain what wasn't working because the blocking transmit was blocking (I confirmed by stepping into some of the functions), but for some reason without a delay, the first several messages wouldn't ever make it to a Serial Monitor.

Also, trying to put the delay within the USB init instead of the Logger, or pretty much anywhere else that would have made sense failed to stop the issue.

Anyway, this seems to resolve #343 and related issues that required setting a delay after the Logging function.

github-actions[bot] commented 2 years ago

Unit Test Results

    1 files  ±0    16 suites  ±0   0s :stopwatch: ±0s 145 tests ±0  145 :heavy_check_mark: ±0  0 :zzz: ±0  0 :x: ±0 

Results for commit 0ad2657e. ± Comparison against base commit 121074f7.

stephenhensley commented 2 years ago

Confirmed that this should fix #343

The following code, doesn't cause any issues starting the audio immediately after the Logger:

#include "daisy_seed.h"

using namespace daisy;

DaisySeed hw;

void AudioCallback(AudioHandle::InputBuffer  in,
                   AudioHandle::OutputBuffer out,
                   size_t                    size)
{
    std::copy(&in[0][0], &in[0][size], &out[0][0]);
    std::copy(&in[1][0], &in[1][size], &out[1][0]);
}

int main(void)
{
    hw.Init();
    hw.StartLog();
    hw.StartAudio(AudioCallback);
    hw.PrintLine("Hello World!");
    while(1) {}
}