Integrate terminal and implement read sensor command
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
|
||||
#include "light_sensors.hpp"
|
||||
|
||||
namespace detail {
|
||||
|
||||
constexpr auto ENDL = "\r\n";
|
||||
@@ -47,6 +49,7 @@ class Terminal {
|
||||
if(receiveInput()) {
|
||||
parseInput();
|
||||
}
|
||||
m_serial.flushTx();
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -57,6 +60,7 @@ class Terminal {
|
||||
static Uart m_serial;
|
||||
static char m_inputBuffer[INPUT_BUFFER_SIZE];
|
||||
static uint16_t m_inputSize;
|
||||
static LightSensors m_lightSensors;
|
||||
|
||||
static bool receiveInput()
|
||||
{
|
||||
@@ -112,7 +116,7 @@ class Terminal {
|
||||
printHelp();
|
||||
}
|
||||
else if(detail::substringEquals(m_inputBuffer, detail::READ_CMD, m_inputSize)) {
|
||||
readSensor();
|
||||
readSensors();
|
||||
}
|
||||
else if(detail::substringEquals(m_inputBuffer, detail::VERSION_CMD, m_inputSize)) {
|
||||
printVersion();
|
||||
@@ -137,7 +141,16 @@ class Terminal {
|
||||
m_serial << detail::VERSION_CMD << " ....: displays firmware version" << detail::ENDL;
|
||||
}
|
||||
|
||||
static void readSensor() { m_serial << "Sensor values: 1 2 3" << detail::ENDL; }
|
||||
static void readSensors()
|
||||
{
|
||||
const auto sensorValues = m_lightSensors.getValues();
|
||||
m_serial << "Sensor values: ";
|
||||
for(const auto& ldrValue: sensorValues) {
|
||||
m_serial.txNumber(ldrValue);
|
||||
m_serial << ", ";
|
||||
}
|
||||
m_serial << detail::ENDL;
|
||||
}
|
||||
|
||||
static void printVersion() { m_serial << "AdaptiveBrightness v" << detail::VERSION << detail::ENDL; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user