Rockbox.org home
Downloads
Release release
Dev builds dev builds
Extras extras
themes themes
Documentation
Manual manual
Wiki wiki
Device Status device status
Support
Forums forums
Mailing lists mailing lists
IRC IRC
Development
Bugs bugs
Patches patches
Dev Guide dev guide
Search




Rockbox Technical Forums


Login with username, password and session length
Home Help Search Staff List Login Register
News:

Rockbox Ports are now being developed for various digital audio players!

+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Feature Ideas
| | |-+  Power off at 40% state-of-charge for storing
« previous next »
  • Print
Pages: [1] 2

Author Topic: Power off at 40% state-of-charge for storing  (Read 1902 times)

Offline cereal_killer

  • Member
  • *
  • Posts: 363
Power off at 40% state-of-charge for storing
« on: August 16, 2018, 02:46:15 PM »
Li-ion batteries (and I think this then applies to DAPs as well) should be stored at a 40 percent state-of-charge. The idea is to have a setting for power off, like the sleep timer, but not after a given time, but when the battery reaches 40% and then put the Player away. Is a plugin a better option?
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 461
Re: Power off at 40% state-of-charge for storing
« Reply #1 on: August 16, 2018, 09:39:00 PM »
if you set your idle Poweroff you could use a lua script to hold it on till the battery level gets low enough

Code: [Select]
require("actions")   -- Contains rb.actions & rb.contexts
local battery

if (not rb.battery_level) or (not rb.audio_stop) then
rb.splash(1000, "missing functions")
os.exit()
end

if rb.backlight_force_on then rb.backlight_force_on() end

while rb.get_plugin_action(0) ~= rb.actions.PLA_CANCEL do
local battery = rb.battery_level()
rb.splash(1000, battery .. "%")

if battery < 45 then
    rb.audio_stop()
    rb.lcd_clear_display()
    rb.lcd_update()
os.exit()
end
end

if you really wanted to be slick you could change the poweroff time out as well
http://forums.rockbox.org/index.php/topic,52389.msg242523.html#msg242523
Logged

Offline cereal_killer

  • Member
  • *
  • Posts: 363
Re: Power off at 40% state-of-charge for storing
« Reply #2 on: August 17, 2018, 04:21:51 AM »
Hello Bilgus, thanks for the reply and that you even offered a solution. So does this mean to create a lua plugin, start it and it will power off? What if the level is already below 40 percent? By now this is over my head and I really need to dig into this.
Logged

Offline gomezz

  • Member
  • *
  • Posts: 109
Re: Power off at 40% state-of-charge for storing
« Reply #3 on: August 17, 2018, 04:59:24 AM »
Never heard of this before.  Do you have a reference for this claim?
Logged
Sansa Clip+ Rockbox v3.14

Offline cereal_killer

  • Member
  • *
  • Posts: 363
Re: Power off at 40% state-of-charge for storing
« Reply #4 on: August 17, 2018, 08:46:09 AM »
Quote from: gomezz on August 17, 2018, 04:59:24 AM
Never heard of this before.  Do you have a reference for this claim?

https://batteryuniversity.com/index.php/learn/article/how_to_store_batteries

I hope this is reliable.
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 461
Re: Power off at 40% state-of-charge for storing
« Reply #5 on: August 17, 2018, 10:37:55 AM »
yes you would start it up and it would turn off once the battery was low enough if the battery was already low it would do the same
Logged

Offline TAC109

  • Member
  • *
  • Posts: 86
Re: Power off at 40% state-of-charge for storing
« Reply #6 on: August 17, 2018, 06:27:05 PM »
It depends how long you want to store the device. I have a Fuze+ that I'm not using at present and it self-discharges from full to completely empty in about 3 months without any use. I currently charge it to full about every 2 months to avoid having the battery going completely flat.
Logged

Offline cereal_killer

  • Member
  • *
  • Posts: 363
