Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions src/assets/files/UsbSerialSimple.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include "Particle.h"

SerialLogHandler logHandler;

SYSTEM_THREAD(ENABLED);

const std::chrono::milliseconds logPeriod = 5s;
unsigned long lastLog;
int counter;

void setup()
{
}

void loop()
{
if (Network.listening())
{
// If we are in listening mode (blinking dark blue), don't
// output by USB serial, because it can conflict with
// serial commands.
return;
}

if (millis() - lastLog >= logPeriod.count())
{
lastLog = millis();

Log.info("counter=%d", ++counter);
}
}
56 changes: 56 additions & 0 deletions src/assets/files/UsbSerialTwoWay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#include "Particle.h"

SerialLogHandler logHandler;

SYSTEM_THREAD(ENABLED);

const std::chrono::milliseconds logPeriod = 5s;
unsigned long lastLog;
int counter;

const size_t BUF_SIZE = 128;
char buf[BUF_SIZE];
size_t bufOffset = 0;

void setup()
{
}

void loop()
{
if (Network.listening())
{
// If we are in listening mode (blinking dark blue), don't
// output by USB serial, because it can conflict with
// serial commands.
return;
}

if (millis() - lastLog >= logPeriod.count())
{
lastLog = millis();

Log.info("counter=%d", ++counter);
}

while (Serial.available())
{
char c = (char)Serial.read();
if (c == '\r' || c == '\n')
{
if (bufOffset > 0)
{
buf[bufOffset] = 0;
Log.info("received %s", buf);
}
bufOffset = 0;
}
else
{
if ((bufOffset + 1) < (BUF_SIZE - 1))
{
buf[bufOffset++] = c;
}
}
}
}
Loading