#include <stdio.h>
#include <string.h>
#include "board.h"
#include "bme280_wrapper.h"
#include "lis2dh12_wrapper.h"
#include "app_config.h"
#include "format_data.h"
#define SENSOR_DATA_DST_ENDPOINT 11
#define SENSOR_DATA_SRC_ENDPOINT 11
typedef enum
{
SENSOR_TASK_STATE_START_MEAS,
SENSOR_TASK_STATE_SEND_DATA
} sensor_task_state_e;
sensor_task_state_e m_task_state;
sensor_data_t m_sensor_data;
static bool ruuvi_spi_init(void)
{
{
return false;
}
return true;
}
static void send_data(sensor_data_t *data)
{
uint8_t buff[102];
int len = 102;
len = format_data_tlv(buff, data, len);
app_res_e res = lib_state->getRouteInfo(&route_info);
&& len != -1)
{
data_to_send.
bytes = (
const uint8_t *) buff;
lib_data->sendData(&data_to_send);
}
}
static uint32_t sensor_task()
{
const app_config_t * cfg = App_Config_get();
uint32_t time_to_run;
switch (m_task_state)
{
case SENSOR_TASK_STATE_START_MEAS:
{
m_task_state = SENSOR_TASK_STATE_SEND_DATA;
if(cfg->temperature_enable ||
cfg->humidity_enable ||
cfg->pressure_enable )
{
time_to_run = BME280_wrapper_startMeasurement();
}
if(cfg->accel_x_enable ||
cfg->accel_y_enable ||
cfg->accel_z_enable )
{
uint32_t lis2dh12_time_to_run;
lis2dh12_time_to_run = LIS2DH12_wrapper_startMeasurement();
if(lis2dh12_time_to_run > time_to_run)
{
time_to_run = lis2dh12_time_to_run;
}
}
break;
}
case SENSOR_TASK_STATE_SEND_DATA:
{
m_sensor_data.count++;
if (cfg->temperature_enable ||
cfg->humidity_enable ||
cfg->pressure_enable )
{
bme280_wrapper_measurement_t measurement;
BME280_wrapper_readMeasurement(&measurement);
m_sensor_data.temp = measurement.temperature;
m_sensor_data.press = measurement.pressure;
m_sensor_data.humi = measurement.humidity;
}
if(cfg->accel_x_enable ||
cfg->accel_y_enable ||
cfg->accel_z_enable )
{
lis2dh12_wrapper_measurement_t measurement;
LIS2DH12_wrapper_readMeasurement(&measurement);
m_sensor_data.acc_x = measurement.accel_x;
m_sensor_data.acc_y = measurement.accel_y;
m_sensor_data.acc_z = measurement.accel_z;
}
send_data(&m_sensor_data);
m_task_state = SENSOR_TASK_STATE_START_MEAS;
time_to_run = cfg->sensors_period_ms;
break;
}
default:
{
m_task_state = SENSOR_TASK_STATE_START_MEAS;
time_to_run = cfg->sensors_period_ms;
break;
}
}
return time_to_run;
}
static void on_config_update(void)
{
const app_config_t * cfg = App_Config_get();
if(cfg->sensors_period_ms == 0)
{
}
else
{
}
}
{
{
return;
}
m_sensor_data.count = 0;
m_task_state = SENSOR_TASK_STATE_START_MEAS;
App_Config_init(on_config_update);
ruuvi_spi_init();
BME280_wrapper_init();
LIS2DH12_wrapper_init();
lib_state->startStack();
}