Integrate terminal and implement read sensor command
This commit is contained in:
@@ -1,14 +1,9 @@
|
||||
#include <array>
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
#include "init.h"
|
||||
#include "light_sensors.hpp"
|
||||
#include "terminal.hpp"
|
||||
#include "uart.hpp"
|
||||
|
||||
using serial_t = uart::Vcp<>;
|
||||
using terminal_t = Terminal<serial_t>;
|
||||
|
||||
static volatile bool g_error = false;
|
||||
|
||||
@@ -19,16 +14,13 @@ extern "C" void Error_Handler(void)
|
||||
|
||||
static inline void initializeHardware()
|
||||
{
|
||||
serial_t serial;
|
||||
terminal_t terminal;
|
||||
|
||||
do {
|
||||
g_error = false;
|
||||
init();
|
||||
serial.init();
|
||||
if(g_error)
|
||||
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_RESET);
|
||||
else
|
||||
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, GPIO_PIN_SET);
|
||||
terminal.init();
|
||||
HAL_GPIO_WritePin(RED_LED_GPIO_Port, RED_LED_Pin, g_error ? GPIO_PIN_RESET : GPIO_PIN_SET);
|
||||
} while(g_error);
|
||||
}
|
||||
|
||||
@@ -44,27 +36,10 @@ int main()
|
||||
HAL_GPIO_WritePin(GREEN_LED_GPIO_Port, GREEN_LED_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
||||
|
||||
serial_t serial;
|
||||
LightSensors lightSensors;
|
||||
terminal_t terminal;
|
||||
|
||||
while(true) {
|
||||
const auto ldrValues = lightSensors.getValues();
|
||||
|
||||
std::array<char, 32> printBuffer;
|
||||
|
||||
for(uint8_t i = 0; i < ldrValues.size(); ++i) {
|
||||
const auto ldrID = i + 1;
|
||||
const auto percentage = ldrValues[i] * 100 / 0xFFF;
|
||||
const auto bufLen = std::sprintf(printBuffer.data(), "LDR%d: %04hu - %03d%%\r\n%s", ldrID, ldrValues[i], percentage, (i == 2) ? "\r\n" : "");
|
||||
if(bufLen > 0) {
|
||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_RESET);
|
||||
serial.txString(printBuffer.data());
|
||||
serial.flushTx();
|
||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
||||
}
|
||||
}
|
||||
|
||||
HAL_Delay(1000);
|
||||
terminal.callback();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Reference in New Issue
Block a user