Move parser to separate module and add USART_IsDataAvailable

This commit is contained in:
2024-08-27 15:09:06 +02:00
parent c716137e1a
commit e64880f66c
5 changed files with 65 additions and 51 deletions

44
src/parser.c Normal file
View File

@@ -0,0 +1,44 @@
#include "common.h"
#include "serial.h"
#include "parser.h"
// # Supported Commands
// (Optional decimal point for numbers)
// - START
// - RESET
// - STOP
// - SET TEMP 20
// - SET DEWP 60.0
static int state;
void CMD_Parse(char ch)
{
switch (state) {
case 0:
if (ch == 't')
state = 1;
break;
case 1:
if (ch == 'e')
state = 2;
else
state = 0;
case 2:
if (ch == 's')
state = 3;
else
state = 0;
case 3:
if (ch == 't')
state = 4;
else
state = 0;
case 4:
if (ch == '\n') {
USART_Printf("[CORE] Parsed 'test'!\r\n");
state = 0;
} else
state = 0;
}
}