|
|
|
@ -1,8 +1,3 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021 Nordic Semiconductor ASA
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
|
#include <zephyr/drivers/sensor.h>
|
|
|
|
|
#include <zephyr/logging/log.h>
|
|
|
|
@ -12,74 +7,74 @@
|
|
|
|
|
|
|
|
|
|
#include <app_version.h>
|
|
|
|
|
|
|
|
|
|
#include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
|
#include <zephyr/bluetooth/hci.h>
|
|
|
|
|
// #include <zephyr/bluetooth/bluetooth.h>
|
|
|
|
|
// #include <zephyr/bluetooth/hci.h>
|
|
|
|
|
|
|
|
|
|
LOG_MODULE_REGISTER(main, CONFIG_APP_LOG_LEVEL);
|
|
|
|
|
|
|
|
|
|
#define BLINK_PERIOD_MS_STEP 100U
|
|
|
|
|
#define BLINK_PERIOD_MS_MAX 1000U
|
|
|
|
|
|
|
|
|
|
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
|
|
|
|
|
#define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
|
|
|
|
|
// #define DEVICE_NAME CONFIG_BT_DEVICE_NAME
|
|
|
|
|
// #define DEVICE_NAME_LEN (sizeof(DEVICE_NAME) - 1)
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Set Advertisement data. Based on the Eddystone specification:
|
|
|
|
|
* https://github.com/google/eddystone/blob/master/protocol-specification.md
|
|
|
|
|
* https://github.com/google/eddystone/tree/master/eddystone-url
|
|
|
|
|
*/
|
|
|
|
|
static const struct bt_data ad[] = {
|
|
|
|
|
BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
|
|
|
|
|
BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0xaa, 0xfe),
|
|
|
|
|
BT_DATA_BYTES(BT_DATA_SVC_DATA16,
|
|
|
|
|
0xaa, 0xfe, /* Eddystone UUID */
|
|
|
|
|
0x10, /* Eddystone-URL frame type */
|
|
|
|
|
0x00, /* Calibrated Tx power at 0m */
|
|
|
|
|
0x00, /* URL Scheme Prefix http://www. */
|
|
|
|
|
'z', 'e', 'p', 'h', 'y', 'r',
|
|
|
|
|
'p', 'r', 'o', 'j', 'e', 'c', 't',
|
|
|
|
|
0x08) /* .org */
|
|
|
|
|
};
|
|
|
|
|
// /*
|
|
|
|
|
// * Set Advertisement data. Based on the Eddystone specification:
|
|
|
|
|
// * https://github.com/google/eddystone/blob/master/protocol-specification.md
|
|
|
|
|
// * https://github.com/google/eddystone/tree/master/eddystone-url
|
|
|
|
|
// */
|
|
|
|
|
// static const struct bt_data ad[] = {
|
|
|
|
|
// BT_DATA_BYTES(BT_DATA_FLAGS, BT_LE_AD_NO_BREDR),
|
|
|
|
|
// BT_DATA_BYTES(BT_DATA_UUID16_ALL, 0xaa, 0xfe),
|
|
|
|
|
// BT_DATA_BYTES(BT_DATA_SVC_DATA16,
|
|
|
|
|
// 0xaa, 0xfe, /* Eddystone UUID */
|
|
|
|
|
// 0x10, /* Eddystone-URL frame type */
|
|
|
|
|
// 0x00, /* Calibrated Tx power at 0m */
|
|
|
|
|
// 0x00, /* URL Scheme Prefix http://www. */
|
|
|
|
|
// 'z', 'e', 'p', 'h', 'y', 'r',
|
|
|
|
|
// 'p', 'r', 'o', 'j', 'e', 'c', 't',
|
|
|
|
|
// 0x08) /* .org */
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
/* Set Scan Response data */
|
|
|
|
|
static const struct bt_data sd[] = {
|
|
|
|
|
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
|
|
|
|
|
};
|
|
|
|
|
// /* Set Scan Response data */
|
|
|
|
|
// static const struct bt_data sd[] = {
|
|
|
|
|
// BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
static void bt_ready(int err)
|
|
|
|
|
{
|
|
|
|
|
char addr_s[BT_ADDR_LE_STR_LEN];
|
|
|
|
|
bt_addr_le_t addr = {0};
|
|
|
|
|
size_t count = 1;
|
|
|
|
|
// static void bt_ready(int err)
|
|
|
|
|
// {
|
|
|
|
|
// char addr_s[BT_ADDR_LE_STR_LEN];
|
|
|
|
|
// bt_addr_le_t addr = {0};
|
|
|
|
|
// size_t count = 1;
|
|
|
|
|
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERR("Bluetooth init failed (err %d)", err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// if (err)
|
|
|
|
|
// {
|
|
|
|
|
// LOG_ERR("Bluetooth init failed (err %d)", err);
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
LOG_INF("Bluetooth initialized");
|
|
|
|
|
// LOG_INF("Bluetooth initialized");
|
|
|
|
|
|
|
|
|
|
// Start advertising
|
|
|
|
|
err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
|
|
|
|
|
sd, ARRAY_SIZE(sd));
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERR("Advertising failed to start (err %d)", err);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// // Start advertising
|
|
|
|
|
// err = bt_le_adv_start(BT_LE_ADV_NCONN_IDENTITY, ad, ARRAY_SIZE(ad),
|
|
|
|
|
// sd, ARRAY_SIZE(sd));
|
|
|
|
|
// if (err)
|
|
|
|
|
// {
|
|
|
|
|
// LOG_ERR("Advertising failed to start (err %d)", err);
|
|
|
|
|
// return;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/* For connectable advertising you would use
|
|
|
|
|
* bt_le_oob_get_local(). For non-connectable non-identity
|
|
|
|
|
* advertising an non-resolvable private address is used;
|
|
|
|
|
* there is no API to retrieve that.
|
|
|
|
|
*/
|
|
|
|
|
// /* For connectable advertising you would use
|
|
|
|
|
// * bt_le_oob_get_local(). For non-connectable non-identity
|
|
|
|
|
// * advertising an non-resolvable private address is used;
|
|
|
|
|
// * there is no API to retrieve that.
|
|
|
|
|
// */
|
|
|
|
|
|
|
|
|
|
bt_id_get(&addr, &count);
|
|
|
|
|
bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s));
|
|
|
|
|
// bt_id_get(&addr, &count);
|
|
|
|
|
// bt_addr_le_to_str(&addr, addr_s, sizeof(addr_s));
|
|
|
|
|
|
|
|
|
|
LOG_INF("Beacon started, advertising as %s", addr_s);
|
|
|
|
|
}
|
|
|
|
|
// LOG_INF("Beacon started, advertising as %s", addr_s);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
int main(void)
|
|
|
|
|
{
|
|
|
|
@ -112,12 +107,12 @@ int main(void)
|
|
|
|
|
LOG_INF("Starting Mellifera version %s...", APP_VERSION_STRING);
|
|
|
|
|
// LOG_INF("Board: %s", BOARD);
|
|
|
|
|
|
|
|
|
|
// Initialize the Bluetooth Subsystem
|
|
|
|
|
err = bt_enable(bt_ready);
|
|
|
|
|
if (err)
|
|
|
|
|
{
|
|
|
|
|
LOG_ERR("Bluetooth init failed (err %d)", err);
|
|
|
|
|
}
|
|
|
|
|
// // Initialize the Bluetooth Subsystem
|
|
|
|
|
// err = bt_enable(bt_ready);
|
|
|
|
|
// if (err)
|
|
|
|
|
// {
|
|
|
|
|
// LOG_ERR("Bluetooth init failed (err %d)", err);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
display = DEVICE_DT_GET(DT_CHOSEN(zephyr_display));
|
|
|
|
|
if (!device_is_ready(display))
|
|
|
|
@ -148,7 +143,7 @@ int main(void)
|
|
|
|
|
display_blanking_off(display);
|
|
|
|
|
|
|
|
|
|
x_res = cfb_get_display_parameter(display, CFB_DISPLAY_WIDTH);
|
|
|
|
|
y_res = cfb_get_display_parameter(display, CFB_DISPLAY_HEIGH);
|
|
|
|
|
y_res = cfb_get_display_parameter(display, CFB_DISPLAY_HEIGHT);
|
|
|
|
|
rows = cfb_get_display_parameter(display, CFB_DISPLAY_ROWS);
|
|
|
|
|
ppt = cfb_get_display_parameter(display, CFB_DISPLAY_PPT);
|
|
|
|
|
|
|
|
|
|