Re: Power off at 40% state-of-charge for storing
« Reply #7 on: August 18, 2018, 03:59:13 AM »
According to the page I linked, storing a battery fully charged leads to a non-recoverable capacity loss, especially when the temperature is elevated. Thus the 40 percent charge, when storing.
« Last Edit: August 18, 2018, 04:01:30 AM by cereal_killer »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 461
Re: Power off at 40% state-of-charge for storing
« Reply #8 on: August 18, 2018, 06:09:45 AM »
here you go..

Code: [Select]
local batteryoff = 45 --percentage of battery when script will quit

require("actions")   -- Contains rb.actions & rb.contexts

if not pcall(require, "settings") then
    -- check if settings.lua is available otherwise put in dummy tables
    rb.system = rb.system or {}
    rb.system.global_settings = rb.system.global_settings or {}
end

if (not rb.battery_level) or (not rb.audio_stop) then
    rb.splash(1000, "missing functions")
    os.exit()
end

local batterylevel = rb.battery_level()
local charging = false
local poweroff = rb.system.global_settings.poweroff or {}

if batterylevel < batteryoff then
    rb.splash(1000, "battery needs charged " .. batterylevel .. "% < " .. batteryoff .. "%")
    if rb.charging_state then charging = rb.charging_state() end
    -- exit if not already charging
    if not charging then os.exit() end
end

function check_battery()
    local dots = ""
    if rb.backlight_force_on then rb.backlight_force_on() end

    repeat
        rb.lcd_clear_display()
        rb.lcd_update()
        if rb.charging_state then charging = rb.charging_state() end

        batterylevel = rb.battery_level()

        if charging then
            rb.splash(1, "charging " .. batterylevel .. "%" .. dots)
            dots = dots .. "."
            if string.len(dots) > 4 then dots = "" end
        else
            rb.splash(1, batterylevel .. "% > " .. batteryoff .. "%")
        end

        if batterylevel < batteryoff and (not charging) then
            rb.audio_stop()
            rb.lcd_clear_display()
            rb.lcd_update()

            if rb.global_settings then
                -- set poweroff time to 1 minute
                rb.global_settings(poweroff[1], poweroff[2], 1)
            end

            return
        end
    until rb.get_plugin_action(500) == rb.actions.PLA_CANCEL
end

check_battery()
os.exit()

EDIT..
Code: [Select]
local batteryoff = 45 --percentage of battery when script will quit

--require("actions")   -- Contains rb.actions & rb.contexts

if not pcall(require, "settings") then
    -- check if settings.lua is available otherwise put in dummy tables
    rb.system = rb.system or {}
    rb.system.global_settings = rb.system.global_settings or {}
end

if (not rb.battery_level) or (not rb.audio_stop) then
    rb.splash(1000, "missing functions")
    os.exit()
end

local batterylevel = rb.battery_level()
local charging = false
local poweroff = rb.system.global_settings.poweroff or {}

if batterylevel < batteryoff then
    rb.splash(1000, "battery needs charged " .. batterylevel .. "% < " .. batteryoff .. "%")
    if rb.charging_state then charging = rb.charging_state() end
    -- exit if not already charging
    if not charging then os.exit() end
end

function check_battery()
    local dots = ""
    if rb.backlight_force_on then rb.backlight_force_on() end

    repeat
        rb.lcd_clear_display()
        rb.lcd_update()
        if rb.charging_state then charging = rb.charging_state() end

        batterylevel = rb.battery_level()

        if charging then
            rb.splash(1, "charging " .. batterylevel .. "%" .. dots)
            dots = dots .. "."
            if string.len(dots) > 4 then dots = "" end
        else
            rb.splash(1, batterylevel .. "% > " .. batteryoff .. "%")
rb.reset_poweroff_timer()
        end

        if batterylevel < batteryoff and (not charging) then
            rb.audio_stop()
            rb.lcd_clear_display()
            rb.lcd_update()

            if rb.global_settings then
                -- set poweroff time to 1 minute
                rb.global_settings(poweroff[1], poweroff[2], 1)
            end

            return
        end
    until rb.get_plugin_action(500) > 0
