mirror of
https://github.com/arendst/Tasmota.git
synced 2025-04-24 06:47:17 +00:00
Merge pull request #15217 from Staars/MI32
MI32: add Berry adv_watch and adv_block to BLE class
This commit is contained in:
commit
612c0262e7
@ -257,7 +257,9 @@ extern const bcstring be_const_str_add_header;
|
||||
extern const bcstring be_const_str_add_light;
|
||||
extern const bcstring be_const_str_add_rule;
|
||||
extern const bcstring be_const_str_addr;
|
||||
extern const bcstring be_const_str_adv_block;
|
||||
extern const bcstring be_const_str_adv_cb;
|
||||
extern const bcstring be_const_str_adv_watch;
|
||||
extern const bcstring be_const_str_allocated;
|
||||
extern const bcstring be_const_str_alternate;
|
||||
extern const bcstring be_const_str_animate;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,17 +1,19 @@
|
||||
#include "be_constobj.h"
|
||||
|
||||
static be_define_const_map_slots(be_class_BLE_map) {
|
||||
{ be_const_key(set_chr, -1), be_const_func(be_BLE_set_characteristic) },
|
||||
{ be_const_key(set_svc, -1), be_const_func(be_BLE_set_service) },
|
||||
{ be_const_key(run, -1), be_const_func(be_BLE_run) },
|
||||
{ be_const_key(conn_cb, 0), be_const_func(be_BLE_reg_conn_cb) },
|
||||
{ be_const_key(adv_cb, 1), be_const_func(be_BLE_reg_adv_cb) },
|
||||
{ be_const_key(adv_block, -1), be_const_func(be_BLE_adv_block) },
|
||||
{ be_const_key(conn_cb, -1), be_const_func(be_BLE_reg_conn_cb) },
|
||||
{ be_const_key(adv_cb, 5), be_const_func(be_BLE_reg_adv_cb) },
|
||||
{ be_const_key(set_MAC, -1), be_const_func(be_BLE_set_MAC) },
|
||||
{ be_const_key(adv_watch, -1), be_const_func(be_BLE_adv_watch) },
|
||||
{ be_const_key(run, -1), be_const_func(be_BLE_run) },
|
||||
{ be_const_key(set_svc, 4), be_const_func(be_BLE_set_service) },
|
||||
{ be_const_key(set_chr, 3), be_const_func(be_BLE_set_characteristic) },
|
||||
};
|
||||
|
||||
static be_define_const_map(
|
||||
be_class_BLE_map,
|
||||
6
|
||||
8
|
||||
);
|
||||
|
||||
BE_EXPORT_VARIABLE be_define_const_class(
|
||||
|
@ -32,6 +32,8 @@ extern int be_BLE_set_MAC(bvm *vm);
|
||||
extern int be_BLE_set_characteristic(bvm *vm);
|
||||
extern int be_BLE_run(bvm *vm);
|
||||
extern int be_BLE_set_service(bvm *vm);
|
||||
extern int be_BLE_adv_watch(bvm *vm);
|
||||
extern int be_BLE_adv_block(bvm *vm);
|
||||
|
||||
#include "be_fixed_be_class_BLE.h"
|
||||
|
||||
@ -43,7 +45,9 @@ class be_class_BLE (scope: global, name: BLE) {
|
||||
set_chr, func(be_BLE_set_characteristic)
|
||||
adv_cb, func(be_BLE_reg_adv_cb)
|
||||
set_MAC, func(be_BLE_set_MAC)
|
||||
adv_watch, func(be_BLE_adv_watch)
|
||||
adv_block, func(be_BLE_adv_block)
|
||||
}
|
||||
@const_object_info_end */
|
||||
|
||||
#endif //USE_MI_ESP32
|
||||
#endif //USE_MI_ESP32
|
@ -122,6 +122,8 @@ extern "C" {
|
||||
extern bool MI32setBerryCtxSvc(const char *Svc);
|
||||
extern bool MI32setBerryCtxChr(const char *Chr);
|
||||
extern bool MI32setBerryCtxMAC(uint8_t *MAC, uint8_t type);
|
||||
extern bool MI32addMACtoBlockList(uint8_t *MAC, uint8_t type);
|
||||
extern bool MI32addMACtoWatchList(uint8_t *MAC, uint8_t type);
|
||||
|
||||
|
||||
int be_BLE_reg_conn_cb(bvm *vm);
|
||||
@ -191,11 +193,40 @@ extern "C" {
|
||||
int be_BLE_run(bvm *vm);
|
||||
int be_BLE_run(bvm *vm){
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc == 2 && be_isint(vm, 2)) {
|
||||
if ((argc == 2) && be_isint(vm, 2)) {
|
||||
if (MI32runBerryConnection(be_toint(vm, 2))) be_return(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
int be_BLE_adv_block(bvm *vm);
|
||||
int be_BLE_adv_block(bvm *vm){
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc > 1 && be_isbytes(vm, 2)) {
|
||||
size_t len = 6;
|
||||
uint8_t type = 0;
|
||||
if(argc == 3 && be_isint(vm, 3)){
|
||||
type = be_toint(vm,3);
|
||||
}
|
||||
if(MI32addMACtoBlockList((uint8_t*)be_tobytes(vm, 2, &len),type)) be_return(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
int be_BLE_adv_watch(bvm *vm);
|
||||
int be_BLE_adv_watch(bvm *vm){
|
||||
int32_t argc = be_top(vm); // Get the number of arguments
|
||||
if (argc > 1 && be_isbytes(vm, 2)) {
|
||||
size_t len = 6;
|
||||
uint8_t type = 0;
|
||||
if(argc == 3 && be_isint(vm, 3)){
|
||||
type = be_toint(vm,3);
|
||||
}
|
||||
if (MI32addMACtoWatchList((uint8_t*)be_tobytes(vm, 2, &len),type)) be_return(vm);
|
||||
}
|
||||
be_raise(vm, kTypeError, nullptr);
|
||||
}
|
||||
|
||||
} //extern "C"
|
||||
|
||||
|
||||
@ -213,16 +244,18 @@ be_BLE_op:
|
||||
1 read
|
||||
2 write
|
||||
3 subscribe
|
||||
4 unsubscribe
|
||||
4 unsubscribe - maybe later
|
||||
5 disconnect
|
||||
|
||||
11 read once, then disconnect
|
||||
12 write once, then disconnect
|
||||
13 subscribe once, then disconnect
|
||||
14 unsubscribe once, then disconnect
|
||||
14 unsubscribe once, then disconnect - maybe later
|
||||
|
||||
BLE.conn_cb(cb,buffer)
|
||||
BLE.adv_cb(cb,buffer)
|
||||
BLE.adv_watch(MAC)
|
||||
BLE.adv_block(MAC)
|
||||
|
||||
MI32.devices()
|
||||
MI32.get_name(slot)
|
||||
@ -231,4 +264,4 @@ MI32.set_bat(slot,int)
|
||||
MI32.set_hum(slot,float)
|
||||
MI32.set_temp(slot,float)
|
||||
|
||||
*/
|
||||
*/
|
@ -22,6 +22,8 @@
|
||||
--------------------------------------------------------------------------------------------
|
||||
Version yyyymmdd Action Description
|
||||
--------------------------------------------------------------------------------------------
|
||||
0.9.5.4 20220325 changed - add Berry adv_watch and adv_block to BLE class
|
||||
-------
|
||||
0.9.5.3 20220315 changed - reworked Berry part, active scanning and holding active connections possible, new format of advertisement buffer
|
||||
-------
|
||||
0.9.5.1 20220209 changed - rename YEERC to YLYK01, add dimmer YLKG08 (incl. YLKG07), change button report scheme
|
||||
@ -707,6 +709,33 @@ extern "C" {
|
||||
MI32.beAdvBuf = buffer;
|
||||
}
|
||||
|
||||
bool MI32addMACtoBlockList(uint8_t *MAC, uint8_t type){
|
||||
NimBLEDevice::addIgnored(NimBLEAddress(MAC,type));
|
||||
return NimBLEDevice::isIgnored(NimBLEAddress(MAC,type));
|
||||
}
|
||||
|
||||
bool MI32addMACtoWatchList(uint8_t *MAC, uint8_t type){
|
||||
NimBLEAddress _newAddress = NimBLEAddress(MAC,type);
|
||||
if(MI32Scan==nullptr){
|
||||
if(!NimBLEDevice::whiteListAdd(_newAddress)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
bool _runningScan = MI32Scan->stop();
|
||||
if(NimBLEDevice::whiteListAdd(_newAddress)){
|
||||
MI32Scan->setFilterPolicy(BLE_HCI_SCAN_FILT_USE_WL);
|
||||
if(_runningScan) MI32Scan->start(0, MI32scanEndedCB, false);
|
||||
}
|
||||
else {
|
||||
if(_runningScan) MI32Scan->start(0, MI32scanEndedCB, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
AddLog(LOG_LEVEL_INFO,PSTR("M32: add %s to watchlist of size: %u"),_newAddress.toString().c_str(),NimBLEDevice::getWhiteListCount());
|
||||
return true;
|
||||
}
|
||||
|
||||
void MI32setBatteryForSlot(uint32_t slot, uint8_t value){
|
||||
if(slot>MIBLEsensors.size()-1) return;
|
||||
if(MIBLEsensors[slot].feature.bat){
|
||||
@ -1017,9 +1046,15 @@ void MI32ScanTask(void *pvParameters){
|
||||
MI32Scan->setInterval(70);
|
||||
MI32Scan->setWindow(50);
|
||||
MI32Scan->setAdvertisedDeviceCallbacks(&MI32ScanCallbacks,true);
|
||||
if(NimBLEDevice::getWhiteListCount()>0){
|
||||
MI32Scan->setFilterPolicy(BLE_HCI_SCAN_FILT_USE_WL);
|
||||
}
|
||||
else {
|
||||
MI32Scan->setFilterPolicy(BLE_HCI_SCAN_FILT_NO_WL);
|
||||
}
|
||||
MI32Scan->setActiveScan(MI32.option.activeScan);
|
||||
MI32Scan->setMaxResults(0);
|
||||
MI32Scan->start(0, MI32scanEndedCB, true); // never stop scanning, will pause automatically while connecting
|
||||
MI32Scan->start(0, MI32scanEndedCB, false); // never stop scanning, will pause automatically while connecting
|
||||
MI32.infoMsg = MI32_START_SCANNING;
|
||||
|
||||
uint32_t timer = 0;
|
||||
@ -2282,4 +2317,4 @@ bool Xsns62(uint8_t function)
|
||||
#endif // USE_MI_ESP32
|
||||
#endif // CONFIG_IDF_TARGET_ESP32 or CONFIG_IDF_TARGET_ESP32C3
|
||||
#endif // ESP32
|
||||
#endif // USE_BLE_ESP32
|
||||
#endif // USE_BLE_ESP32
|
Loading…
x
Reference in New Issue
Block a user