Now runs on idf5 and you can start and stop the stack!
This commit is contained in:
parent
8cafd558e4
commit
3e4dd23f90
|
@ -77,14 +77,14 @@ static const char *gadget_name;
|
||||||
static uint8_t *gadget_mfg;
|
static uint8_t *gadget_mfg;
|
||||||
static size_t gadget_mfg_len;
|
static size_t gadget_mfg_len;
|
||||||
|
|
||||||
|
static ble_uuid_t *cud_uuid = BLE_UUID16_DECLARE(0x2901);
|
||||||
|
|
||||||
static const struct ble_gatt_svc_def *gatt_svr_svcs;
|
static const struct ble_gatt_svc_def *gatt_svr_svcs;
|
||||||
static const uint16_t *notify_handles;
|
static const uint16_t *notify_handles;
|
||||||
|
|
||||||
static task_handle_t task_handle;
|
static task_handle_t task_handle;
|
||||||
static QueueHandle_t response_queue;
|
static QueueHandle_t response_queue;
|
||||||
|
|
||||||
static bool already_inited;
|
|
||||||
|
|
||||||
static int struct_pack_index;
|
static int struct_pack_index;
|
||||||
static int struct_unpack_index;
|
static int struct_unpack_index;
|
||||||
|
|
||||||
|
@ -588,9 +588,7 @@ lble_build_gatt_svcs(lua_State *L, struct ble_gatt_svc_def **resultp, const uint
|
||||||
|
|
||||||
chr->descriptors = dsc;
|
chr->descriptors = dsc;
|
||||||
|
|
||||||
dsc->uuid = (const ble_uuid_t*)(ble_uuid16_t[]) {
|
dsc->uuid = cud_uuid;
|
||||||
BLE_UUID16_INIT(0x2901)
|
|
||||||
};
|
|
||||||
dsc->att_flags = BLE_ATT_F_READ;
|
dsc->att_flags = BLE_ATT_F_READ;
|
||||||
dsc->access_cb = lble_access_cb;
|
dsc->access_cb = lble_access_cb;
|
||||||
dsc->arg = chr->arg;
|
dsc->arg = chr->arg;
|
||||||
|
@ -666,6 +664,8 @@ lble_sys_init(lua_State *L) {
|
||||||
task_handle = task_get_id(lble_task_cb);
|
task_handle = task_get_id(lble_task_cb);
|
||||||
response_queue = xQueueCreate(2, sizeof(response_message_t));
|
response_queue = xQueueCreate(2, sizeof(response_message_t));
|
||||||
|
|
||||||
|
esp_log_level_set("NimBLE", ESP_LOG_WARN);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -678,15 +678,6 @@ lble_host_task(void *param)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
lble_init_stack(lua_State *L) {
|
lble_init_stack(lua_State *L) {
|
||||||
static char stack_inited;
|
|
||||||
if (!stack_inited) {
|
|
||||||
stack_inited = 1;
|
|
||||||
int ret = esp_nimble_hci_and_controller_init();
|
|
||||||
if (ret != ESP_OK) {
|
|
||||||
luaL_error(L, "esp_nimble_hci_and_controller_init() failed with error: %d", ret);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
nimble_port_init();
|
nimble_port_init();
|
||||||
|
|
||||||
|
@ -994,10 +985,6 @@ static int lble_init(lua_State *L) {
|
||||||
if (inited != STOPPED) {
|
if (inited != STOPPED) {
|
||||||
return luaL_error(L, "ble is already running");
|
return luaL_error(L, "ble is already running");
|
||||||
}
|
}
|
||||||
if (already_inited) {
|
|
||||||
return luaL_error(L, "Can only call ble.init once. Internal stack problem.");
|
|
||||||
}
|
|
||||||
already_inited = true;
|
|
||||||
if (!struct_pack_index) {
|
if (!struct_pack_index) {
|
||||||
lua_getglobal(L, "struct");
|
lua_getglobal(L, "struct");
|
||||||
lua_getfield(L, -1, "pack");
|
lua_getfield(L, -1, "pack");
|
||||||
|
@ -1066,10 +1053,6 @@ static int lble_init(lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int lble_shutdown(lua_State *L) {
|
static int lble_shutdown(lua_State *L) {
|
||||||
// It seems that shutting down the stack corrupts some critical data structures
|
|
||||||
// so, for now, don't allow it.
|
|
||||||
luaL_error(L, "Shutting down the BLE stack is currently not possible");
|
|
||||||
|
|
||||||
inited = SHUTTING;
|
inited = SHUTTING;
|
||||||
|
|
||||||
ble_gap_adv_stop();
|
ble_gap_adv_stop();
|
||||||
|
@ -1080,10 +1063,6 @@ static int lble_shutdown(lua_State *L) {
|
||||||
|
|
||||||
nimble_port_deinit();
|
nimble_port_deinit();
|
||||||
|
|
||||||
if (ESP_OK != esp_nimble_hci_and_controller_deinit()) {
|
|
||||||
return luaL_error(L, "Failed to shutdown the BLE controller");
|
|
||||||
}
|
|
||||||
|
|
||||||
inited = STOPPED;
|
inited = STOPPED;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -11,10 +11,6 @@ This allows you to build simple gadgets that can be interrogated and controlled
|
||||||
This initializes the Bluetooth stack and starts advertising according to the data in the
|
This initializes the Bluetooth stack and starts advertising according to the data in the
|
||||||
configuration table. See below for a detailed description of this table.
|
configuration table. See below for a detailed description of this table.
|
||||||
|
|
||||||
At the present time, you can only call the `init` function once. There is some problem
|
|
||||||
in the underlying implementation of the BLE stack that prevents a `init`, `shutdown`, `init`
|
|
||||||
sequence from working.
|
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`ble.init(ble_config)`
|
`ble.init(ble_config)`
|
||||||
|
|
||||||
|
@ -65,7 +61,7 @@ Updates the advertising data field for future advertising frames.
|
||||||
|
|
||||||
#### Parameters
|
#### Parameters
|
||||||
|
|
||||||
- `advertisement` This string will be placed in future advertising frames as the manufacturer data field. This overrides the a`advertisement` value from the config block.
|
- `advertisement` This string will be placed in future advertising frames as the manufacturer data field. This overrides the `advertisement` value from the config block.
|
||||||
|
|
||||||
#### Returns
|
#### Returns
|
||||||
`nil`
|
`nil`
|
||||||
|
@ -77,8 +73,7 @@ ble.advertise("foo")
|
||||||
|
|
||||||
## ble.shutdown()
|
## ble.shutdown()
|
||||||
|
|
||||||
Shuts down the Bluetooth controller and returns it to the state where another `init` ought to work (but currently doesn't). And, at the moment, shutting
|
Shuts down the Bluetooth controller and returns it to the state where another `init` ought to work.
|
||||||
it down doesn't work either -- it appears to corrupt some deep data structures.
|
|
||||||
|
|
||||||
#### Syntax
|
#### Syntax
|
||||||
`ble.shutdown()`
|
`ble.shutdown()`
|
||||||
|
@ -153,4 +148,4 @@ end
|
||||||
|
|
||||||
### Type conversions
|
### Type conversions
|
||||||
|
|
||||||
If the `type` value converts a single item, then that will be the value that is placed into the `value` element. If it converts multiple elements, then the elements will be placed into an array that that will be plaed into the `value` element.
|
If the `type` value converts a single item, then that will be the value that is placed into the `value` element. If it converts multiple elements, then the elements will be placed into an array that that will be placed into the `value` element.
|
||||||
|
|
Loading…
Reference in New Issue