mirror of
https://github.com/meshtastic/firmware.git
synced 2025-04-29 19:03:52 +00:00

* POC. Board definition JSON upcoming. Generic for now * side-effect: RP2040 is building again. * WIP Pico Targets * current state of affairs * ahem * POC. Board definition JSON upcoming. Generic for now * side-effect: RP2040 is building again. * WIP Pico Targets * current state of affairs * ahem * fmt * update toolkit and fmt * Add built in LED pin * Use arduino pins * init SPI bus on right pins. * Use SPI1 and control chip select manually * Use macro define for SPI selection. This needs to be defined in the ini file since portduino needs it inside the framework source * Remove manual CS; works when not using setCS() * Remove whoopsie debug line * we are not ARDUINO_AVR_NANO_EVERY any more * fix rp2040 compilation * fix RadioLibHAL * Use new arduino-pico core * Use cortex-m0plus for BSEC2 library * Forgot RAK11310 target for BSEC2 library * That branch was merged * RAK11310 is working too --------- Co-authored-by: Ben Meadors <benmmeadors@gmail.com> Co-authored-by: GUVWAF <thijs@havinga.eu>
81 lines
2.3 KiB
C++
81 lines
2.3 KiB
C++
#include "SerialConsole.h"
|
|
#include "NodeDB.h"
|
|
#include "PowerFSM.h"
|
|
#include "configuration.h"
|
|
|
|
#define Port Serial
|
|
// Defaulting to the formerly removed phone_timeout_secs value of 15 minutes
|
|
#define SERIAL_CONNECTION_TIMEOUT (15 * 60) * 1000UL
|
|
|
|
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);
|
|
va_end(arg);
|
|
console->flush();
|
|
}
|
|
|
|
SerialConsole::SerialConsole() : StreamAPI(&Port), RedirectablePrint(&Port), concurrency::OSThread("SerialConsole")
|
|
{
|
|
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
|
|
|
|
Port.begin(SERIAL_BAUD);
|
|
#if defined(ARCH_NRF52) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3) || defined(ARCH_RP2040)
|
|
time_t timeout = millis();
|
|
while (!Port) {
|
|
if ((millis() - timeout) < 5000) {
|
|
delay(100);
|
|
} else {
|
|
break;
|
|
}
|
|
}
|
|
#endif
|
|
emitRebooted();
|
|
}
|
|
|
|
int32_t SerialConsole::runOnce()
|
|
{
|
|
return runOncePart();
|
|
}
|
|
|
|
void SerialConsole::flush()
|
|
{
|
|
Port.flush();
|
|
}
|
|
|
|
// For the serial port we can't really detect if any client is on the other side, so instead just look for recent messages
|
|
bool SerialConsole::checkIsConnected()
|
|
{
|
|
uint32_t now = millis();
|
|
return (now - lastContactMsec) < SERIAL_CONNECTION_TIMEOUT;
|
|
}
|
|
|
|
/**
|
|
* we override this to notice when we've received a protobuf over the serial
|
|
* stream. Then we shunt off debug serial output.
|
|
*/
|
|
bool SerialConsole::handleToRadio(const uint8_t *buf, size_t len)
|
|
{
|
|
// only talk to the API once the configuration has been loaded and we're sure the serial port is not disabled.
|
|
if (config.has_lora && config.device.serial_enabled) {
|
|
// Turn off debug serial printing once the API is activated, because other threads could print and corrupt packets
|
|
if (!config.device.debug_log_enabled)
|
|
setDestination(&noopPrint);
|
|
canWrite = true;
|
|
|
|
return StreamAPI::handleToRadio(buf, len);
|
|
} else {
|
|
return false;
|
|
}
|
|
} |