Replace the existing Apache 2.0 boilerplate header with an SPDX tag throughout the zephyr code tree. This patch was generated via a script run over the master branch. Also updated doc/porting/application.rst that had a dependency on line numbers in a literal include. Manually updated subsys/logging/sys_log.c that had a malformed header in the original file. Also cleanup several cases that already had a SPDX tag and we either got a duplicate or missed updating. Jira: ZEP-1457 Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c Signed-off-by: David B. Kinder <david.b.kinder@intel.com> Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
73 lines
1.6 KiB
C
73 lines
1.6 KiB
C
/** @file
|
|
* @brief BAS Service sample
|
|
*/
|
|
|
|
/*
|
|
* Copyright (c) 2016 Intel Corporation
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
#include <stdint.h>
|
|
#include <stddef.h>
|
|
#include <string.h>
|
|
#include <errno.h>
|
|
#include <misc/printk.h>
|
|
#include <misc/byteorder.h>
|
|
#include <zephyr.h>
|
|
|
|
#include <bluetooth/bluetooth.h>
|
|
#include <bluetooth/hci.h>
|
|
#include <bluetooth/conn.h>
|
|
#include <bluetooth/uuid.h>
|
|
#include <bluetooth/gatt.h>
|
|
|
|
static struct bt_gatt_ccc_cfg blvl_ccc_cfg[CONFIG_BLUETOOTH_MAX_PAIRED] = {};
|
|
static uint8_t simulate_blvl;
|
|
static uint8_t battery = 100;
|
|
|
|
static void blvl_ccc_cfg_changed(const struct bt_gatt_attr *attr,
|
|
uint16_t value)
|
|
{
|
|
simulate_blvl = (value == BT_GATT_CCC_NOTIFY) ? 1 : 0;
|
|
}
|
|
|
|
static ssize_t read_blvl(struct bt_conn *conn, const struct bt_gatt_attr *attr,
|
|
void *buf, uint16_t len, uint16_t offset)
|
|
{
|
|
const char *value = attr->user_data;
|
|
|
|
return bt_gatt_attr_read(conn, attr, buf, len, offset, value,
|
|
sizeof(*value));
|
|
}
|
|
|
|
/* Battery Service Declaration */
|
|
static struct bt_gatt_attr attrs[] = {
|
|
BT_GATT_PRIMARY_SERVICE(BT_UUID_BAS),
|
|
BT_GATT_CHARACTERISTIC(BT_UUID_BAS_BATTERY_LEVEL,
|
|
BT_GATT_CHRC_READ | BT_GATT_CHRC_NOTIFY),
|
|
BT_GATT_DESCRIPTOR(BT_UUID_BAS_BATTERY_LEVEL, BT_GATT_PERM_READ,
|
|
read_blvl, NULL, &battery),
|
|
BT_GATT_CCC(blvl_ccc_cfg, blvl_ccc_cfg_changed),
|
|
};
|
|
|
|
void bas_init(void)
|
|
{
|
|
bt_gatt_register(attrs, ARRAY_SIZE(attrs));
|
|
}
|
|
|
|
void bas_notify(void)
|
|
{
|
|
if (!simulate_blvl) {
|
|
return;
|
|
}
|
|
|
|
battery--;
|
|
if (!battery) {
|
|
/* Software eco battery charger */
|
|
battery = 100;
|
|
}
|
|
|
|
bt_gatt_notify(NULL, &attrs[2], &battery, sizeof(battery));
|
|
}
|