|
Creating an elapsed timer for a PDA running the Palm OS can be something of a challenge.
We were commissioned to write a timer that could be used to make battery life comparisons between different models alongside some benchmark software that we developed for comparative testing. We had been reviewing NS Basic for Palm and so took a look at what was available within that language to help us in our task.
It was clear that we could wrestle with the time functions or that we could keep a count of the system “clicks” and convert them into elapsed time. The latter approach looked best as what we really wanted to measure was the elapsed time that the PDA was active and to ignore time spent in “sleep mode”.
The handy function SysInfo(1) would give us the current count of system clicks and the related SysInfo(2) would give us the number of clicks per second. We did find that these functions did not work correctly in the Palm software emulator - well not in version 3.0a anyway - the timer ran a little fast during desktop testing.
The SysEventAvailable() function was used to determine if the user wanted to do something with their PDA other than run the elapsed timer - if our code did not stop running then nothing else could. However here we met the big problem - our process did not get any system resources assigned to it until the user decided to switch back to the timer program. If the program got re-started - how were we going to know where we were to show the correct elapsed time?
The basic timer subroutine ended up looking like this:
Sub ShowETime() Dim WorkSecs as Integer Do While SySEventAvailable() < 1 NowTime = SysInfo(1) NowTime = (NowTime - StartTime) / ClicksPerSec WorkSecs = Int(NowTime) If WorkSecs > ElapsedSecs Then ElapsedSecs = WorkSecs Call SetDisplay End If If AutoOff = 0 Then Delay 0.1 End If Loop End Sub
StartTime, NowTime and ClicksPerSec had been declared in the project Start-up Code as Floats and ClicksPerSec had been set to the relevant value at the same time. Calling the Delay function seemed to stop the PDA doing an “Auto-Off” so we added that optional feature to the UI.
Another problem we wanted to deal with was the PDA running out of battery power altogether or the user doing a re-set - both would effectively re-start the system “click” count.
The solution to the problems was to include a small database in the project to hold the start time in system clicks. We also stored the true time and date from the current setting of the PDA. As an addition we wrote a count of the elapsed hours to the database every hour that passed (with the timer running of course) to give us some idea of total elapsed time if the system ran out of power.
You can download all of the code for this project (and the database) from our downloads page - look for the Free Code section. If you just want the timer and the supporting database then you can download these from the Free Software section.
|