Select Git revision
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
main.c 9.77 KiB
/*
* Copyright (c) 2023 Nordic Semiconductor ASA
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/bluetooth/bluetooth.h>
#include <zephyr/bluetooth/uuid.h>
//#################################################
#include <zephyr/drivers/adc.h>
#include <zephyr/kernel.h>
#include <stdio.h>
#include <stdint.h>
//------------------------------------------------
//------------------------------------------------
#include <zephyr/device.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/sensor.h>
//------------------------------------------------
//------------------------------------------------
/* ADC node from the devicetree. */
#define ADC_NODE DT_ALIAS(adc0)
/* Data of ADC device specified in devicetree. */
static const struct device *adc = DEVICE_DT_GET(ADC_NODE);
/* Configuration of the ADC channel */
static const struct adc_channel_cfg channel_cfg = {
.gain = ADC_GAIN_1_6,
.reference = ADC_REF_INTERNAL,
.acquisition_time = ADC_ACQ_TIME_DEFAULT,
.channel_id = 0,
.input_positive = SAADC_CH_PSELP_PSELP_VDD,
};
#define ADC_RESOLUTION 12
#define BUFFER_SIZE 1 /* We only need one sample */
static int16_t sample_buffer[BUFFER_SIZE];
//#################################################
#define SERVICE_DATA_LEN 15
#define SERVICE_UUID 0xfcd2 /* BTHome service UUID */
#define IDX_TEMPL 4 /* Index of lo byte of temp in service data*/
#define IDX_TEMPH 5 /* Index of hi byte of temp in service data*/
#define IDX_HUML 7 /* Index of lo byte of humidity in service data */
#define IDX_HUMH 8 /* Index of hi byte of humidity in service data */
#define IDX_PRESL 10 /* Index of lo byte of pressure in service data (in hPa */
#define IDX_PRESM 11 /* Index of hi byte of pressure in service data (in hPa)*/
#define IDX_PRESH 12 /* Index of hi byte of pressure in service data (in hPa) */
#define BAT 14 /* Index of hi byte of temp in service data*/
#define ADV_PARAM BT_LE_ADV_PARAM(BT_LE_ADV_OPT_USE_IDENTITY, \
BT_GAP_ADV_SLOW_INT_MIN, \
BT_GAP_ADV_SLOW_INT_MAX, NULL)
static uint8_t service_data[SERVICE_DATA_LEN] = {
BT_UUID_16_ENCODE(SERVICE_UUID),
0x40,
0x02, /* Temperature */
0xc4, /* Low byte */
0x00, /* High byte */
0x03, /* Humidity */
0xbf, /* 50.55% low byte*/
0x13, /* 50.55% high byte*/