add watch and block, code changes only

This commit is contained in:
Staars 2022-03-25 10:15:58 +01:00
parent 40d231875f
commit cf80b826ac
3 changed files with 79 additions and 7 deletions

View File

@ -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

View File

@ -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)
*/
*/

View File

@ -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