Refactor light sensor
This commit is contained in:
3
AdaptiveBrightnessFirmware/Src/light_sensors.cpp
Normal file
3
AdaptiveBrightnessFirmware/Src/light_sensors.cpp
Normal file
@@ -0,0 +1,3 @@
|
||||
#include "light_sensors.hpp"
|
||||
|
||||
std::array<uint16_t, 3> LightSensors::m_adcValues = {};
|
||||
@@ -3,33 +3,13 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
|
||||
#include "adc.h"
|
||||
#include "init.h"
|
||||
#include "light_sensors.hpp"
|
||||
#include "terminal.hpp"
|
||||
#include "uart.hpp"
|
||||
#include "utils.hpp"
|
||||
|
||||
using serial_t = uart::Vcp<>;
|
||||
|
||||
std::array<uint16_t, 3> sampleLightSensors()
|
||||
{
|
||||
std::array<uint16_t, 3> adcValues;
|
||||
|
||||
HAL_ADC_Start(&hadc);
|
||||
|
||||
util::for_constexpr(
|
||||
[&adcValues](const auto& idx) {
|
||||
constexpr auto i = idx.value;
|
||||
HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
|
||||
adcValues[i] = HAL_ADC_GetValue(&hadc);
|
||||
},
|
||||
std::make_index_sequence<adcValues.size()>{});
|
||||
|
||||
HAL_ADC_Stop(&hadc);
|
||||
|
||||
return adcValues;
|
||||
}
|
||||
|
||||
static volatile bool g_error = false;
|
||||
|
||||
extern "C" void Error_Handler(void)
|
||||
@@ -65,9 +45,10 @@ int main()
|
||||
HAL_GPIO_WritePin(BLUE_LED_GPIO_Port, BLUE_LED_Pin, GPIO_PIN_SET);
|
||||
|
||||
serial_t serial;
|
||||
LightSensors lightSensors;
|
||||
|
||||
while(true) {
|
||||
const auto ldrValues = sampleLightSensors();
|
||||
const auto ldrValues = lightSensors.getValues();
|
||||
|
||||
std::array<char, 32> printBuffer;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user