inputs: serial: basic serial command inputs
This commit is contained in:
		
							
								
								
									
										34
									
								
								src/inputs/Serial.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/inputs/Serial.cpp
									
									
									
									
									
										Normal 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); | ||||
| @@ -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(); | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user