mirror of
https://gitlab.com/Luci_/arduino-photometrics.git
synced 2026-04-03 11:35:37 +02:00
122 lines
3.1 KiB
C++
122 lines
3.1 KiB
C++
#include <Arduino.h>
|
|
#include "sensormanager.h"
|
|
#include "debug_config.h"
|
|
|
|
|
|
SensorManager::SensorManager(){}
|
|
|
|
SensorManager::~SensorManager(){}
|
|
|
|
/**
|
|
* @brief setup
|
|
* * init manager and photorésistor objects
|
|
*
|
|
* * @param nb_sensor @c uint8_t number of photoresistor
|
|
* @param analog_in @c uint8_t* array of pin identificators
|
|
* @return @c void
|
|
*/
|
|
void SensorManager::setup(uint8_t nb_sensor, uint8_t *analog_in){
|
|
nbPhotoSensor = nb_sensor;
|
|
for(uint8_t i = 0; i < nbPhotoSensor; i++){
|
|
SensorOhm tmp(analog_in[i]);
|
|
sensor_list[i] = tmp;
|
|
sensor_list[i].setup();
|
|
// init max and min array
|
|
if (unsigned_int){
|
|
min[i]= 2e9;
|
|
max[i]= 0;
|
|
}else{
|
|
min[i]= 2e9;
|
|
max[i]= -2e9;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief get_resistance
|
|
* * Get resistives values of photosensors
|
|
* Warning res_tab
|
|
* * @param res_tab @c int32_t must be a local array pointer
|
|
* @param tab_lenght @c uint8_t equal to or greater than the number of photo-res managed
|
|
* @return @c void
|
|
*/
|
|
void SensorManager::get_resistances(int32_t* res_tab, uint8_t tab_lenght){
|
|
if (tab_lenght < nbPhotoSensor){
|
|
DLOGLN("Error bad tab size")
|
|
return;
|
|
}
|
|
|
|
for (uint8_t i = 0; i < nbPhotoSensor; i++)
|
|
{
|
|
res_tab[i] = get_resistances_at(i);
|
|
}
|
|
}
|
|
|
|
void SensorManager::updateMinMax(uint8_t index, int32_t current_res) {
|
|
if(min[index] > current_res){
|
|
min[index] = current_res;
|
|
}
|
|
if(max[index] < current_res){
|
|
max[index] = current_res;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @brief get_min_max
|
|
* * Get highest and lowest resistives values of photosensors
|
|
* Warning res_tab
|
|
* * @param min_res_tab_max_res_tab @c int32_t must be a local array pointer
|
|
* @param tab_lenght @c uint8_t equal to or greater than the number of photo-res managed
|
|
* @return @c void
|
|
*/
|
|
void SensorManager::get_min_max(int32_t* min_res_tab, int32_t* max_res_tab, uint8_t tab_lenght){
|
|
if (tab_lenght < nbPhotoSensor){
|
|
DLOGLN("Error bad tab size")
|
|
return;
|
|
}
|
|
|
|
for (uint8_t i = 0; i < nbPhotoSensor; i++)
|
|
{
|
|
min_res_tab[i] = min[i];
|
|
max_res_tab[i] = max[i];
|
|
}
|
|
}
|
|
|
|
uint8_t SensorManager::get_nb_photores(){
|
|
return nbPhotoSensor;
|
|
}
|
|
|
|
void SensorManager::print_current_res(){
|
|
int32_t curr[nbPhotoSensor];
|
|
get_resistances(curr, nbPhotoSensor);
|
|
|
|
for (uint8_t i = 0; i < nbPhotoSensor; i++)
|
|
{
|
|
Serial.print("Photo-resistance n°");
|
|
Serial.print(i, DEC);
|
|
Serial.print(" : ");
|
|
Serial.print(curr[i], DEC);
|
|
Serial.print(" | ");
|
|
}
|
|
Serial.println();
|
|
}
|
|
|
|
void SensorManager::print_min_max_res(){
|
|
for (uint8_t i = 0; i < nbPhotoSensor; i++)
|
|
{
|
|
Serial.print("Photo-resistance n°");
|
|
Serial.print(i, DEC);
|
|
Serial.print(" : min = ");
|
|
Serial.print(min[i], DEC);
|
|
Serial.print(", max = ");
|
|
Serial.print(max[i], DEC);
|
|
Serial.print(" | ");
|
|
}
|
|
Serial.println();
|
|
}
|
|
|
|
int32_t SensorManager::get_resistances_at(uint8_t index){
|
|
int32_t tmp = sensor_list[index].readResistance();
|
|
updateMinMax(index, tmp);
|
|
return tmp;
|
|
} |