bt call and pairing dialog. powermgm refactoring

This commit is contained in:
sharandac
2020-08-14 15:40:34 +02:00
parent 174ab77d2f
commit 46122f4c1a
19 changed files with 1145 additions and 173 deletions

View File

@@ -49,7 +49,6 @@ portMUX_TYPE powermgmMux = portMUX_INITIALIZER_UNLOCKED;
void powermgm_setup( TTGOClass *ttgo ) {
powermgm_status = xEventGroupCreate();
xEventGroupClearBits( powermgm_status, POWERMGM_STANDBY | POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_SILENCE_WAKEUP | POWERMGM_SILENCE_WAKEUP_REQUEST );
pmu_setup( ttgo );
bma_setup( ttgo );
@@ -65,86 +64,92 @@ void powermgm_setup( TTGOClass *ttgo ) {
*/
void powermgm_loop( TTGOClass *ttgo ) {
// event-tripper pmu-button or pmu-battery state change
if ( powermgm_get_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP | POWERMGM_SILENCE_WAKEUP_REQUEST | POWERMGM_STANDBY_REQUEST ) ) {
// if we have an request when we are in silence mode, emulate an wakeup from standby
if ( powermgm_get_event( POWERMGM_SILENCE_WAKEUP ) && powermgm_get_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP ) ) {
powermgm_set_event( POWERMGM_STANDBY );
powermgm_clear_event( POWERMGM_SILENCE_WAKEUP );
// check if a button or doubleclick was release
if( powermgm_get_event( POWERMGM_PMU_BUTTON | POWERMGM_BMA_DOUBLECLICK ) ) {
if ( powermgm_get_event( POWERMGM_STANDBY ) || powermgm_get_event( POWERMGM_SILENCE_WAKEUP ) ) {
powermgm_set_event( POWERMGM_WAKEUP_REQUEST );
}
if ( powermgm_get_event( POWERMGM_STANDBY ) ) {
powermgm_clear_event( POWERMGM_STANDBY );
log_i("go wakeup");
setCpuFrequencyMhz(240);
pmu_wakeup();
bma_wakeup();
display_wakeup();
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());
Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());
ttgo->startLvglTick();
lv_disp_trig_activity(NULL);
if ( !display_get_block_return_maintile() ) {
mainbar_jump_to_maintile( LV_ANIM_OFF );
}
}
else {
ttgo->stopLvglTick();
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());
Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());
display_standby();
timesyncToRTC();
bma_standby();
pmu_standby();
wifictl_standby();
blectl_standby();
powermgm_set_event( POWERMGM_STANDBY );
powermgm_clear_event( POWERMGM_SILENCE_WAKEUP );
adc_power_off();
if ( !blectl_get_enable_on_standby() ) {
motor_vibe(3);
delay(50);
log_i("go standby");
setCpuFrequencyMhz( 10 );
gpio_wakeup_enable ( (gpio_num_t)AXP202_INT, GPIO_INTR_LOW_LEVEL );
gpio_wakeup_enable ( (gpio_num_t)BMA423_INT1, GPIO_INTR_HIGH_LEVEL );
esp_sleep_enable_gpio_wakeup ();
esp_light_sleep_start();
// from here, the consumption is round about 2.5mA
// total standby time is 152h (6days) without use?
}
else {
log_i("standby block by bluetooth");
setCpuFrequencyMhz( 80 );
// from here, the consumption is round about 23mA
// total standby time is 19h without use?
}
powermgm_set_event( POWERMGM_STANDBY_REQUEST );
}
// clear event
powermgm_clear_event( POWERMGM_PMU_BUTTON | POWERMGM_PMU_BATTERY | POWERMGM_BMA_WAKEUP | POWERMGM_STANDBY_REQUEST | POWERMGM_SILENCE_WAKEUP_REQUEST );
powermgm_clear_event( POWERMGM_PMU_BUTTON | POWERMGM_BMA_DOUBLECLICK );
}
// drive into
if ( powermgm_get_event( POWERMGM_SILENCE_WAKEUP_REQUEST | POWERMGM_WAKEUP_REQUEST ) ) {
powermgm_clear_event( POWERMGM_STANDBY | POWERMGM_SILENCE_WAKEUP );
log_i("go wakeup");
setCpuFrequencyMhz(240);
pmu_wakeup();
bma_wakeup();
display_wakeup( powermgm_get_event( POWERMGM_SILENCE_WAKEUP_REQUEST )?true:false );
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());
Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());
ttgo->startLvglTick();
lv_disp_trig_activity(NULL);
if ( powermgm_get_event( POWERMGM_SILENCE_WAKEUP_REQUEST ) ) {
powermgm_set_event( POWERMGM_SILENCE_WAKEUP );
}
}
else if( powermgm_get_event( POWERMGM_STANDBY_REQUEST ) ) {
powermgm_set_event( POWERMGM_STANDBY );
powermgm_clear_event( POWERMGM_SILENCE_WAKEUP );
if ( !display_get_block_return_maintile() ) {
mainbar_jump_to_maintile( LV_ANIM_OFF );
}
ttgo->stopLvglTick();
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());
Serial.printf("Free PSRAM: %d\r\n", ESP.getFreePsram());
display_standby();
timesyncToRTC();
bma_standby();
pmu_standby();
wifictl_standby();
blectl_standby();
adc_power_off();
if ( !blectl_get_enable_on_standby() ) {
motor_vibe(3);
delay(50);
log_i("go standby");
setCpuFrequencyMhz( 10 );
gpio_wakeup_enable ( (gpio_num_t)AXP202_INT, GPIO_INTR_LOW_LEVEL );
gpio_wakeup_enable ( (gpio_num_t)BMA423_INT1, GPIO_INTR_HIGH_LEVEL );
esp_sleep_enable_gpio_wakeup ();
esp_light_sleep_start();
// from here, the consumption is round about 2.5mA
// total standby time is 152h (6days) without use?
}
else {
log_i("standby block by bluetooth");
setCpuFrequencyMhz( 80 );
// from here, the consumption is round about 23mA
// total standby time is 19h without use?
}
}
powermgm_clear_event( POWERMGM_SILENCE_WAKEUP_REQUEST | POWERMGM_WAKEUP_REQUEST | POWERMGM_STANDBY_REQUEST );
pmu_loop( ttgo );
bma_loop( ttgo );
display_loop( ttgo );