Skip to content

File SerialRead.cpp

File List > examples > SerialRead > SerialRead.cpp

Go to the documentation of this file

Source Code

#include "daisy_seed.h"

using namespace daisy;

DaisySeed hw;

FIFO<FixedCapStr<128>, 16> msg_fifo;

void UsbCallback(uint8_t *buff, uint32_t *length)
{
    if(buff && length) 
    {
        // Create a new string, and push it to the FIFO
        FixedCapStr<128> rx((const char *)buff, *length);
        msg_fifo.PushBack(rx);

        // strncpy(outbuff, (const char*)buff, *length);
        // hw.PrintLine(outbuff);
    }
}

int main(void)
{
    // Initialize the Daisy Seed
    hw.Init();

    // Start the log, and wait for connection
    hw.StartLog(true);

    // Set USB callback
    hw.usb_handle.SetReceiveCallback(UsbCallback,
                                     UsbHandle::UsbPeriph::FS_INTERNAL);

    hw.PrintLine("Send messages in your Serial Monitor!");

    while(1)
    {
        while(!msg_fifo.IsEmpty())
        {
            auto msg = msg_fifo.PopFront();
            hw.Print("Received Message: ");
            hw.PrintLine(msg.Cstr());
        }

        hw.SetLed((System::GetNow() & 1023) > 511);
    }
}