Public Access
43 lines
936 B
C++
43 lines
936 B
C++
#include "nano_link/nano_monitor.h"
|
|||
|
|
|
||
|
|
NanoMonitor::NanoMonitor(NanoLink &nano, BROSE9323 &display) : _nano(nano), _display(display)
|
||
|
|
{
|
||
|
|
}
|
||
|
|
|
||
|
|
bool NanoMonitor::loop(uint32_t now, uint32_t resync_ms)
|
||
|
|
{
|
||
|
|
bool on = _nano.isOn();
|
||
|
|
if (on != _was_on)
|
||
|
|
{
|
||
|
|
// Switched on (the Nano booted, NanoLink::on() took its READY) or off
|
||
|
|
_was_on = on;
|
||
|
|
_check.reset(now);
|
||
|
|
_len = 0;
|
||
|
|
}
|
||
|
|
if (!on)
|
||
|
|
return false;
|
||
|
|
|
||
|
|
// First the answers that arrived (also while loop() was blocked), then the timeouts
|
||
|
|
Stream &serial = _nano.stream();
|
||
|
|
while (serial.available())
|
||
|
|
{
|
||
|
|
char c = serial.read();
|
||
|
|
if (c == '\n')
|
||
|
|
{
|
||
|
|
_line[_len] = '\0';
|
||
|
|
_check.line(_line, now);
|
||
|
|
_len = 0;
|
||
|
|
}
|
||
|
|
else if (_len < sizeof(_line) - 1)
|
||
|
|
_line[_len++] = c;
|
||
|
|
}
|
||
|
|
bool resync = _check.resyncNow(now, resync_ms);
|
||
|
|
|
||
|
|
uint32_t frames = _display.framesSent();
|
||
|
|
if (_check.due(frames, now))
|
||
|
|
{
|
||
|
|
serial.print("C\n");
|
||
|
|
_check.sent(_display.crc(), frames, now);
|
||
|
|
}
|
||
|
|
return resync;
|
||
|
|
}
|