LoRa-BLE-Sensor
Loading...
Searching...
No Matches
Functions | Variables
sensor_power.c File Reference

This is a library for sensor power configurations and control. This is manages the power configuration, pin configuration, and control of sensor power. More...

#include "sensor_power.h"
#include <errno.h>
#include <zephyr/kernel.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/regulator.h>
#include <zephyr/drivers/adc.h>
#include <stdio.h>
#include <string.h>
#include <zephyr/logging/log.h>
Include dependency graph for sensor_power.c:

Functions

 LOG_MODULE_REGISTER (sensor_power, LOG_LEVEL_INF)
 
int set_sensor_output (sensor_power_config_t *config, enum sensor_voltage voltage)
 Set the sensor voltage for an output, enabling/disabling the correct regulators, and setting the correct gpios. When setting the voltage to OFF the voltage may take 1-2 seconds to fully turn off, due to capacitors on the output.
 
int sensor_power_init (sensor_power_config_t *config)
 Initialize a sensor_power_setup. This sets the id of the output, the gpios beings used and the regulator device being used. After configurations are set, the sensors output is set OFF.
 
enum sensor_voltage get_sensor_output (sensor_power_config_t *config)
 Get the sensor voltage that is set for an output.
 
float read_sensor_output (sensor_power_config_t *config)
 Read the voltage output of the selected sensor power configuration. Takes into account resistor divider on output.
 
int validate_output (sensor_power_config_t *config, enum sensor_voltage voltage, uint8_t accepted_error)
 

Variables

const float sensor_voltage_values []
 
enum sensor_voltage sensor_state [SENSOR_POWER_INDEX_LIMIT]
 

Detailed Description

This is a library for sensor power configurations and control. This is manages the power configuration, pin configuration, and control of sensor power.

Author
Tyler Garcia
Version
0.1
Date
2025-05-09

Function Documentation

◆ get_sensor_output()

enum sensor_voltage get_sensor_output ( sensor_power_config_t config)

Get the sensor voltage that is set for an output.

Parameters
configsensor_power_config_t sensor power configuration for the current sensor
Returns
enum sensor_voltage for selected sensor configuration

◆ read_sensor_output()

float read_sensor_output ( sensor_power_config_t config)

Read the voltage output of the selected sensor power configuration. Takes into account resistor divider on output.

Parameters
configsensor_power_config_t sensor power configuration for the current sensor
Returns
float output of the sensor power system

◆ sensor_power_init()

int sensor_power_init ( sensor_power_config_t config)

Initialize a sensor_power_setup. This sets the id of the output, the gpios beings used and the regulator device being used. After configurations are set, the sensors output is set OFF.

Parameters
configsensor_power_config_t sensor power configuration for the current sensor
Returns
int -1 if error setting up power system or adc

◆ set_sensor_output()

int set_sensor_output ( sensor_power_config_t config,
enum sensor_voltage  voltage 
)

Set the sensor voltage for an output, enabling/disabling the correct regulators, and setting the correct gpios. When setting the voltage to OFF the voltage may take 1-2 seconds to fully turn off, due to capacitors on the output.

Parameters
configsensor_power_config_t sensor power configuration for the current sensor
voltageenum sensor_voltage setting selected
Returns
int 0 if successful, sets voltage to OFF if invalid voltage input

◆ validate_output()

int validate_output ( sensor_power_config_t config,
enum sensor_voltage  voltage,
uint8_t  accepted_error 
)
Parameters
configsensor_power_config_t sensor power configuration for the current sensor
voltageenum sensor_voltage setting selected
accepted_errorerror in percent that the device is allowed to be off by
Returns
int 0 if successful, -1 if not

Variable Documentation

◆ sensor_voltage_values

const float sensor_voltage_values[]
Initial value:
= {
[SENSOR_VOLTAGE_OFF] = 2.75,
[SENSOR_VOLTAGE_3V3] = 3.3,
[SENSOR_VOLTAGE_5V] = 5.0,
[SENSOR_VOLTAGE_6V] = 6.0,
[SENSOR_VOLTAGE_12V] = 12.0,
[SENSOR_VOLTAGE_24V] = 24.0,
}