end

check_battery()
os.exit()
« Last Edit: August 27, 2018, 05:15:14 PM by Bilgus »
Logged

Offline cereal_killer

  • Member
  • *
  • Posts: 363
Re: Power off at 40% state-of-charge for storing
« Reply #9 on: August 21, 2018, 11:59:39 AM »
Thank you Bilgus, does this need the "Lua using global_settings, global_status" patch, or can I just add it to a  rockbox build.
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 461
Re: Power off at 40% state-of-charge for storing
« Reply #10 on: August 21, 2018, 09:56:19 PM »
it is set up to work with either.. if you don't use the global settings patch you just need to make sure idle poweroff is set
« Last Edit: August 21, 2018, 09:57:57 PM by Bilgus »
Logged

Offline cereal_killer

  • Member
  • *
  • Posts: 363
Re: Power off at 40% state-of-charge for storing
« Reply #11 on: August 27, 2018, 01:39:53 PM »
Quote from: Bilgus on August 21, 2018, 09:56:19 PM
it is set up to work with either.. if you don't use the global settings patch you just need to make sure idle poweroff is set

Today I compiled a build with the plugin you provided without using the global settings patch. I hope I did everything right: I put a file called 45percent.lua containing your code into /apps/plugins and added a new line with this filename to CATEGORIES and to SOURCES (and to be sure to edit the right file to SOURCES.app.build after /* plugins common to all models */) The created build loads fine on my Sansa Clipv2. Starting the plugin right away shows 65% > 45%. Exiting can only be done with a reset (long power press). After a restart, when starting playback to speed up battery drain and then starting the plugin the player freezes showing only the status bar and the disk activity icon. Interestingly the game boomshine.lua also freezes the player. Regarding the setting idle power off, this doesn't change the behaviour (this setting is limited to 60 minutes, so if the battery is not at 45% after that time, the player will also shut down, right?)
I will add your patch and try again. I'll report back.
Thanks again.

Edit: Applying the patch didn't change the situation, the plugin still freezes the player. Any suggestions?
« Last Edit: August 27, 2018, 01:56:37 PM by cereal_killer »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 461
Re: Power off at 40% state-of-charge for storing
« Reply #12 on: August 27, 2018, 03:20:33 PM »
Cereal_killer, what player are you using?

I've done quite a bit to the lua backend so I might have broken something on your player.

Could you try 3.14 and see if the issue is reproducible?

Also is the count going down? like 60% > 45%.. 50% > 45%...

idle power off shouldn't be active while the plugin is active though I might be mistaken in that case play music as well
« Last Edit: August 27, 2018, 03:30:08 PM by Bilgus »
Logged

Offline Bilgus

  • Developer
  • Member
  • *
  • Posts: 461
Re: Power off at 40% state-of-charge for storing
« Reply #13 on: August 27, 2018, 05:16:29 PM »
I edited the script above to quit on any key press and to reset the power off timer this should help with the issues
Logged

Offline cereal_killer

  • Member
  • *
  • Posts: 363
Re: Power off at 40% state-of-charge for storing
« Reply #14 on: August 29, 2018, 10:24:14 AM »
I use a Sansa Clip v2. I tried your edited script, but everything behaves the same as before. I started the plugin right after booting and it showed 48% > 45% for more than 6 hours. But after resetting the player, the battery level was at 9%. No keypress quit the plugin.

Boomshine.lua also freezes the player with 3.14.
Logged

  • Print
Pages: [1] 2
« previous next »
+  Rockbox Technical Forums
|-+  Rockbox Development
| |-+  Feature Ideas
| | |-+  Power off at 40% state-of-charge for storing
 

  • SMF 2.0.6 | SMF © 2013, Simple Machines
  • XHTML
  • RSS
  • WAP2

Page created in 0.087 seconds with 64 queries.