2021-11-10 09:35:27 +00:00
|
|
|
/**
|
|
|
|
* @file CommandHandler.h
|
|
|
|
* @author Jens True (jens.chr.true@gmail.com)
|
|
|
|
* @brief CommandHandler Header
|
|
|
|
* @version 0.1
|
|
|
|
* @date 2021-11-10
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2021
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2019-09-04 13:28:38 +00:00
|
|
|
#ifndef COMMANDHANDLER_H
|
|
|
|
#define COMMANDHANDLER_H
|
|
|
|
#include "DisplayProxy.h"
|
|
|
|
|
2021-10-28 14:44:20 +00:00
|
|
|
/**
|
2021-11-09 09:00:30 +00:00
|
|
|
* Parse a JSON command and convert it into display command(s).
|
2021-10-28 14:44:20 +00:00
|
|
|
*/
|
2019-09-04 13:28:38 +00:00
|
|
|
class CommandHandler
|
|
|
|
{
|
|
|
|
public:
|
2021-11-03 10:13:25 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
* @param display Takes an implementation of DisplayProxy through polymorphism.
|
|
|
|
*/
|
2021-10-28 11:50:57 +00:00
|
|
|
explicit CommandHandler(DisplayProxy *display);
|
2021-11-03 10:13:25 +00:00
|
|
|
/**
|
|
|
|
* Parse a command in JSON format
|
|
|
|
* @code{.json}
|
2021-11-09 09:00:30 +00:00
|
|
|
* To display a string
|
|
|
|
*
|
2021-11-03 10:13:25 +00:00
|
|
|
* {"cmd":"write","x": 2, "y": 10, "text":"Hello World"}
|
2021-11-09 09:00:30 +00:00
|
|
|
*
|
|
|
|
* or to clear the display
|
|
|
|
*
|
|
|
|
* {"cmd":"clear"}
|
2021-11-03 10:13:25 +00:00
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* @param cmd String to parse
|
|
|
|
* @return True if the input was parsed correctly.
|
|
|
|
*/
|
|
|
|
bool parseJSON(const char *cmd);
|
2021-11-10 09:35:27 +00:00
|
|
|
|
|
|
|
bool parse
|
2019-09-04 13:28:38 +00:00
|
|
|
private:
|
2021-11-03 10:13:25 +00:00
|
|
|
/**
|
2021-11-09 09:00:30 +00:00
|
|
|
* Internal helpers for printing debug strings
|
2021-11-03 10:13:25 +00:00
|
|
|
*/
|
2021-11-09 09:00:30 +00:00
|
|
|
void debugSerial(const char *text);
|
|
|
|
void debugSerial(const char *command, const char *text);
|
2021-11-03 15:01:30 +00:00
|
|
|
/**
|
|
|
|
* Display instance
|
|
|
|
*/
|
2019-09-04 13:28:38 +00:00
|
|
|
DisplayProxy *display;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|