some fixes

This commit is contained in:
sharandac
2020-08-13 01:17:42 +02:00
parent 4bb56c8b58
commit f5f6faa53f
11 changed files with 110 additions and 42 deletions

View File

@@ -53,16 +53,16 @@ class BleCtlServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
blectl_set_event( BLECTL_CONNECT );
statusbar_style_icon( STATUSBAR_BLUETOOTH, STATUSBAR_STYLE_WHITE );
Serial.printf("BLE connected\r\n");
log_i("BLE connected");
};
void onDisconnect(BLEServer* pServer) {
blectl_clear_event( BLECTL_CONNECT );
statusbar_style_icon( STATUSBAR_BLUETOOTH, STATUSBAR_STYLE_GRAY );
Serial.printf("BLE disconnected\r\n");
log_i("BLE disconnected");
delay(500);
pServer->getAdvertising()->start();
Serial.printf("BLE advertising...\r\n");
log_i("BLE advertising...");
}
};
@@ -72,29 +72,29 @@ class BleCtlServerCallbacks: public BLEServerCallbacks {
class BtlCtlSecurity : public BLESecurityCallbacks {
uint32_t onPassKeyRequest(){
Serial.printf("BLE: PassKeyRequest\r\n");
log_i("BLE: PassKeyRequest");
// TODO: when is this used?
return 123456;
}
void onPassKeyNotify(uint32_t pass_key){
blectl_set_event( BLECTL_PAIRING );
Serial.printf("Bluetooth Pairing Request\r\nPIN: %06d\r\n", pass_key);
log_i("Bluetooth Pairing Request\r\nPIN: %06d", pass_key);
}
bool onConfirmPIN(uint32_t pass_key){
Serial.printf("BLE: The passkey YES/NO number :%06d\r\n", pass_key);
log_i("BLE: The passkey YES/NO number :%06d", pass_key);
// vTaskDelay(5000);
// return true;
// TODO: when is this used?
return false;
}
bool onSecurityRequest(){
Serial.printf("BLE: SecurityRequest\r\n");
log_i("BLE: SecurityRequest");
// TODO: when is this used?
return true;
}
void onAuthenticationComplete( esp_ble_auth_cmpl_t cmpl ){
Serial.printf("Bluetooth pairing %s\r\n", cmpl.success ? "successful" : "unsuccessful");
log_i("Bluetooth pairing %s", cmpl.success ? "successful" : "unsuccessful");
if( cmpl.success ){
uint16_t length;
@@ -122,7 +122,7 @@ class BleCtlCallbacks : public BLECharacteristicCallbacks
for (int i = 0; i < rxValue.length(); i++) {
if (rxValue[i] == 0x10) {
if ( message.length() ) {
log_i("BLE: Discarding %d bytes\n", message.length());
log_i("BLE: Discarding %d bytes", message.length());
}
message.clear();
} else if (rxValue[i] == '\n') {
@@ -157,6 +157,8 @@ void blectl_setup( void ) {
esp_bt_controller_enable( ESP_BT_MODE_BLE );
esp_bt_controller_mem_release( ESP_BT_MODE_CLASSIC_BT );
esp_bt_mem_release( ESP_BT_MODE_CLASSIC_BT );
esp_bt_controller_mem_release( ESP_BT_MODE_IDLE );
esp_bt_mem_release( ESP_BT_MODE_IDLE );
// Create the BLE Device
// Name needs to match filter in Gadgetbridge's banglejs getSupportedType() function.
@@ -204,33 +206,41 @@ void blectl_setup( void ) {
pServer->getAdvertising()->setMinInterval( 100 );
pServer->getAdvertising()->setMaxInterval( 200 );
pServer->getAdvertising()->start();
Serial.printf("BLE advertising...\r\n");
log_i("BLE advertising...");
}
/*
*
*/
void blectl_set_event( EventBits_t bits ) {
portENTER_CRITICAL_ISR(&blectlMux);
portENTER_CRITICAL(&blectlMux);
xEventGroupSetBits( blectl_status, bits );
portEXIT_CRITICAL_ISR(&blectlMux);
portEXIT_CRITICAL(&blectlMux);
}
/*
*
*/
void blectl_clear_event( EventBits_t bits ) {
portENTER_CRITICAL_ISR(&blectlMux);
portENTER_CRITICAL(&blectlMux);
xEventGroupClearBits( blectl_status, bits );
portEXIT_CRITICAL_ISR(&blectlMux);
portEXIT_CRITICAL(&blectlMux);
}
/*
*
*/
EventBits_t blectl_get_event( EventBits_t bits ) {
portENTER_CRITICAL_ISR(&blectlMux);
portENTER_CRITICAL(&blectlMux);
EventBits_t temp = xEventGroupGetBits( blectl_status ) & bits;
portEXIT_CRITICAL_ISR(&blectlMux);
portEXIT_CRITICAL(&blectlMux);
return( temp );
}
void blectl_standby( void ) {
statusbar_style_icon( STATUSBAR_BLUETOOTH, STATUSBAR_STYLE_GRAY );
}
void blectl_wakeup( void ) {
statusbar_style_icon( STATUSBAR_BLUETOOTH, STATUSBAR_STYLE_GRAY );
}

View File

@@ -58,5 +58,7 @@
* @param bits event state, example: POWERMGM_STANDBY to evaluate if the system in standby
*/
EventBits_t blectl_get_event( EventBits_t bits );
void blectl_standby( void );
void blectl_wakeup( void );
#endif // _BLECTL_H

View File

@@ -124,6 +124,7 @@ void display_save_config( void ) {
doc["brightness"] = display_config.brightness;
doc["rotation"] = display_config.rotation;
doc["timeout"] = display_config.timeout;
doc["block_return_maintile"] = display_config.block_return_maintile;
if ( serializeJsonPretty( doc, file ) == 0) {
log_e("Failed to write config file");
@@ -154,6 +155,7 @@ void display_read_config( void ) {
display_config.brightness = doc["brightness"].as<uint32_t>();
display_config.rotation = doc["rotation"].as<uint32_t>();
display_config.timeout = doc["timeout"].as<uint32_t>();
display_config.block_return_maintile = doc["block_return_maintile"].as<bool>();
}
doc.clear();
}
@@ -203,6 +205,14 @@ uint32_t display_get_rotation( void ) {
return( display_config.rotation );
}
bool display_get_block_return_maintile( void ) {
return( display_config.block_return_maintile );
}
void display_set_block_return_maintile( bool block_return_maintile ) {
display_config.block_return_maintile = block_return_maintile;
}
void display_set_rotation( uint32_t rotation ) {
TTGOClass *ttgo = TTGOClass::getWatch();
display_config.rotation = rotation;

View File

@@ -35,6 +35,7 @@
uint32_t brightness = DISPLAY_MAX_BRIGHTNESS;
uint32_t timeout = DISPLAY_MIN_TIMEOUT;
uint32_t rotation = 0;
bool block_return_maintile = false;
} display_config_t;
#define DISPLAY_CONFIG_FILE "/display.cfg"
@@ -96,6 +97,18 @@
* @param rotation from 0-270 in 90 degree steps
*/
void display_set_rotation( uint32_t rotation );
/*
* @brief read the block_return_maintile while wakeup
*
* @param rotation from 0-270 in 90 degree steps
*/
bool display_get_block_return_maintile( void );
/*
* @brief set the block_return_maintile while wakeup
*
* @param block_return_maintile true or false, true means no autoreturn zu maintile
*/
void display_set_block_return_maintile( bool block_return_maintile );
/*
* @brief set display into standby
*/

View File

@@ -31,6 +31,7 @@
#include "bma.h"
#include "powermgm.h"
#include "wifictl.h"
#include "blectl.h"
#include "timesync.h"
#include "motor.h"
#include "touch.h"
@@ -84,6 +85,8 @@ void powermgm_loop( TTGOClass *ttgo ) {
timesyncToSystem();
wifictl_wakeup();
blectl_wakeup();
Serial.printf("Total heap: %d\r\n", ESP.getHeapSize());
Serial.printf("Free heap: %d\r\n", ESP.getFreeHeap());
Serial.printf("Total PSRAM: %d\r\n", ESP.getPsramSize());
@@ -91,6 +94,10 @@ void powermgm_loop( TTGOClass *ttgo ) {
ttgo->startLvglTick();
lv_disp_trig_activity(NULL);
if ( !display_get_block_return_maintile() ) {
mainbar_jump_to_maintile( LV_ANIM_OFF );
}
}
else {
ttgo->stopLvglTick();
@@ -100,19 +107,22 @@ void powermgm_loop( TTGOClass *ttgo ) {
Serial.printf("Total PSRAM: %d\r\n", ESP.getPsramSize());
Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());
display_standby();
mainbar_jump_to_maintile( LV_ANIM_OFF );
timesyncToRTC();
bma_standby();
pmu_standby();
wifictl_standby();
blectl_standby();
powermgm_set_event( POWERMGM_STANDBY );
powermgm_clear_event( POWERMGM_SILENCE_WAKEUP );
adc_power_off();
motor_vibe(1);
delay(50);
log_i("go standby");
setCpuFrequencyMhz( 80 );
@@ -135,26 +145,26 @@ void powermgm_loop( TTGOClass *ttgo ) {
*
*/
void powermgm_set_event( EventBits_t bits ) {
portENTER_CRITICAL_ISR(&powermgmMux);
portENTER_CRITICAL(&powermgmMux);
xEventGroupSetBits( powermgm_status, bits );
portEXIT_CRITICAL_ISR(&powermgmMux);
portEXIT_CRITICAL(&powermgmMux);
}
/*
*
*/
void powermgm_clear_event( EventBits_t bits ) {
portENTER_CRITICAL_ISR(&powermgmMux);
portENTER_CRITICAL(&powermgmMux);
xEventGroupClearBits( powermgm_status, bits );
portEXIT_CRITICAL_ISR(&powermgmMux);
portEXIT_CRITICAL(&powermgmMux);
}
/*
*
*/
EventBits_t powermgm_get_event( EventBits_t bits ) {
portENTER_CRITICAL_ISR(&powermgmMux);
portENTER_CRITICAL(&powermgmMux);
EventBits_t temp = xEventGroupGetBits( powermgm_status ) & bits;
portEXIT_CRITICAL_ISR(&powermgmMux);
portEXIT_CRITICAL(&powermgmMux);
return( temp );
}