Moved BLE stuff to src/ble/
This commit is contained in:
parent
3749d689ba
commit
597542649a
9 changed files with 87 additions and 31 deletions
3
code/nrf-connect/.gitignore
vendored
3
code/nrf-connect/.gitignore
vendored
|
|
@ -1 +1,2 @@
|
|||
build
|
||||
build
|
||||
build_*
|
||||
|
|
@ -4,10 +4,13 @@ find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
|||
|
||||
project(b_parasite)
|
||||
|
||||
include_directories(src)
|
||||
|
||||
target_sources(app PRIVATE
|
||||
src/main.c
|
||||
src/prst/shtc3.c
|
||||
src/prst/adc.c
|
||||
src/prst/led.c
|
||||
src/prst/button.c
|
||||
src/prst/ble/ble.c
|
||||
)
|
||||
|
|
|
|||
|
|
@ -9,4 +9,5 @@ CONFIG_BT_PERIPHERAL=y
|
|||
CONFIG_BT_DEBUG_LOG=y
|
||||
CONFIG_BT_DEVICE_NAME="para"
|
||||
# CONFIG_BT_SETTINGS=n
|
||||
# CONFIG_SETTINGS=n
|
||||
# CONFIG_SETTINGS=n
|
||||
CONFIG_BT_CTLR_TX_PWR_PLUS_8=y
|
||||
|
|
@ -1,54 +1,38 @@
|
|||
#include <logging/log.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
#include <zephyr/zephyr.h>
|
||||
|
||||
#include "prst/adc.h"
|
||||
#include "prst/ble/ble.h"
|
||||
#include "prst/button.h"
|
||||
#include "prst/data.h"
|
||||
#include "prst/led.h"
|
||||
#include "prst/macros.h"
|
||||
#include "prst/shtc3.h"
|
||||
|
||||
LOG_MODULE_REGISTER(main, LOG_LEVEL_DBG);
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME),
|
||||
};
|
||||
|
||||
static const struct bt_data sd[] = {
|
||||
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME),
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
RET_IF_ERR(prst_adc_init());
|
||||
RET_IF_ERR(prst_led_init());
|
||||
RET_IF_ERR(prst_button_init());
|
||||
RET_IF_ERR(prst_ble_init());
|
||||
|
||||
RET_IF_ERR(prst_led_flash(2));
|
||||
|
||||
prst_adc_read_t batt;
|
||||
prst_adc_soil_moisture_t soil;
|
||||
prst_adc_photo_sensor_t photo;
|
||||
RET_IF_ERR(prst_ble_adv_start());
|
||||
|
||||
RET_IF_ERR(bt_enable(/*bt_reader_cb_t=*/NULL));
|
||||
|
||||
if (IS_ENABLED(CONFIG_SETTINGS)) {
|
||||
RET_IF_ERR_MSG(settings_load(), "Error in settings_load()");
|
||||
}
|
||||
|
||||
RET_IF_ERR(
|
||||
bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd, ARRAY_SIZE(sd)));
|
||||
prst_sensors_t sensors;
|
||||
|
||||
while (true) {
|
||||
RET_IF_ERR(prst_adc_batt_read(&batt));
|
||||
RET_IF_ERR(prst_adc_soil_read(batt.voltage, &soil));
|
||||
RET_IF_ERR(prst_adc_photo_read(batt.voltage, &photo));
|
||||
RET_IF_ERR(prst_adc_batt_read(&sensors.batt));
|
||||
RET_IF_ERR(prst_adc_soil_read(sensors.batt.voltage, &sensors.soil));
|
||||
RET_IF_ERR(prst_adc_photo_read(sensors.batt.voltage, &sensors.photo));
|
||||
|
||||
LOG_INF("Batt: %d mV", batt.millivolts);
|
||||
LOG_INF("Soil: %.0f %% (%.3f mV)", 100 * soil.percentage,
|
||||
soil.adc_read.voltage);
|
||||
LOG_INF("Photo: %u lx (%.3f mV)", photo.brightness, soil.adc_read.voltage);
|
||||
LOG_INF("Batt: %d mV", sensors.batt.millivolts);
|
||||
LOG_INF("Soil: %.0f %% (%.3f mV)", 100 * sensors.soil.percentage,
|
||||
sensors.soil.adc_read.voltage);
|
||||
LOG_INF("Photo: %u lx (%.3f mV)", sensors.photo.brightness,
|
||||
sensors.soil.adc_read.voltage);
|
||||
k_msleep(500);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
code/nrf-connect/src/prst/ble/ble.c
Normal file
39
code/nrf-connect/src/prst/ble/ble.c
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
#include "ble.h"
|
||||
|
||||
#include <logging/log.h>
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/settings/settings.h>
|
||||
|
||||
#include "prst/macros.h"
|
||||
|
||||
LOG_MODULE_REGISTER(ble, LOG_LEVEL_DBG);
|
||||
|
||||
static const struct bt_data ad[] = {
|
||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
||||
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME),
|
||||
};
|
||||
|
||||
static const struct bt_data sd[] = {
|
||||
BT_DATA_BYTES(BT_DATA_NAME_COMPLETE, CONFIG_BT_DEVICE_NAME),
|
||||
};
|
||||
|
||||
int prst_ble_init() {
|
||||
RET_IF_ERR(bt_enable(/*bt_reader_cb_t=*/NULL));
|
||||
if (IS_ENABLED(CONFIG_SETTINGS)) {
|
||||
RET_IF_ERR_MSG(settings_load(), "Error in settings_load()");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int prst_ble_adv_start() {
|
||||
return bt_le_adv_start(BT_LE_ADV_CONN, ad, ARRAY_SIZE(ad), sd,
|
||||
ARRAY_SIZE(sd));
|
||||
}
|
||||
|
||||
int prst_ble_adv_stop() {
|
||||
return bt_le_adv_stop();
|
||||
}
|
||||
|
||||
int prst_ble_adv_set_data(const prst_sensors_t *sensors) {
|
||||
return 0;
|
||||
}
|
||||
11
code/nrf-connect/src/prst/ble/ble.h
Normal file
11
code/nrf-connect/src/prst/ble/ble.h
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#ifndef _PRST_BLE_BLE_H_
|
||||
#define _PRST_BLE_BLE_H_
|
||||
|
||||
#include "prst/data.h"
|
||||
|
||||
int prst_ble_init();
|
||||
int prst_ble_adv_start();
|
||||
int prst_ble_adv_stop();
|
||||
int prst_ble_adv_set_data(const prst_sensors_t *sensors);
|
||||
|
||||
#endif // _PRST_BLE_BLE_H_
|
||||
0
code/nrf-connect/src/prst/ble/encoding.c
Normal file
0
code/nrf-connect/src/prst/ble/encoding.c
Normal file
3
code/nrf-connect/src/prst/ble/encoding.h
Normal file
3
code/nrf-connect/src/prst/ble/encoding.h
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#ifndef _PRST_BLE_ENCODING_H_
|
||||
#define _PRST_BLE_ENCODING_H_
|
||||
#endif // _PRST_BLE_ENCODING_H_
|
||||
14
code/nrf-connect/src/prst/data.h
Normal file
14
code/nrf-connect/src/prst/data.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#ifndef _PRST_DATA_H_
|
||||
#define _PRST_DATA_H_
|
||||
|
||||
#include "prst/adc.h"
|
||||
#include "prst/shtc3.h"
|
||||
|
||||
typedef struct {
|
||||
prst_adc_soil_moisture_t soil;
|
||||
prst_adc_photo_sensor_t photo;
|
||||
prst_adc_read_t batt;
|
||||
prst_shtc3_read_t shtc3;
|
||||
} prst_sensors_t;
|
||||
|
||||
#endif // _PRST_DATA_H_
|
||||
Loading…
Add table
Reference in a new issue