summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apps/misc.c75
-rw-r--r--firmware/export/powermgmt.h3
-rw-r--r--firmware/powermgmt.c13
3 files changed, 43 insertions, 48 deletions
diff --git a/apps/misc.c b/apps/misc.c
index 08e699e781..88ec73e2d3 100644
--- a/apps/misc.c
+++ b/apps/misc.c
@@ -611,7 +611,7 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
611 if(!charger_inserted()) 611 if(!charger_inserted())
612#endif 612#endif
613 { 613 {
614 bool batt_crit = battery_level_critical(); 614 bool batt_safe = battery_level_safe();
615 int audio_stat = audio_status(); 615 int audio_stat = audio_status();
616 616
617 FOR_NB_SCREENS(i) 617 FOR_NB_SCREENS(i)
@@ -619,15 +619,8 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
619#ifdef X5_BACKLIGHT_SHUTDOWN 619#ifdef X5_BACKLIGHT_SHUTDOWN
620 x5_backlight_shutdown(); 620 x5_backlight_shutdown();
621#endif 621#endif
622 if (!battery_level_safe()) 622 if (batt_safe)
623 gui_syncsplash(3*HZ, "%s %s", 623 {
624 str(LANG_WARNING_BATTERY_EMPTY),
625 str(LANG_SHUTTINGDOWN));
626 else if (battery_level_critical())
627 gui_syncsplash(3*HZ, "%s %s",
628 str(LANG_WARNING_BATTERY_LOW),
629 str(LANG_SHUTTINGDOWN));
630 else {
631#ifdef HAVE_TAGCACHE 624#ifdef HAVE_TAGCACHE
632 if (!tagcache_prepare_shutdown()) 625 if (!tagcache_prepare_shutdown())
633 { 626 {
@@ -636,44 +629,60 @@ static bool clean_shutdown(void (*callback)(void *), void *parameter)
636 return false; 629 return false;
637 } 630 }
638#endif 631#endif
639 gui_syncsplash(0, str(LANG_SHUTTINGDOWN)); 632 if (battery_level() > 10)
633 gui_syncsplash(0, str(LANG_SHUTTINGDOWN));
634 else
635 gui_syncsplash(0, "%s %s",
636 str(LANG_WARNING_BATTERY_LOW),
637 str(LANG_SHUTTINGDOWN));
638 }
639 else
640 {
641 gui_syncsplash(0, "%s %s",
642 str(LANG_WARNING_BATTERY_EMPTY),
643 str(LANG_SHUTTINGDOWN));
640 } 644 }
641 645
642 if (global_settings.fade_on_stop 646 if (global_settings.fade_on_stop
643 && (audio_stat & AUDIO_STATUS_PLAY)) 647 && (audio_stat & AUDIO_STATUS_PLAY))
644 { 648 {
645 fade(0); 649 fade(0);
646 } 650 }
647 651
648#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC 652 if (batt_safe) /* do not save on critical battery */
649 if (!batt_crit && (audio_stat & AUDIO_STATUS_RECORD))
650 { 653 {
651 audio_stop_recording(); 654#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
652 while(audio_status() & AUDIO_STATUS_RECORD) 655 if (audio_stat & AUDIO_STATUS_RECORD)
653 sleep(1); 656 audio_stop_recording();
654 }
655
656 audio_close_recording();
657#endif 657#endif
658 /* audio_stop_recording == audio_stop for HWCODEC */ 658 /* audio_stop_recording == audio_stop for HWCODEC */
659 audio_stop();
659 660
660 audio_stop(); 661 if (callback != NULL)
661 while (audio_status()) 662 callback(parameter);
662 sleep(1);
663
664 if (callback != NULL)
665 callback(parameter);
666 663
667 if (!batt_crit) /* do not save on critical battery */ 664 /* wait for audio_stop or audio_stop_recording to complete */
665 while (audio_status())
666 sleep(1);
667
668#if defined(HAVE_RECORDING) && CONFIG_CODEC == SWCODEC
669 audio_close_recording();
670#endif
668 system_flush(); 671 system_flush();
669#ifdef HAVE_EEPROM_SETTINGS 672#ifdef HAVE_EEPROM_SETTINGS
670 if (firmware_settings.initialized) 673 if (firmware_settings.initialized)
671 { 674 {
672 firmware_settings.disk_clean = true; 675 firmware_settings.disk_clean = true;
673 firmware_settings.bl_version = 0; 676 firmware_settings.bl_version = 0;
674 eeprom_settings_store(); 677 eeprom_settings_store();
678 }
679#endif
675 } 680 }
681#ifdef HAVE_DIRCACHE
682 else
683 dircache_disable();
676#endif 684#endif
685
677 shutdown_hw(); 686 shutdown_hw();
678 } 687 }
679#endif 688#endif
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index b8e8b580d1..d42cc30154 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -144,9 +144,6 @@ void battery_read_info(int *adc, int *voltage, int *level);
144/* Tells if the battery level is safe for disk writes */ 144/* Tells if the battery level is safe for disk writes */
145bool battery_level_safe(void); 145bool battery_level_safe(void);
146 146
147/* Tells if battery is in critical power saving state */
148bool battery_level_critical(void);
149
150void set_poweroff_timeout(int timeout); 147void set_poweroff_timeout(int timeout);
151void set_battery_capacity(int capacity); /* set local battery capacity value */ 148void set_battery_capacity(int capacity); /* set local battery capacity value */
152void set_battery_type(int type); /* set local battery type */ 149void set_battery_type(int type); /* set local battery type */
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 000a8bb2ec..26323c43ab 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -143,11 +143,6 @@ bool battery_level_safe(void)
143 return battery_level() >= 10; 143 return battery_level() >= 10;
144} 144}
145 145
146bool battery_level_critical(void)
147{
148 return false;
149}
150
151void set_poweroff_timeout(int timeout) 146void set_poweroff_timeout(int timeout)
152{ 147{
153 (void)timeout; 148 (void)timeout;
@@ -422,12 +417,6 @@ bool battery_level_safe(void)
422 return battery_centivolts > battery_level_dangerous[battery_type]; 417 return battery_centivolts > battery_level_dangerous[battery_type];
423} 418}
424 419
425/* Tells if the battery is in critical powersaving state */
426bool battery_level_critical(void)
427{
428 return ((battery_capacity * battery_percent / BATTERY_CAPACITY_MIN) < 10);
429}
430
431void set_poweroff_timeout(int timeout) 420void set_poweroff_timeout(int timeout)
432{ 421{
433 poweroff_timeout = timeout; 422 poweroff_timeout = timeout;
@@ -1291,7 +1280,7 @@ void shutdown_hw(void)
1291 } 1280 }
1292#endif 1281#endif
1293 audio_stop(); 1282 audio_stop();
1294 if (!battery_level_critical()) { /* do not save on critical battery */ 1283 if (battery_level_safe()) { /* do not save on critical battery */
1295#ifdef HAVE_LCD_BITMAP 1284#ifdef HAVE_LCD_BITMAP
1296 glyph_cache_save(); 1285 glyph_cache_save();
1297#endif 1286#endif