added proximity code
This commit is contained in:
@@ -44,6 +44,7 @@ static lv_obj_t *statusbar_wifilabel = NULL;
|
||||
static lv_obj_t *statusbar_wifiiplabel = NULL;
|
||||
static lv_obj_t *statusbar_bluetooth = NULL;
|
||||
static lv_obj_t *statusbar_stepcounterlabel = NULL;
|
||||
static lv_obj_t *statusbar_tagRSSI = NULL;
|
||||
static lv_style_t statusbarstyle[ STATUSBAR_STYLE_NUM ];
|
||||
|
||||
lv_status_bar_t statusicon[ STATUSBAR_NUM ] =
|
||||
@@ -191,6 +192,16 @@ void statusbar_setup( void )
|
||||
lv_label_set_text(statusbar_stepcounterlabel, "0");
|
||||
lv_obj_align(statusbar_stepcounterlabel, statusbar_stepicon, LV_ALIGN_OUT_RIGHT_MID, 5, 0 );
|
||||
|
||||
statusbar_tagRSSI = lv_label_create(statusbar, NULL);
|
||||
lv_obj_reset_style_list( statusbar_tagRSSI, LV_OBJ_PART_MAIN );
|
||||
lv_obj_add_style( statusbar_tagRSSI, LV_OBJ_PART_MAIN, &statusbarstyle[ STATUSBAR_STYLE_WHITE ] );
|
||||
lv_label_set_text(statusbar_tagRSSI, "0");
|
||||
lv_obj_align(statusbar_tagRSSI, statusbar, LV_ALIGN_CENTER, -30, 0 );
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
statusbar_hide_icon( STATUSBAR_BELL );
|
||||
statusbar_hide_icon( STATUSBAR_WARNING );
|
||||
statusbar_hide_icon( STATUSBAR_WIFI );
|
||||
@@ -385,6 +396,15 @@ void statusbar_update_stepcounter( int step ) {
|
||||
snprintf( stepcounter, sizeof( stepcounter ), "%d", step );
|
||||
lv_label_set_text( statusbar_stepcounterlabel, (const char *)stepcounter );
|
||||
}
|
||||
|
||||
|
||||
void statusbar_update_rssi( int rssi ) {
|
||||
char rssidisplay[4]="";
|
||||
snprintf( rssidisplay, sizeof( rssidisplay ), "%d", rssi );
|
||||
lv_label_set_text( statusbar_tagRSSI, (const char *)rssidisplay );
|
||||
log_i("update rssi: %s",rssidisplay);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
|
||||
@@ -113,5 +113,7 @@
|
||||
*/
|
||||
void statusbar_hide( bool hide );
|
||||
|
||||
void statusbar_update_rssi( int rssi );
|
||||
|
||||
#endif // _STATUSBAR_H
|
||||
|
||||
|
||||
@@ -31,6 +31,9 @@
|
||||
#include <BLEServer.h>
|
||||
#include <BLEUtils.h>
|
||||
#include <BLE2902.h>
|
||||
#include <BLEAdvertisedDevice.h>
|
||||
#include <BLEscan.h>
|
||||
#include "hardware/motor.h"
|
||||
|
||||
#include "blectl.h"
|
||||
#include "json_psram_allocator.h"
|
||||
@@ -51,6 +54,15 @@ BLECharacteristic *pTxCharacteristic;
|
||||
BLECharacteristic *pRxCharacteristic;
|
||||
uint8_t txValue = 0;
|
||||
|
||||
//scan stuff
|
||||
BLEScan *pBLEScan = NULL;
|
||||
const int scantime = 1;
|
||||
const BLEAddress testmac = BLEAddress("ed:19:fd:19:43:0a");
|
||||
int currentRSSI = -99;
|
||||
bool deviceFound = false;
|
||||
const unsigned int bleNotfoundreload = 5;
|
||||
unsigned int bleNotfoundCountdown = bleNotfoundreload;
|
||||
|
||||
BLECharacteristic *pBatteryLevelCharacteristic;
|
||||
BLECharacteristic *pBatteryPowerStateCharacteristic;
|
||||
|
||||
@@ -210,6 +222,52 @@ class BleCtlCallbacks : public BLECharacteristicCallbacks
|
||||
};
|
||||
|
||||
|
||||
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
|
||||
void onResult(BLEAdvertisedDevice advertisedDevice) {
|
||||
if (advertisedDevice.getAddress().equals(testmac))
|
||||
{
|
||||
log_i("BLE Tag found, rssi: %i ", advertisedDevice.getRSSI());
|
||||
currentRSSI = advertisedDevice.getRSSI();
|
||||
deviceFound = true;
|
||||
bleNotfoundCountdown = bleNotfoundreload;
|
||||
statusbar_update_rssi(currentRSSI);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void myscanCompleteCB(BLEScanResults result)
|
||||
{
|
||||
if(!deviceFound )
|
||||
{
|
||||
currentRSSI = 0;
|
||||
if(!bleNotfoundCountdown--)
|
||||
{
|
||||
motor_vibe(10);
|
||||
}
|
||||
}
|
||||
deviceFound = false;
|
||||
pBLEScan->clearResults();
|
||||
pBLEScan->start(scantime,myscanCompleteCB,true);
|
||||
log_i("BLE scan re-started...");
|
||||
}
|
||||
|
||||
int blectl_get_tagRSSI( void ){
|
||||
log_i("Rssi requested %i",currentRSSI);
|
||||
return currentRSSI;
|
||||
}
|
||||
|
||||
void blectl_start_scan( void )
|
||||
{
|
||||
pBLEScan->start(scantime,myscanCompleteCB,true);
|
||||
log_i("BLE tag scan started...");
|
||||
}
|
||||
|
||||
void blectl_stop_scan( void )
|
||||
{
|
||||
pBLEScan->stop();
|
||||
log_i("BLE tag scan stopped.");
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@@ -231,6 +289,14 @@ void blectl_setup( void ) {
|
||||
// The minimum power level (-12dbm) ESP_PWR_LVL_N12 was too low
|
||||
BLEDevice::setPower( ESP_PWR_LVL_N9 );
|
||||
|
||||
// BLE scan
|
||||
pBLEScan = BLEDevice::getScan();
|
||||
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
|
||||
pBLEScan->setActiveScan(true);
|
||||
pBLEScan->setInterval(100);
|
||||
pBLEScan->setWindow(99);
|
||||
|
||||
|
||||
// Enable encryption
|
||||
BLEServer* pServer = BLEDevice::createServer();
|
||||
BLEDevice::setEncryptionLevel( ESP_BLE_SEC_ENCRYPT_NO_MITM );
|
||||
@@ -306,6 +372,8 @@ void blectl_setup( void ) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
@@ -386,13 +454,19 @@ void blectl_send_event_cb( EventBits_t event, char *msg ) {
|
||||
void blectl_standby( void ) {
|
||||
/*
|
||||
*/
|
||||
blectl_stop_scan();
|
||||
}
|
||||
|
||||
|
||||
void blectl_wakeup( void ) {
|
||||
/*
|
||||
*/
|
||||
blectl_start_scan();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void blectl_set_enable_on_standby( bool enable_on_standby ) {
|
||||
blectl_config.enable_on_standby = enable_on_standby;
|
||||
blectl_save_config();
|
||||
|
||||
@@ -122,4 +122,9 @@
|
||||
|
||||
void blectl_update_battery( int32_t percent, bool charging, bool plug );
|
||||
|
||||
int blectl_get_tagRSSI( void );
|
||||
void blectl_start_scan( void );
|
||||
void blectl_stop_scan( void );
|
||||
|
||||
|
||||
#endif // _BLECTL_H
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "json_psram_allocator.h"
|
||||
|
||||
#include "gui/statusbar.h"
|
||||
#include "hardware/blectl.h"
|
||||
|
||||
|
||||
EventGroupHandle_t bma_event_handle = NULL;
|
||||
bma_config_t bma_config[ BMA_CONFIG_NUM ];
|
||||
@@ -91,6 +93,8 @@ void bma_wakeup( void ) {
|
||||
|
||||
stepcounter_before_reset = ttgo->bma->getCounter();
|
||||
statusbar_update_stepcounter( stepcounter + ttgo->bma->getCounter() );
|
||||
statusbar_update_rssi( blectl_get_tagRSSI() );
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -138,6 +142,7 @@ void bma_loop( void ) {
|
||||
if ( !powermgm_get_event( POWERMGM_STANDBY ) && xEventGroupGetBitsFromISR( bma_event_handle ) & BMA_EVENT_INT ) {
|
||||
stepcounter_before_reset = ttgo->bma->getCounter();
|
||||
statusbar_update_stepcounter( stepcounter + ttgo->bma->getCounter() );
|
||||
statusbar_update_rssi(blectl_get_tagRSSI());
|
||||
xEventGroupClearBitsFromISR( bma_event_handle, BMA_EVENT_INT );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user