From 2c7501f0c2d452533bdaeb8235de14c54c0b5f17 Mon Sep 17 00:00:00 2001 From: Torrie Fischer Date: Sat, 18 Feb 2023 16:27:24 +0100 Subject: [PATCH] inputs: serial: basic serial command inputs --- src/inputs/Serial.cpp | 34 ++++++++++++++++++++++++++++++++++ src/inputs/Serial.h | 11 ++++++++--- 2 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/inputs/Serial.cpp diff --git a/src/inputs/Serial.cpp b/src/inputs/Serial.cpp new file mode 100644 index 0000000..2358665 --- /dev/null +++ b/src/inputs/Serial.cpp @@ -0,0 +1,34 @@ +#include "Serial.h" + +InputEvent +Serial::read() +{ + while (Serial.available() > 0) { + char nextChar = Serial.read(); + if (nextChar == '\n') { + doCommand(); + m_buf = ""; + } else { + m_buf += nextChar; + } + } +} + +void +Serial::doCommand() { + if (command == "tasks") { + Serial.println("Tasks:"); + auto sched = MainLoop::instance()->scheduler; + for(auto task : sched.tasks) { + bool isFigment = task->isFigment(); + if (isFigment) { + Serial.println("F " + task->name); + } else { + Serial.println("T " + task->name); + } + } + } +} + +STATIC_ALLOC(SerialInput); +STATIC_TASK(SerialInput); diff --git a/src/inputs/Serial.h b/src/inputs/Serial.h index 36fae7f..dfc2a65 100644 --- a/src/inputs/Serial.h +++ b/src/inputs/Serial.h @@ -1,12 +1,17 @@ +#pragma once #include "Particle.h" #include "../Figments/Figments.h" class SerialInput: public InputSource { public: - void onAttach() override { + void onStart() override { //Serial.begin(); } - InputEvent read() { - } + InputEvent read(); + +private: + String m_buf; + void doCommand(); + }