diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig b/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig index 6ac033e64399fd24035e0b857c71ba88216bee6f..90d0673bcc0ad4cf9877a303ccd8576cffff24cc 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig +++ b/zephyr/modules/owntech_data_acquisition/zephyr/Kconfig @@ -4,5 +4,6 @@ config OWNTECH_DATA_ACQUISITION select DMA depends on OWNTECH_ADC_DRIVER depends on OWNTECH_HRTIM_DRIVER + depends on CONSOLE_GETCHAR # Force-select the following to avoid dependency loop select OWNTECH_SCHEDULING diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.cpp b/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.cpp index 6bb2143b76b52582ecca207fcb837f7e218ad58b..f67932cfd364a87aa2998ad672292812d362f529 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.cpp +++ b/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.cpp @@ -28,8 +28,13 @@ ///// // Include + // Zephyr #include <zephyr.h> +#include <console/console.h> + +// Stdlib +#include <stdlib.h> // Current file header #include "data_conversion.h" @@ -59,6 +64,67 @@ static float32_t offset_temperature = 0.0; static float32_t gain_analog_comm = 1.0; static float32_t offset_analog_comm = 0.0; +//Maximum number of number for gain and offset value +static const uint8_t MaxCharInOneLine = 20; + +///// +// Private Functions + +float32_t get_calibration_coefficients(const char* physicalParameter,const char* gainOrOffset) +{ + + uint8_t carcount; + char received_char; + char line[MaxCharInOneLine];//number of character in one line + float32_t parameterCoefficient; + + do + { + //Initializing variables for eventual loop + carcount = 0; + + printk("Type %s %s and press enter \n", physicalParameter, gainOrOffset); + + do + { + received_char = console_getchar(); + line[carcount] = received_char; + + if(received_char == 0x08)//backspace character + { + if(carcount>0)//To avoid carcount being negative + carcount--; + } + else + { + carcount++; + } + + printk("%c", received_char);//echoing value + + if(carcount>=(MaxCharInOneLine-1)) + { + printk("Maximum caracter allowed reached \n"); + break; + } + + } while ((received_char!='\n')); // EOL char : CRLF + line[carcount-2] = '\0'; // adding end of tab character to prepare for atof function + + //Converting string to float + parameterCoefficient = atof(line); + + //Getting confirmation + printk("%s %s applied will be : %f\n", physicalParameter, gainOrOffset, parameterCoefficient); + + //Getting validation + printk("Press y to validate, any other character to retype the %s \n", gainOrOffset); + received_char = console_getchar(); + + }while(received_char != 'y'); + + return parameterCoefficient; +} ///// // Public Functions @@ -170,3 +236,47 @@ void data_conversion_set_analog_comm_parameters(float32_t gain, float32_t offset gain_analog_comm = gain; offset_analog_comm = offset; } + +void set_default_acquisition_parameters() +{ + float32_t gains[] = {1, 1, 1, 1, 1, 1}; + float32_t offsets[] = {0, 0, 0, 0, 0, 0}; + + data_conversion_set_v_high_parameters(gains[0], offsets[0]); + data_conversion_set_v1_low_parameters(gains[1], offsets[1]); + data_conversion_set_v2_low_parameters(gains[2], offsets[2]); + data_conversion_set_i_high_parameters(gains[3], offsets[3]); + data_conversion_set_i1_low_parameters(gains[4], offsets[4]); + data_conversion_set_i2_low_parameters(gains[5], offsets[5]); + + printk("Calibration gains set to default !\n"); +} + +void set_user_acquisition_parameters() +{ + static float32_t gains[6];//VH, V1, V2, IH, I1, I2 + static float32_t offsets[6];//VH, V1, V2, IH, I1, I2 + + gains[0] = get_calibration_coefficients("VHigh", "gain"); + gains[1] = get_calibration_coefficients("V1Low", "gain"); + gains[2] = get_calibration_coefficients("V2Low", "gain"); + gains[3] = get_calibration_coefficients("I2Low", "gain"); + gains[4] = get_calibration_coefficients("IHigh", "gain"); + gains[5] = get_calibration_coefficients("I1Low", "gain"); + + offsets[0] = get_calibration_coefficients("VHigh", "offset"); + offsets[1] = get_calibration_coefficients("V1Low", "offset"); + offsets[2] = get_calibration_coefficients("V2Low", "offset"); + offsets[3] = get_calibration_coefficients("I2Low", "offset"); + offsets[4] = get_calibration_coefficients("IHigh", "offset"); + offsets[5] = get_calibration_coefficients("I1Low", "offset"); + + data_conversion_set_v_high_parameters(gains[0], offsets[0]); + data_conversion_set_v1_low_parameters(gains[1], offsets[1]); + data_conversion_set_v2_low_parameters(gains[2], offsets[2]); + data_conversion_set_i_high_parameters(gains[3], offsets[3]); + data_conversion_set_i1_low_parameters(gains[4], offsets[4]); + data_conversion_set_i2_low_parameters(gains[5], offsets[5]); + + printk("Calibration coefficients updated !\n"); +} \ No newline at end of file diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.h b/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.h index c59a082399195abbee2a32e8bb04325f63275541..1c1cc986dfcc003f1abb9055050c5a6f9e09aecc 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.h +++ b/zephyr/modules/owntech_data_acquisition/zephyr/data_conversion/data_conversion.h @@ -22,6 +22,7 @@ * @author Antoine Boche <antoine.boche@laas.fr> * @author Clément Foucher <clement.foucher@laas.fr> * @author Luiz Villa <luiz.villa@laas.fr> + * @author Thomas Walter <thomas.walter@laas.fr> */ #ifndef DATA_CONVERSION_H_ @@ -186,5 +187,14 @@ void data_conversion_set_extra_parameters(float32_t gain, float32_t offset); */ void data_conversion_set_analog_comm_parameters(float32_t gain, float32_t offset); +/** + * @brief Set calibration coefficients of all gains to 1 and all offsets to 0 + */ +void set_default_acquisition_parameters(); + +/** + * @brief Retrieve calibration coefficients via console input and update them + */ +void set_user_acquisition_parameters(); #endif // DATA_CONVERSION_H_ diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp index 7b2afac44293d6caa78987c94029df759033c776..b841d3958a21f82c866877e819cee29ba5a17959 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp +++ b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.cpp @@ -22,6 +22,7 @@ * * @author Clément Foucher <clement.foucher@laas.fr> * @author Luiz Villa <luiz.villa@laas.fr> + * @author Thomas Walter <thomas.walter@laas.fr> */ @@ -477,3 +478,13 @@ void DataAcquisition::_setParameters(channel_assignment_t assignment, float32_t { assignment.set_parameters(gain, offset); } + +void DataAcquisition::setDefaultCalibrationFactors(void) +{ + set_default_acquisition_parameters(); +} + +void DataAcquisition::setUserCalibrationFactors(void) +{ + set_user_acquisition_parameters(); +} \ No newline at end of file diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h index d559e942cc1107577bcdf2ef8a8e0981f008fd36..2df56b31a671eaccab3503e08c6a960e99ce16a7 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h +++ b/zephyr/modules/owntech_data_acquisition/zephyr/public_api/DataAcquisition.h @@ -21,6 +21,7 @@ * @date 2023 * * @author Clément Foucher <clement.foucher@laas.fr> + * @author Thomas Walter <thomas.walter@laas.fr> */ @@ -265,6 +266,17 @@ public: void setAnalogCommParameters(float32_t gain, float32_t offset); ///@} + /** + * @brief Init default gain and offset structures for all ADCs and + * sets these default parameters. + */ + void setDefaultCalibrationFactors(void); + + /** + * @brief Retrieve stored parameters from Flash memory and configure ADC parameters + */ + void setUserCalibrationFactors(void); + private: /** * Internal types definitions.