move streamapi into a thread, saves power and increases responsiveness

This commit is contained in:
Kevin Hester
2021-03-25 06:15:15 +08:00
parent e17fe7e075
commit b20930c111
13 changed files with 121 additions and 114 deletions

View File

@@ -6,25 +6,28 @@
#define Port Serial
SerialConsole console;
SerialConsole *console;
void consoleInit()
{
new SerialConsole(); // Must be dynamically allocated because we are now inheriting from thread
}
void consolePrintf(const char *format, ...)
{
va_list arg;
va_start(arg, format);
console.vprintf(format, arg);
console->vprintf(format, arg);
va_end(arg);
}
SerialConsole::SerialConsole() : StreamAPI(&Port), RedirectablePrint(&Port)
{
assert(!console);
console = this;
canWrite = false; // We don't send packets to our port until it has talked to us first
// setDestination(&noopPrint); for testing, try turning off 'all' debug output and see what leaks
}
// setDestination(&noopPrint); for testing, try turning off 'all' debug output and see what leaks
/// Do late init that can't happen at constructor time
void SerialConsole::init()
{
Port.begin(SERIAL_BAUD);
StreamAPI::init();
emitRebooted();
@@ -34,14 +37,14 @@ void SerialConsole::init()
* we override this to notice when we've received a protobuf over the serial
* stream. Then we shunt off debug serial output.
*/
void SerialConsole::handleToRadio(const uint8_t *buf, size_t len)
bool SerialConsole::handleToRadio(const uint8_t *buf, size_t len)
{
// Turn off debug serial printing once the API is activated, because other threads could print and corrupt packets
if (!radioConfig.preferences.debug_log_enabled)
setDestination(&noopPrint);
canWrite = true;
StreamAPI::handleToRadio(buf, len);
return StreamAPI::handleToRadio(buf, len);
}
/// Hookable to find out when connection changes