From 0e87096bade23a8e82552d45e78bfad965c00365 Mon Sep 17 00:00:00 2001 From: Christian Baars Date: Thu, 21 Dec 2023 20:28:08 +0100 Subject: [PATCH] allow Berry fast_loop for BLE module (#20281) --- lib/libesp32/berry_tasmota/src/be_MI32_lib.c | 4 +++ .../xdrv_52_3_berry_MI32.ino | 5 ++++ .../tasmota_xsns_sensor/xsns_62_esp32_mi.ino | 30 ++++++++++++------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/lib/libesp32/berry_tasmota/src/be_MI32_lib.c b/lib/libesp32/berry_tasmota/src/be_MI32_lib.c index 22c0a0bc6..e56ad7ae2 100644 --- a/lib/libesp32/berry_tasmota/src/be_MI32_lib.c +++ b/lib/libesp32/berry_tasmota/src/be_MI32_lib.c @@ -46,6 +46,9 @@ module MI32 (scope: global) { extern int be_BLE_init(bvm *vm); +extern void be_BLE_loop(void); +BE_FUNC_CTYPE_DECLARE(be_BLE_loop, "", ""); + extern void be_BLE_reg_conn_cb(void* function, uint8_t *buffer); BE_FUNC_CTYPE_DECLARE(be_BLE_reg_conn_cb, "", "cc"); @@ -79,6 +82,7 @@ BE_FUNC_CTYPE_DECLARE(be_BLE_adv_block, "", "@(bytes)~[i]"); /* @const_object_info_begin module BLE (scope: global) { init, func(be_BLE_init) + loop, ctype_func(be_BLE_loop) conn_cb, ctype_func(be_BLE_reg_conn_cb) set_svc, ctype_func(be_BLE_set_service) run, ctype_func(be_BLE_run) diff --git a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino index eb5e9ed33..27a8ed9ba 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_52_3_berry_MI32.ino @@ -76,6 +76,7 @@ extern "C" { ** BLE - generic BLE functions ********************************************************************/ extern bool MI32checkBLEinitialization(); + extern void MI32BerryLoop(); extern void MI32setBerryAdvCB(void* function, uint8_t *buffer); extern void MI32setBerryConnCB(void* function, uint8_t *buffer); extern void MI32setBerryServerCB(void* function, uint8_t *buffer); @@ -95,6 +96,10 @@ extern "C" { be_return_nil(vm); } + void be_BLE_loop(void){ + MI32BerryLoop(); + } + void be_BLE_reg_conn_cb(void* function, uint8_t *buffer); void be_BLE_reg_conn_cb(void* function, uint8_t *buffer){ MI32setBerryConnCB(function,buffer); diff --git a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino index c10a559c7..415b2b556 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_62_esp32_mi.ino @@ -707,6 +707,10 @@ extern "C" { return (MI32.mode.init && Settings->flag5.mi32_enable); } + void MI32BerryLoop(){ + MI32BLELoop(); + } + bool MI32runBerryServer(uint16_t operation, bool response){ MI32.conCtx->operation = operation; MI32.conCtx->response = response; @@ -1861,15 +1865,10 @@ void MI32ParseResponse(char *buf, uint16_t bufsize, uint8_t addr[6], int RSSI) { } /** - * @brief Launch functions from Core 1 to make race conditions less likely - * - */ - -void MI32Every50mSecond(){ - if(MI32.mode.shallTriggerTele){ - MI32.mode.shallTriggerTele = 0; - MI32triggerTele(); - } + * Called automatically every 50 milliseconds or can be triggered from Berry with BLE.loop() - useful from fast_loop +*/ +void MI32BLELoop() +{ if(MI32.mode.triggerBerryAdvCB == 1){ if(MI32.beAdvCB != nullptr){ // AddLogBuffer(LOG_LEVEL_DEBUG,MI32.beAdvBuf,40); @@ -1945,14 +1944,25 @@ void MI32Every50mSecond(){ } } } - if(MI32.infoMsg > 0){ char _message[32]; GetTextIndexed(_message, sizeof(_message), MI32.infoMsg-1, kMI32_BLEInfoMsg); AddLog(LOG_LEVEL_DEBUG,PSTR("M32: %s"),_message); MI32.infoMsg = 0; } +} +/** + * @brief Launch functions from Core 1 to make race conditions less likely + * + */ + +void MI32Every50mSecond(){ + if(MI32.mode.shallTriggerTele){ + MI32.mode.shallTriggerTele = 0; + MI32triggerTele(); + } + MI32BLELoop(); } /**