70 lines
1.7 KiB
C
70 lines
1.7 KiB
C
/**
|
|
* @file adc_sensor.c
|
|
* @brief Implementation of the ADC sensor library.
|
|
*
|
|
* This file contains the implementation for initializing and reading from ADC
|
|
* sensors. It currently provides simulated values for voltage and current, with
|
|
* placeholders for real hardware ADC implementation.
|
|
*/
|
|
|
|
#include <lib/adc_sensor.h>
|
|
#include <zephyr/kernel.h>
|
|
#include <zephyr/logging/log.h>
|
|
|
|
LOG_MODULE_REGISTER(adc_sensor, LOG_LEVEL_INF);
|
|
|
|
// Simulated values
|
|
#define SIMULATED_VOLTAGE_MV 12000
|
|
#define SIMULATED_CURRENT_MA 45
|
|
|
|
static bool initialized =
|
|
false; // Flag to indicate if the ADC sensor is initialized
|
|
|
|
int adc_sensor_init(void) {
|
|
if (initialized) {
|
|
return 0;
|
|
}
|
|
|
|
#ifdef CONFIG_ADC_SENSOR_SIMULATED
|
|
LOG_INF("ADC sensor initialized (simulated mode)");
|
|
LOG_INF("Simulated values: %dmV, %dmA", SIMULATED_VOLTAGE_MV,
|
|
SIMULATED_CURRENT_MA);
|
|
#else
|
|
// TODO: Initialize real ADC hardware
|
|
LOG_INF("ADC sensor initialized (real ADC mode - not yet implemented)");
|
|
#endif
|
|
|
|
initialized = true;
|
|
return 0;
|
|
}
|
|
|
|
uint16_t adc_sensor_get_voltage_mv(void) {
|
|
if (!initialized) {
|
|
LOG_WRN("ADC sensor not initialized, calling adc_sensor_init()");
|
|
adc_sensor_init();
|
|
}
|
|
|
|
#ifdef CONFIG_ADC_SENSOR_SIMULATED
|
|
return SIMULATED_VOLTAGE_MV;
|
|
#else
|
|
// TODO: Read real ADC value for voltage
|
|
// For now return simulated value
|
|
return SIMULATED_VOLTAGE_MV;
|
|
#endif
|
|
}
|
|
|
|
uint16_t adc_sensor_get_current_ma(void) {
|
|
if (!initialized) {
|
|
LOG_WRN("ADC sensor not initialized, calling adc_sensor_init()");
|
|
adc_sensor_init();
|
|
}
|
|
|
|
#ifdef CONFIG_ADC_SENSOR_SIMULATED
|
|
return SIMULATED_CURRENT_MA;
|
|
#else
|
|
// TODO: Read real ADC value for current
|
|
// For now return simulated value
|
|
return SIMULATED_CURRENT_MA;
|
|
#endif
|
|
}
|