3 #if (RI_ADC_PHOTO_ENABLED || DOXYGEN)
26 #ifdef RI_ADC_PHOTO_CHANNEL
27 #define ADC_PHOTO_USE_CHANNEL RI_ADC_PHOTO_CHANNEL
29 #define ADC_PHOTO_USE_CHANNEL 1
32 #ifdef RI_ADC_PHOTO_DIVIDER
33 #define ADC_PHOTO_USE_DIVIDER RI_ADC_PHOTO_DIVIDER
35 #define ADC_PHOTO_USE_DIVIDER 1.00f
38 #ifdef RI_ADC_PHOTO_VDD
39 #define ADC_PHOTO_USE_VDD RI_ADC_PHOTO_VDD
41 #define ADC_PHOTO_USE_VDD 3.60f
44 #define ADC_PHOTO_DATA_COUNTER 1
45 #define ADC_PHOTO_DEFAULT_BITFIELD 0
46 #define ADC_PHOTO_ENABLE_BYTE 1
47 #define ADC_PHOTO_VOLTS_TO_LUX 1333.00f
52 #ifdef RI_ADC_ADV_CONFIG
53 .p_pin.resistor = RI_ADC_RESISTOR_DISABLED,
61 #ifdef RI_ADC_ADV_CONFIG
63 .acqtime = RI_ADC_ACQTIME_10US,
73 static uint64_t m_tsample;
74 static bool m_autorefresh;
76 static bool m_is_init;
77 static const char m_sensor_name[] =
"PHOTO";
80 static float volts_to_lux (
const float *
const data)
162 environmental_sensor,
rd_bus_t bus, uint8_t handle)
166 if (NULL == environmental_sensor)
179 environmental_sensor->
name = m_sensor_name;
183 &adc_photo_pins_config,
227 m_autorefresh =
false;
247 m_autorefresh =
false;
252 uint8_t current_mode;
262 m_autorefresh =
false;
264 err_code |= get_data();
269 m_autorefresh =
true;
317 err_code = get_data();
328 d_environmental.
data = &env_values;
329 d_environmental.
valid = env_fields;
330 d_environmental.
fields = env_fields;
#define RD_ERROR_INVALID_PARAM
Invalid Parameter.
#define RD_ERROR_NULL
Null Pointer.
uint32_t rd_status_t
bitfield for representing errors
#define RD_ERROR_NOT_SUPPORTED
Not supported.
#define RD_SUCCESS
Internal Error.
#define RD_UINT64_INVALID
Signal that value should not be used.
#define RD_ERROR_INVALID_STATE
Invalid state, operation disallowed in this state.
#define RD_SENSOR_DSP_LAST
Return last value from sensor. Parameter: No effect. Use default.
#define RD_SENSOR_CFG_SLEEP
Sensor should go to sleep immediately.
#define RD_SENSOR_CFG_DEFAULT
Default value, always valid for the sensor.
void rd_sensor_uninitialize(rd_sensor_t *const p_sensor)
Mark sensor as uninitialized by calling the generic initialization. Will not clear the name of the se...
rd_status_t rd_sensor_configuration_get(const rd_sensor_t *sensor, rd_sensor_configuration_t *config)
Implementation of ref rd_configuration_fp.
void rd_sensor_initialize(rd_sensor_t *const p_sensor)
Initialize sensor struct with non-null pointers which return RD_ERROR_NOT_INITIALIZED.
rd_status_t validate_default_input_set(uint8_t *const input, const uint8_t mode)
Validate that given setting can be set on a sensor which supports only default value.
void rd_sensor_data_populate(rd_sensor_data_t *const target, const rd_sensor_data_t *const provided, const rd_sensor_data_fields_t requested)
Populate given target data with data provided by sensor as requested.
rd_status_t rd_sensor_configuration_set(const rd_sensor_t *sensor, rd_sensor_configuration_t *config)
Implementation of ref rd_configuration_fp.
#define RD_SENSOR_CFG_CONTINUOUS
Sensor will keep sampling at defined sample rate.
rd_bus_t
Type of bus sensor uses.
uint64_t rd_sensor_timestamp_get(void)
Calls the timestamp function and returns its value.
rd_status_t validate_default_input_get(uint8_t *const input)
Validate and get input when only allowed value is default.
#define RD_SENSOR_CFG_SINGLE
Sensor should go to sleep after single measurement.
Header to enable and disable module compilation.
Ruuvi error codes and error check function.
Ruuvi sensor interface Lifecycle: Beta
Interface for controlling ADC onboard MCU.
@ RI_ADC_MODE_SINGLE
Single ended mode.
@ RI_ADC_VREF_EXTERNAL
External voltage reference.
rd_status_t ri_adc_get_data_absolute(uint8_t channel_num, ri_adc_get_data_t *p_config, float *p_data)
Get ADC data in volts.
@ RI_ADC_GND
GND of device.
rd_status_t ri_adc_stop(uint8_t channel_num)
Stop use ADC channel.
rd_status_t ri_adc_configure(uint8_t channel_num, ri_adc_pins_config_t *p_pins, ri_adc_channel_config_t *p_config)
Configure ADC channel.
rd_status_t ri_adc_init(ri_adc_config_t *p_config)
Initialization of ADC.
rd_status_t ri_adc_photo_scale_set(uint8_t *scale)
rd_sensor_setup_fp
rd_status_t ri_adc_photo_mode_get(uint8_t *mode)
rd_sensor_setup_fp
rd_status_t ri_adc_photo_dsp_set(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
#define ADC_PHOTO_USE_VDD
rd_status_t ri_adc_photo_init(rd_sensor_t *environmental_sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_adc_photo_dsp_get(uint8_t *dsp, uint8_t *parameter)
rd_sensor_dsp_fp
#define ADC_PHOTO_VOLTS_TO_LUX
#define ADC_PHOTO_ENABLE_BYTE
#define ADC_PHOTO_USE_DIVIDER
rd_status_t ri_adc_photo_samplerate_set(uint8_t *samplerate)
rd_sensor_setup_fp
#define ADC_PHOTO_DEFAULT_BITFIELD
rd_status_t ri_adc_photo_resolution_set(uint8_t *resolution)
rd_sensor_setup_fp
rd_status_t ri_adc_photo_data_get(rd_sensor_data_t *const p_data)
rd_sensor_data_fp
#define ADC_PHOTO_USE_CHANNEL
#define ADC_PHOTO_DATA_COUNTER
rd_status_t ri_adc_photo_uninit(rd_sensor_t *sensor, rd_bus_t bus, uint8_t handle)
rd_sensor_init_fp
rd_status_t ri_adc_photo_mode_set(uint8_t *mode)
rd_sensor_setup_fp
unsigned int luminosity
Light level, dimensionless. Comparable only between identical devices.
Generic sensor data struct.
float * data
Data of sensor. Must contain as many elements as fields has bits set.
uint64_t timestamp_ms
Timestamp of the event, rd_sensor_timestamp_get.
rd_sensor_data_fields_t valid
Listing of valid data in this sample.
rd_sensor_data_fields_t fields
Description of datafields which may be contained in this sample.
Interface to sensor. Some sensors can implement additional functions. The additional functions are de...
rd_sensor_data_fp data_get
rd_sensor_data_fp
rd_configuration_fp configuration_set
rd_configuration_fp
rd_sensor_setup_fp samplerate_get
rd_sensor_setup_fp
rd_sensor_setup_fp resolution_get
rd_sensor_setup_fp
rd_sensor_init_fp uninit
rd_sensor_init_fp
rd_configuration_fp configuration_get
rd_configuration_fp
rd_sensor_dsp_fp dsp_get
rd_sensor_dsp_fp
rd_sensor_data_fields_t provides
Description of data fields the sensor is able to provide.
rd_sensor_dsp_fp dsp_set
rd_sensor_dsp_fp
rd_sensor_setup_fp mode_set
rd_sensor_setup_fp
const char * name
Sensor human-readable name. Should be at most 8 bytes long.
rd_sensor_setup_fp mode_get
rd_sensor_setup_fp
rd_sensor_setup_fp samplerate_set
rd_sensor_setup_fp
rd_sensor_init_fp init
rd_sensor_init_fp
rd_sensor_setup_fp scale_set
rd_sensor_setup_fp
rd_sensor_setup_fp resolution_set
rd_sensor_setup_fp
rd_sensor_setup_fp scale_get
rd_sensor_setup_fp
ri_adc_pin_config_t p_pin
Union to access sensor data.
uint32_t bitfield
Bitfield used to access sensor data.
rd_sensor_data_bitfield_t datas
Structured data field.