×

Discussion Board

Results 1 to 11 of 11
  1. #1
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    151

    Battery life testing script

    I am writing a script to test the battery life of some of my spare batteries. I know some last longer than others (non official nokia, ebay etc) but now I want a figure for how long they last.

    So my code does a lot of endless work, and each time it completes a chunk it logs the current score (y) to a text file. In fact, it alternates between two text files so I can keep each file small.

    Anyway, it's running on my nokia 5800 touch.

    When the main loop (while running = 1) runs, the UI becomes unresponsive, and I can't quit the app. This is annoying during testing.

    Can anyone help me make the UI responsive please? Or better still, can someone show me how to create a thread to put the work in the new thread so the UI stays responsive?

    And if anyone has any ideas to increase the power demands on the script that would be helpful, as it would use the batter faster! Thanks

    Code:
    import appuifw
    
    def quit():
        running = 0
    
    appuifw.app.exit_key_handler = quit
    
    y = 0
    running = 1
    
    while running:
    
        logfile = open("e:\\Python\\batterylife.txt", "w") 
        print(y)
    
        for x in range(10000):
            x * x * x
    
        logfile.write(str(y))
        print >> logfile, '\r'
    
        logfile.close()
    
        y += 1
    
    
    
        logfile2 = open("e:\\Python\\batterylife2.txt", "w") 
        print(y)
    
        for x in range(10000):
            x * x * x
    
        logfile2.write(str(y))
        print >> logfile2, '\r'
    
        logfile2.close()
        
        y += 1

  2. #2
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Battery life testing script

    hello jtullis

    just a question are you implementing this in a thread??

  3. #3
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    151

    Re: Battery life testing script

    Quote Originally Posted by gaba88 View Post
    hello jtullis

    just a question are you implementing this in a thread??
    Erm, no I don't think so. The code below is the full app. I don't know how to do this in a thread. IS it easy? Thanks

  4. #4
    Nokia Developer Champion
    Join Date
    Jul 2008
    Location
    Pakistan
    Posts
    1,065

    Smile Re: Battery life testing script

    Your Main loop is running without any delay, which makes ur script hang. Either use one second delay i.e e32.ao_sleep(1) or e32.ao_yield() at end of loop . Try this :
    Code:
    import appuifw, e32
    
    def quit():
        running = 0
    
    appuifw.app.exit_key_handler = quit
    
    y = 0
    running = 1
    
    while running:
    
        logfile = open("e:\\Python\\batterylife.txt", "w") 
        print(y)
    
        for x in range(10000):
            x * x * x
    
        logfile.write(str(y))
        print >> logfile, '\r'
    
        logfile.close()
    
        y += 1
    
    
    
        logfile2 = open("e:\\Python\\batterylife2.txt", "w") 
        print(y)
    
        for x in range(10000):
            x * x * x
    
        logfile2.write(str(y))
        print >> logfile2, '\r'
    
        logfile2.close()
        
        y += 1
        e32.ao_yield()
    Hope it helps u..

    Best Regards,
    SajiSoft

  5. #5
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    151

    Re: Battery life testing script

    Thanks this is really helpful.

    So with the yield command in your quoted code i can now push the exit button, but nothing happens.

    Interestingly, when I insert another line of code in the quit function, the whole of pys60 exits when i push the exit button. It doesn't go back to script shell, it just exits altogether.

    Code:
    import appuifw, e32, audio
    
    def quit():
        audio.say("quit")
        running = 0
    
    appuifw.app.exit_key_handler = quit
    
    y = 0
    running = 1
    
    while running:
    
        logfile = open("e:\\Python\\batterylife.txt", "w") 
        print(y)
    
        for x in range(10000):
            x * x * x
    
        logfile.write(str(y))
        print >> logfile, '\r'
    
        logfile.close()
    
        y += 1
    
    
    
        logfile2 = open("e:\\Python\\batterylife2.txt", "w") 
        print(y)
    
        for x in range(10000):
            x * x * x
    
        logfile2.write(str(y))
        print >> logfile2, '\r'
    
        logfile2.close()
        
        y += 1
        e32.ao_yield()
    Why should the addition of the audio.say("quit") command make the quit function work, whereas without that extra line the quit function didn't behave as it should do! hmmmm

  6. #6
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    151

    Re: Battery life testing script

    ah, I think I need a global running....

  7. #7
    Nokia Developer Champion
    Join Date
    Jul 2008
    Location
    Pakistan
    Posts
    1,065

    Smile Re: Battery life testing script

    Quote Originally Posted by jtullis View Post
    ah, I think I need a global running....
    Ofcourse, U need to write quit function like this :
    Code:
    def quit():
        global running
        running = 0
    Hope it helps u...

    Best Regards,
    SajiSoft

  8. #8
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Battery life testing script

    Quote Originally Posted by jtullis View Post
    Thanks this is really helpful.

    So with the yield command in your quoted code i can now push the exit button, but nothing happens.
    hello jtullis

    just to add when you make a standalone application just add this line to make a proper exit:

    Code:
    appuifw.app.set_exit()
    Cheers,
    Gaba88

  9. #9
    Regular Contributor
    Join Date
    Mar 2008
    Posts
    151

    Re: Battery life testing script

    OK great, thanks guys, this forum is a great place to get help.

    Does anyone know how to maximise the battery drain for my simulation?

    At the moment my cpu use is running at 100% according to nokia energy profiler for xm 5800, but maybe I should be using bluetooth and wlan scanning to drive my battery harder.

    This is helping me to identify which of my batteries (I have lots!) lasts the longest.

  10. #10
    Nokia Developer Champion
    Join Date
    Feb 2008
    Location
    Ahmedabad, Gujarat, India
    Posts
    3,852

    Re: Battery life testing script

    Quote Originally Posted by jtullis View Post
    Does anyone know how to maximise the battery drain for my simulation?
    ya you can maximise the battery drain maximum by keeping GPRS on , using Bluetooth and WLAN scanning, using GPRS for positioning and there are many more ways.

    Hope it helps you.

    Regards
    Gaba88

  11. #11
    Super Contributor
    Join Date
    Mar 2003
    Location
    Espoo, Finland
    Posts
    976

    Re: Battery life testing script

    Quote Originally Posted by jtullis View Post
    Does anyone know how to maximise the battery drain for my simulation?
    Too easy

    Activate GPS, WLAN, BlueTooth, force screen to stay active (code below), play a movie and try if you can still play music at the same time. Please note that when device runs out of memory, it starts to kill silently background processes i.e. apps running at background.

    Code:
    def handle_screensaver():
        ''' Reset inactivity timer to keep lights on '''
        e32.reset_inactivity()
        my_timer.after(4, handle_screensaver)
    Request: try to start up those/some apps from within your code. This should make more automated and results repeatable. I feel you're making a great hardware test tool and would like to see results on a webpage device by device Problem: not all devices have GPS, WLAN and/or bluetooth...

    Edit: I would like see battery performance out-of-box and then compere that to my current battery status.

    Good luck,

    --jouni
    Last edited by JOM; 2009-06-12 at 09:14.

Similar Threads

  1. TargetListener, register, unregister, and battery life
    By olan75 in forum Near Field Communication
    Replies: 1
    Last Post: 2008-05-23, 20:02
  2. N95 battery life with inbuilt SIP client
    By NoRemorse in forum VoIP
    Replies: 4
    Last Post: 2008-02-13, 09:09
  3. Battery life 6230i under ?
    By stefann127 in forum General Development Questions
    Replies: 1
    Last Post: 2007-02-19, 14:28
  4. Replies: 2
    Last Post: 2007-01-28, 21:24
  5. 3330 battery life.
    By Nichicon in forum General Development Questions
    Replies: 0
    Last Post: 2003-12-17, 08:34

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×