Add machine readable read command

This commit is contained in:
BlackMark 2020-07-03 22:34:10 +02:00
parent 05611c0697
commit 9a157f93ae

View File

@ -12,9 +12,10 @@ namespace detail {
constexpr auto ENDL = "\r\n";
constexpr auto HELP_CMD = "help";
constexpr auto READ_CMD = "read";
constexpr auto READ_CSV_CMD = "read csv";
constexpr auto VERSION_CMD = "version";
constexpr auto VERSION = "1.0";
constexpr auto VERSION = "1.1";
static inline bool substringEquals(const char* str1, const char* str2, const size_t& size)
{
@ -118,6 +119,9 @@ class Terminal {
else if(detail::substringEquals(m_inputBuffer, detail::READ_CMD, m_inputSize)) {
readSensors();
}
else if(detail::stringEquals(m_inputBuffer, detail::READ_CSV_CMD, m_inputSize)) {
readSensorsCsv();
}
else if(detail::substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
printVersion();
}
@ -138,6 +142,7 @@ class Terminal {
m_serial << "AdaptiveBrightness command overview: " << detail::ENDL;
m_serial << detail::HELP_CMD << " .......: prints this help message" << detail::ENDL;
m_serial << detail::READ_CMD << " .......: reads and displays all LDR values" << detail::ENDL;
m_serial << detail::READ_CSV_CMD << " ...: read LDR values as csv" << detail::ENDL;
m_serial << detail::VERSION_CMD << " ....: displays firmware version" << detail::ENDL;
}
@ -156,6 +161,16 @@ class Terminal {
}
}
static void readSensorsCsv()
{
const auto sensorValues = m_lightSensors.getValues();
for(size_t i = 0; i < sensorValues.size(); ++i) {
m_serial.txNumber(sensorValues[i]);
m_serial << ((i + 1 == sensorValues.size()) ? "" : ",");
}
m_serial << detail::ENDL;
}
static void printVersion() { m_serial << "AdaptiveBrightness v" << detail::VERSION << detail::ENDL; }
static void printUnknown()