#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();
}
app_scheduler_res_e App_Scheduler_addTask_execTime(task_cb_f cb, uint32_t delay_ms, uint32_t exec_time_us)
Add a task.
app_scheduler_res_e App_Scheduler_cancelTask(task_cb_f cb)
Cancel a task.
#define APP_SCHEDULER_SCHEDULE_ASAP
Value to return from task or as initial time to be executed ASAP.
Board-independent GPIO functions.
gpio_res_e Gpio_outputSetCfg(gpio_id_t id, const gpio_out_cfg_t *out_cfg)
Configure a GPIO as an output GPIO.
@ GPIO_OUT_MODE_PUSH_PULL
gpio_out_mode_cfg_e out_mode_cfg
GPIO output configuration.
__STATIC_INLINE app_res_e configureNodeFromBuildParameters()
Wrapper on top of configureNode to get parameters from build system and hardcoded values from chip (f...
#define BOARD_GPIO_ID_BME280_SPI_CS
#define BOARD_GPIO_ID_LIS2DX12_SPI_CS
Simple minimal SPI master driver It only manages one SPI instance at a time.
spi_bit_order_e bit_order
@ SPI_RES_ALREADY_INITIALIZED
spi_res_e SPI_init(spi_conf_t *conf_p)
Initialize SPI module.
Library to encode/decode buffers in TLV (Type Length Value) format.
List of global functions, passed to App_entrypoint()
@ APP_LIB_DATA_SEND_FLAG_NONE
#define APP_LIB_DATA_NO_TRACKING_ID
When sending data and no tracking of packet is requested, this ID may be used.
app_lib_data_tracking_id_t tracking_id
A struct for lib_data->sendData().
app_lib_state_route_state_e state
@ APP_LIB_STATE_ROUTE_STATE_VALID
Valid next hop / route.
Structure for route information.