25#include "stm32_timer.h"
70 HAL_StatusTypeDef (*
Init)(I2C_HandleTypeDef *hi2c);
71 int8_t (*
Is)(I2C_HandleTypeDef *hi2c, int8_t tryInit);
72 HAL_StatusTypeDef (*
On)(I2C_HandleTypeDef *hi2c);
73 HAL_StatusTypeDef (*
Off)(I2C_HandleTypeDef *hi2c);
74 HAL_StatusTypeDef (*
Read)(I2C_HandleTypeDef *hi2c);
75 int8_t (*
Service)(I2C_HandleTypeDef *hi2c);
100#ifdef SENSOR_BAR_ILS22QS
104#ifdef SENSOR_AMB_TSL2591
108#ifdef SENSOR_BAR_BMP585
122static I2C_HandleTypeDef *
_hi2c = NULL;
156 va_start(argList, format);
177#define sensBuffer_Reset()
178#define sensBuffer_Add(format, ...)
179#define sensBuffer_Get() NULL
180#define sensBuffer_Send()
208 writeLog(
"Sensors:%s", (onOff ?
"On" :
"Off"));
209 for (i = 0; i < count; i++)
235 HAL_StatusTypeDef status;
240 for (i = 0; i < count; i++)
247 if (status == HAL_OK)
264 for (i = 0; i < count; i++)
275 uint8_t underService = 0;
277 for (i = 0; i < count; i++)
401 HAL_StatusTypeDef status;
408 for (i = 0; i < count; i++)
415 writeLog(
"%d. %s Init %s.", i, ((
_sensors[i].Name != NULL) ?
_sensors[i].Name :
"sensor"), ((status == HAL_OK) ?
"OK" :
"failed"));
419 writeLog(
"%d. sensor: Init is NULL", i);
452#ifdef SENSOR_AMB_TSL2591
455#ifdef SENSOR_BAR_ILS22QS
458#ifdef SENSOR_BAR_BMP585
471 uint8_t sz, channel = 1;
483#ifdef SENSOR_AMB_TSL2591
489#ifdef SENSOR_BAR_ILS22QS
496#ifdef SENSOR_BAR_BMP585
546#ifdef SENSOR_AMB_TSL2591
550#ifdef SENSOR_BAR_ILS22QS
554#ifdef SENSOR_BAR_BMP585
572 data->
Size = (uint8_t)off;
588#ifdef SENSOR_AMB_TSL2591
592#ifdef SENSOR_BAR_ILS22QS
596#ifdef SENSOR_BAR_BMP585
uint8_t CayenneLppAddTemperature(uint8_t channel, float celsius)
uint8_t * CayenneLppGetBuffer(void)
uint8_t CayenneLppAddConcentration(uint8_t channel, uint16_t ppm)
Add CO2 concentration data to the buffer.
uint8_t CayenneLppAddLuminosity(uint8_t channel, uint16_t lux)
uint8_t CayenneLppAddBarometricPressure(uint8_t channel, float hpa)
uint8_t CayenneLppAddVoltage(uint8_t channel, float voltage)
Add voltage data to the buffer.
void CayenneLppReset(void)
uint8_t CayenneLppAddParticulateMatter_1_0(uint8_t channel, float concentration_1_0)
Add particulate matter of 1mm concentration data to the buffer.
uint8_t CayenneLppAddParticulateMatter_2_5(uint8_t channel, float concentration_2_5)
Add particulate matter 2.5mm concentration data to the buffer.
uint8_t CayenneLppAddRelativeHumidity(uint8_t channel, float rh)
uint8_t CayenneLppGetSize(void)
uint8_t CayenneLppAddMeasureInterval(uint8_t channel, uint16_t min10)
Add the measure interval in minutes *10 of data measuring.
Implements the Cayenne Low Power Protocol.
Header for ADC interface configuration.
void amb_tsl2591_LogData(char *buf)
log data to buffer
amb_tsl2591_t _bck_amb_tsl2591Data
Snapshot copy of the last completed TSL2591 measurement; used for LoRaWAN transmission.
amb_tsl2591_t _amb_tsl2591Data
Live measurement data from the TSL2591 sensor; updated by amb_tsl2591_Read().
int8_t amb_tsl2591_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if light sensor is present
HAL_StatusTypeDef amb_tsl2591_Read(I2C_HandleTypeDef *hi2c)
read value from sensor, the value is in _ambientData
HAL_StatusTypeDef amb_tsl2591_Off(I2C_HandleTypeDef *hi2c)
turn off sensor
HAL_StatusTypeDef amb_tsl2591_On(I2C_HandleTypeDef *hi2c)
turn on sensor, read value 4x to automatically configure the sensor.
HAL_StatusTypeDef amb_tsl2591_Init(I2C_HandleTypeDef *hi2c)
initialization of light sensor, and check if sensor is present or not Subsequently the sensor is turn...
HAL_StatusTypeDef bar_bmp585_On(I2C_HandleTypeDef *hi2c)
Turn on sensor - wakeup the sensor and start to processing of pressure measure.
HAL_StatusTypeDef bar_bmp585_Off(I2C_HandleTypeDef *hi2c)
Turn off sensor - stop measure and put sensor in very deep sleep mode.
HAL_StatusTypeDef bar_bmp585_Read(I2C_HandleTypeDef *hi2c)
Read value from sensor, pressure and temperature. Sensor must be turned on before.
void bar_bmp585_LogData(char *buf)
Log data to buffer.
HAL_StatusTypeDef bar_bmp585_Init(I2C_HandleTypeDef *hi2c)
Initialize sensor, check if it really is this sensor. After check the sensor is turned off to save po...
bar_bmp585_t _bar_bmp585Data
Live measurement data from the BMP585 sensor; updated by bar_bmp585_Read().
bar_bmp585_t _bck_bar_bmp585Data
Snapshot copy of the last completed BMP585 measurement; used for LoRaWAN transmission.
int8_t bar_bmp585_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
Check if sensor is present.
int8_t bar_ils22qs_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
Check if the ILPS22QS barometric pressure sensor is present on the I2C bus.
HAL_StatusTypeDef bar_ils22qs_Init(I2C_HandleTypeDef *hi2c)
Initialise the ILPS22QS sensor and verify it is present on the I2C bus. The sensor is put into low-po...
HAL_StatusTypeDef bar_ils22qs_Read(I2C_HandleTypeDef *hi2c)
read value from sensor, pressure and temperature. Sensor must be turned on before
HAL_StatusTypeDef bar_ils22qs_On(I2C_HandleTypeDef *hi2c)
turn on sensor
void bar_ils22qs_LogData(char *buf)
log data to buffer
bar_ils22qs_t _bar_ils22qsData
Live measurement data from the ILPS22QS sensor; updated by bar_ils22qs_Read().
HAL_StatusTypeDef bar_ils22qs_Off(I2C_HandleTypeDef *hi2c)
turn off sensor
bar_ils22qs_t _bck_bar_ils22qsData
Snapshot copy of the last completed ILPS22QS measurement; used for LoRaWAN transmission.
This file contains all the function prototypes for the i2c.c file.
void MX_I2C2_Init(void)
Initialise the I2C2 peripheral (hi2c2) as configured by STM32CubeMX. Sets clock speed,...
void MX_I2C2_DeInit(void)
Deinitialise the I2C2 peripheral to reduce current consumption in low-power mode. Call before enterin...
: Header for main.c file. This file contains the common defines of the application.
void Error_Handler(void)
Default error handler called by HAL on unrecoverable errors. Disables interrupts and enters an infini...
void writeLog(const char *format,...)
Format and send a log message over UART (printf-style). Available only when WRITELOG is defined; comp...
void togle_LedOff(int off)
togle led
void writeLogNL(const char *buf)
Send a pre-formatted C string to the UART log followed by a newline.
static I2C_HandleTypeDef * _hi2c
static int getCount_GroupTiming()
sens_ReadingGrp_t
sensor groups for reading - the sensors in one group are read together This is necessary to processin...
static uint8_t sensors_NextGroup()
Move to next used group in _sensors[].
void sensors_Init(I2C_HandleTypeDef *hi2c)
Initialization of all sensors, must be called before for store of hi2c handler.
void sensors_WriteFromBckToDataBlock(mems_DataBlock_t *data)
filling the data block from sensor data - store to memory the methods works with _bck_XXXXX senzor,...
sens_ProcessDef_t sensors_Work()
no sequncer processing reading data from sensor according to group specification
void sensorsSeq_Init(uint32_t sensortAppBit, uint32_t mylorawanAppBit)
task sequencer initialization for sensors reading
void sensors_Start()
non squncer processing start of reading - prepare of internal state machine
uint8_t * sensors_CayennelFromBckData(uint8_t *sizeOut)
collecting sensor data into CayenneLppGetBuffer buffer for sending them via LoRa the methods works wi...
static void tasksensors_Work()
task sensor sequencer
void sensors_Retiming()
the System goes to OFF mode - retiming of timer sensor reading
static sens_ProcessDef_t _processDef
static void sensBuffer_Add(const char *format,...)
static uint32_t _mylorawanSeqID
static uint16_t _sensorMeasureTime
static void sensBuffer_Reset()
static const sens_GrpTiming_t _groupTiming[]
definition of sensors group
static int _groupReadCount
static void sensBuffer_Send()
static char _sensBuffer[1024]
static UTIL_TIMER_Object_t _sensorTimerReading
static char * sensBuffer_Get()
static void sensors_Read(sens_ReadingGrp_t grp)
reading sensor one by one in specified group
static int _groupInxTiming
static int getCount_Sensors()
static void tasksensors_OnTimeout()
void i2c_OnOff(uint8_t onOff)
possible to I2C turn on/off - cumulative
static sleeper_t _processDelay
static const sens_processing_t _sensors[]
static uint8_t sensors_Service()
void sensors_CopyToBck()
The copying data from current sensors buffer to backUp - _bck_XXXXX.
static uint32_t _sensorSeqID
uint8_t sensors_ReadToBckFromDataBlock(const mems_DataBlock_t *data)
reading from memory block and filling specified sensor from memory - ready for sensors_CayennelData t...
static int sensors_OnOff(sens_ReadingGrp_t grp, int onOff)
On/Off sensors according to group.
sens_ProcessDef_t
State machine states for the sensor reading process.
systemParams_t _systemParams
systemParams_Sensors_t
Bitmask of sensor modules that are enabled / available for data collection. Used in systemParams_t....
#define SENSORS_DATASIZE
Total size in bytes of one packed sensor data record. Computed as the sum of all enabled sensor struc...
uint8_t systemParams_IsSensorAvaiable(systemParams_Sensors_t sensorType)
Check whether a particular sensor is enabled in _systemParams.AvailableSensors.
HAL_StatusTypeDef scd41_Off(I2C_HandleTypeDef *hi2c)
stop reading
void scd41_LogData(char *buf)
log data to buffer
HAL_StatusTypeDef scd41_Init(I2C_HandleTypeDef *hi2c)
initialization of sensor sdc41
scd41_t _scd41Data
Live measurement data from the SCD41 sensor; updated by scd41_Read().
HAL_StatusTypeDef scd41_Read(I2C_HandleTypeDef *hi2c)
read value from sensor
HAL_StatusTypeDef scd41_On(I2C_HandleTypeDef *hi2c)
start reading - turn on sensor, reading mode can be: SCD41_CMD_START_PERIODIC - every 5s - this is pr...
int8_t scd41_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if CO2 sensor is present
scd41_t _bck_scd41Data
Snapshot copy of the last completed measurement; used for LoRaWAN transmission.
sps30_t _bck_sps30Data
Snapshot copy of the last completed SPS30 measurement; used for LoRaWAN transmission.
HAL_StatusTypeDef sps30_Read(I2C_HandleTypeDef *hi2c)
Read data if data is available.
void sps30_LogData(char *buf)
log data to buffer
HAL_StatusTypeDef sps30_Off(I2C_HandleTypeDef *hi2c)
Turn off laser and fan to stop measurements.
int8_t sps30_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if SPS30 sensor is present
int8_t sps30_Service(I2C_HandleTypeDef *hi2c)
the sensor need to be cleaning
HAL_StatusTypeDef sps30_Init(I2C_HandleTypeDef *hi2c)
initialization of sensor sps30
HAL_StatusTypeDef sps30_On(I2C_HandleTypeDef *hi2c)
Turn on laser and fan to allow measurements.
sps30_t _sps30Data
Live measurement data from the SPS30 sensor; updated by sps30_Read().
Sensor data record stored as one element in the flash circular queue.
uint8_t Data[(sizeof(uint16_t)+sizeof(tmphm_sht45_t)+sizeof(amb_tsl2591_t)+sizeof(bar_ils22qs_t)+sizeof(bar_bmp585_t)+sizeof(scd41_t)+sizeof(sps30_t))]
the definition for group of sensor sens_ReadingGrp_t the number of readings and timeout for reading d...
sensor definition - interface
int8_t(* Is)(I2C_HandleTypeDef *hi2c, int8_t tryInit)
HAL_StatusTypeDef(* Read)(I2C_HandleTypeDef *hi2c)
systemParams_Sensors_t Type
int8_t(* Service)(I2C_HandleTypeDef *hi2c)
sens_GrpTiming_t GroupTiming
HAL_StatusTypeDef(* Off)(I2C_HandleTypeDef *hi2c)
HAL_StatusTypeDef(* Init)(I2C_HandleTypeDef *hi2c)
HAL_StatusTypeDef(* On)(I2C_HandleTypeDef *hi2c)
void(* LogData)(char *buf)
Non-blocking timer utility – similar to HAL_Delay but without CPU blocking.
Function prototypes for sys_app.c file.
uint8_t GetBatteryLevel(void)
callback to get the battery level in % of full charge (254 full charge, 0 no charge)
HAL_StatusTypeDef tmphm_sht45_On(I2C_HandleTypeDef *hi2c)
Zapnutie sensora dummy.
HAL_StatusTypeDef tmphm_sht45_Init(I2C_HandleTypeDef *hi2c)
initialization, check if sensor is present or not. Checks main (0x44) and alternative address (0x45) ...
HAL_StatusTypeDef tmphm_sht45_Read(I2C_HandleTypeDef *hi2c)
read temperature and humidity from sensor, values are in _tempHumData
void tmphm_sht45_LogData(char *buf)
log data to buffer
tmphm_sht45_t _bck_tmphm_sht45Data
Snapshot copy of the last completed SHT45 measurement; used for LoRaWAN transmission.
HAL_StatusTypeDef tmphm_sht45_Off(I2C_HandleTypeDef *hi2c)
turn off sensor - dummy
tmphm_sht45_t _tmphm_sht45Data
Live measurement data from the SHT45 sensor; updated by tmphm_sht45_Read().
int8_t tmphm_sht45_Is(I2C_HandleTypeDef *hi2c, int8_t tryInit)
check if tempHum sensor is present
void sleeper_SetSleepMS(sleeper_t *v, uint32_t sleepMS)
Change the sleep duration and restart the timer from now.
void sleeper_Next(sleeper_t *v)
Restart the timer so the next period begins from now. InicTime is updated to the current HAL tick.
int sleeper_IsElapsed(const sleeper_t *v)
Check whether the configured time interval has elapsed.