inputs: serial: basic serial command inputs

This commit is contained in:
Torrie Fischer 2023-02-18 16:27:24 +01:00
parent 85b42469f9
commit 2c7501f0c2
2 changed files with 42 additions and 3 deletions

34
src/inputs/Serial.cpp Normal file
View File

@ -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);

View File

@ -1,12 +1,17 @@
#pragma once
#include "Particle.h" #include "Particle.h"
#include "../Figments/Figments.h" #include "../Figments/Figments.h"
class SerialInput: public InputSource { class SerialInput: public InputSource {
public: public:
void onAttach() override { void onStart() override {
//Serial.begin(); //Serial.begin();
} }
InputEvent read() { InputEvent read();
}
private:
String m_buf;
void doCommand();
} }