Old laptop as Digital Clock [SOLVED][and SOLVED even more]

Using applications, configuring, problems
Message
Author
User avatar
davids45
Posts: 1326
Joined: Sun 26 Nov 2006, 23:33
Location: Chatswood, NSW

#16 Post by davids45 »

G'day 01micko,
Hey davids45... see what you started
Well, I did want this for an 'el cheapo' start clock - a fully blown beeping+LED start clock (Norwegian - G'day zigbert) is costing my orienteering club over AU$3000 by the time we get it through our customs.
.
I'm hoping to give the 'el cheapo' a try this Wednesday at some night orienteering in Chatswood (Lowanna Park, 7-8pm). A discount will be offered for any Puppy Linux users, and free use of our First Aid kit :wink: .

And thanks for everyone's interest and input.

David S.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#17 Post by 01micko »

I'm hoping to give the 'el cheapo' a try this Wednesday at some night orienteering in Chatswood (Lowanna Park, 7-8pm). A discount will be offered for any Puppy Linux users, and free use of our First Aid kit
bit far for me mate, but maybe cthisbear or jamesbond can make it. :wink:

Cheers
Puppy Linux Blog - contact me for access

User avatar
zigbert
Posts: 6621
Joined: Wed 29 Mar 2006, 18:13
Location: Valåmoen, Norway
Contact:

#18 Post by zigbert »

davids45 wrote:a fully blown beeping+LED start clock (Norwegian - G'day zigbert) is costing my orienteering club over AU$3000 by the time we get it through our customs.
Sounds like a reasonable price......after all it's not more than we have to pay for 1 kg marinated kangaroo meat :D
davids45 wrote:I'm hoping to give the 'el cheapo' a try this Wednesday at some night orienteering in Chatswood (Lowanna Park, 7-8pm). A discount will be offered for any Puppy Linux users, and free use of our First Aid kit :wink: .
I would really like to come.......

I have Germany on my agenda this year. - But Australia.......sounds like a dream to me.


Sigmund

User avatar
Béèm
Posts: 11763
Joined: Wed 22 Nov 2006, 00:47
Location: Brussels IBM Thinkpad R40, 256MB, 20GB, WiFi ipw2100. Frugal Lin'N'Win

#19 Post by Béèm »

01micko wrote:Béèm
Did you be sure to add -a option to the shebang?

Have fun!

Cheers
Well I took the script where you told davids45 'there has been an update 20 minutes ago' and there was no -a in it.
I now took your latest and it's working.

Now I think the next question from people would be to start this clock when the screen locks. :wink:
Time savers:
Find packages in a snap and install using Puppy Package Manager (Menu).
[url=http://puppylinux.org/wikka/HomePage]Consult Wikka[/url]
Use peppyy's [url=http://wellminded.com/puppy/pupsearch.html]puppysearch[/url]

ken geometrics
Posts: 76
Joined: Fri 23 Jan 2009, 14:59
Location: California

#20 Post by ken geometrics »

01micko wrote:Would you like a config gui with that? Perhaps sound choice, colour choice?
The bell function did not work on my PC. Here is a replacement that does work but is less than ideal. I was going to make it phase lock the delay timing to get exactly onto the minutes roll over but I had an attack of the lazies.

It dings on the minute roll over plus just a smidge. It also doesn't loop every 0.5 seconds while waiting. It does some math to work out the delay that is needed then does that delay.

Code: Select all

function BELL (){

  PREVDING="`date +%M`"
   
  until [ -f  /tmp/killclock ] ;  do
    THISDING="`date +%M`"
    THISTICK="`date +%S`"
    THISTICK=`expr 60 - $THISTICK`

    if [ "$THISDING" != "$PREVDING" ] ; then
      aplay $NOISE 
      PREVDING="$THISDING"
      fi
    sleep ${THISTICK}.3
    done
  }

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

Update

#21 Post by abushcrafter »

Sorry Haven't Applied the lupu yaf-splash bug fix. I don't have the time at the moment. I also don't use lupu currently. in version 0.4 and 0.5 (This one.) I added the exit command at the end of each function. Are they need?

Code: Select all

#!/bin/sh -a

#ChangeLog
#2010-08-14  Alexander S.T. Ross (abushcrafter)  <http://www.google.com/recaptcha/mailhide/d?k=01uNeUuXxeNm9FA3Zciuoqzw==&c=nVfKeb7kjqZVVIQanqJwEC2DP5zrALkSERTopYvj_pU=>
#    * Version=0.4
#    * Applied zigbert's proper full screen clock code.
#    * I also got rid of the kill sound button so when you click on the yaf-splash clock to close it kills the sound with it. 

#2010-08-16  Alexander S.T. Ross (abushcrafter)  <http://www.google.com/recaptcha/mailhide/d?k=01uNeUuXxeNm9FA3Zciuoqzw==&c=nVfKeb7kjqZVVIQanqJwEC2DP5zrALkSERTopYvj_pU=>
#    * Version=0.5
#    * Applied ken geometrics rewritten Bell function.
#    * Changed "echo "Finished. Will Now Exit."" to "echo "Exited"".


rm -f /tmp/killclock

if [ -f $HOME/.bigclockrc ];then . $HOME/.bigclockrc
fi

HEIGHT=`xwininfo -root | grep -m 1 '\geometry' | cut -f4 -d ' ' | cut -f2 -d 'x' | cut -f1 -d '+'`
WIDTH=`xwininfo -root | grep -m 1 '\geometry' | cut -f4 -d ' ' | cut -f1 -d 'x'`
SIZE=$((HEIGHT/44*10))


function YAF (){
echo BG="\"$BG\"" >$HOME/.bigclockrc
echo FG="\"$FG\"" >>$HOME/.bigclockrc
echo NOISE="\"$NOISE\"" >>$HOME/.bigclockrc
yaf-splash -font "-misc-dejavu sans-bold-r-normal--$SIZE-0-0-0-p-0-iso10646-1" -geometry ${WIDTH}x${HEIGHT} -bg $BG -fg $FG -outline 0  -clock
echo "" > /tmp/killclock &
exit
}

function BELL (){
  PREVDING="`date +%M`"
   
  until [ -f  /tmp/killclock ] ;  do
    THISDING="`date +%M`"
    THISTICK="`date +%S`"
    THISTICK=`expr 60 - $THISTICK`

    if [ "$THISDING" != "$PREVDING" ] ; then
      aplay $NOISE
      PREVDING="$THISDING"
      fi
    sleep ${THISTICK}.3
    done 

    rm -v -f /tmp/killclock
    echo ""
    echo "Exited"
    exit
}
function KILLCLOCKGUI (){

   kill `ps|grep "clockgui"|awk '{print $1}'`
   exit 
}

clockgui="
<vbox>
 <hbox>
  <text><label>Enter a colour for background</label></text>
   <entry>
    <variable>BG</variable>
    <input>echo \"$BG\"</input>
    </entry>
  </hbox>
  <hbox>
  <text><label>Enter a colour for foreground</label></text>
   <entry>
    <variable>FG</variable>
    <input>echo \"$FG\"</input>
    </entry>
  </hbox>
  <hbox>
  <text><label>Enter the path to a sound</label></text>
   <entry>
    <variable>NOISE</variable>
    <input>echo $NOISE</input>
    </entry>
  </hbox>
  <hbox>
  <button>
   <label>Sound</label>
   <input file stock=\"gtk-directory\"></input>
   <action>exec rox /usr/share/audio &</action>
  </button>
  <button>
   <label>Colour</label>
   <input file stock=\"gtk-select-color\"></input>
   <action>exec gcolor2 &</action>
  </button>
  <button>
   <label>Go!</label>
   <input file stock=\"gtk-yes\"></input>
   <action>YAF &</action>
   <action>BELL &</action>
   <action>KILLCLOCKGUI &</action>
  </button>
 </hbox>
</vbox>"
gtkdialog3 -p clockgui
unset clockgui
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

User avatar
davids45
Posts: 1326
Joined: Sun 26 Nov 2006, 23:33
Location: Chatswood, NSW

A working START clock

#22 Post by davids45 »

G'day again,
I've slowly been playing with this idea to set up a lap-top as a beeping starting clock for sporting activities like orienteering and time trial races where individual starts are spaced apart at regular intervals (e.g every minute).
The commercial clocks cost several thousand dollars/euros but Puppy on an old lap-top with a reasonable sound system would be a good alternative for the un-rich.

Thanks to all those earlier in this thread who provided scripts for such a beeping digital clock concept.

By trial & error script butchery, I added a second beeping sound into the options so that now the clock gives shorts beeps for the five seconds leading up to the whole minute whereupon a longer different pitch beep is played. In my experience, this is exactly to way the commercial clocks operate.

Precise synchronising of the beep sound with the display was a bit tricky (setting the sleep value so the beep sounded precisely as the seconds display changed). This may have something to do with the length of the beep and the particular computer's hardware.

The battery life or cell-number of the lap-top is important if the clock has to run for a couple of hours away from any mains or back-up power (inverter, generator).

Anyway, here is my current script. Please suggest any improvements.

Code: Select all

#!/bin/sh -a

YAFSPLASH="/usr/X11R7/bin/yaf-splash"   

rm -f /tmp/killclock

if [ -f $HOME/.bigclockrc ];then . $HOME/.bigclockrc
fi

HEIGHT=`xwininfo -root | grep -m 1 '\geometry' | cut -f4 -d ' ' | cut -f2 -d 'x' | cut -f1 -d '+'`
WIDTH=`xwininfo -root | grep -m 1 '\geometry' | cut -f4 -d ' ' | cut -f1 -d 'x'`
SIZE=$((HEIGHT/5))

SIZE=`expr $HEIGHT / 4`
if [ $RATIO -gt 140 ]; then
    MARGINGET=`expr $HEIGHT \* 1`
    MARGIN=`expr $MARGINGET / 3`
  else MARGIN=20
fi



function YAF (){
echo BG="\"$BG\"" >$HOME/.bigclockrc
echo FG="\"$FG\"" >>$HOME/.bigclockrc
echo NOISE="\"$NOISE\"" >>$HOME/.bigclockrc
echo START="\"$START\"" >>$HOME/.bigclockrc
$YAFSPLASH -font "-misc-dejavu sans-bold-r-normal--$SIZE-0-0-0-p-0-iso10646-1" -bg $BG -fg $FG -outline 0  -clock -geometry $((WIDTH+PLACEMENT_X))x$((HEIGHT+PLACEMENT_Y))+0+0
#$YAFSPLASH -font "-misc-dejavu sans-bold-r-normal--$SIZE-0-0-0-p-0-iso10646-1" -margin $MARGIN -bg $BG -fg $FG -outline 0  -clock
}

function BELL (){
   #ZEROTIME=`date +%T|cut -d ':' -f3`
   
   until [ -f  /tmp/killclock ]
       do
	   if [ "`date +%T|cut -d ':' -f3`" = "00" ];then aplay $START ; sleep 0.75 ;fi
	   if [ "`date +%T|cut -d ':' -f3`" = "59" ];then aplay $NOISE ; sleep 0.75 ;fi
	   if [ "`date +%T|cut -d ':' -f3`" = "58" ];then aplay $NOISE ; sleep 0.75 ;fi
	   if [ "`date +%T|cut -d ':' -f3`" = "57" ];then aplay $NOISE ; sleep 0.75 ;fi
	   if [ "`date +%T|cut -d ':' -f3`" = "56" ];then aplay $NOISE ; sleep 0.75 ;fi
	   if [ "`date +%T|cut -d ':' -f3`" = "55" ];then aplay $NOISE ; sleep 0.75 ;fi
	    		  # sleep 0.75
	    		  # sleep time seems critical in synchronising display with beeps - could depend on length of beep?
	    		  # could add intermediate warning sounds or speech file, say at 30 and 20 seconds to go?  Wish I had a working microphone.
       done
}
function KILLSWITCH (){

   kill `ps|grep "clockgui"|awk '{print $1}'`
   export killswitch='
   <window decorated="false">
   <vbox>
     <hbox>
      <button>
       <label>KILLSWITCH</label>
       <input file>/usr/share/doc/puppylogo96.png</input>
       <action>echo "" > /tmp/killclock &</action>
       <action>exit:Exit</action>
      </button>
     </hbox>
    </vbox>
   </window>'
   gtkdialog3 -p killswitch
   unset killswitch
 
}

clockgui="
<vbox>
 <hbox>
  <text><label>Enter a colour for background</label></text>
   <entry>
    <variable>BG</variable>
    <input>echo \"$BG\"</input>
    </entry>
  </hbox>
   <hbox>
  <text><label>Enter a colour for foreground</label></text>
   <entry>
    <variable>FG</variable>
    <input>echo \"$FG\"</input>
    </entry>
  </hbox>
  <hbox>
  <text><label>Enter the path to a short sound</label></text>
   <entry>
    <variable>NOISE</variable>
    <input>echo $NOISE</input>
    </entry>
  </hbox>
  <hbox>
  <text><label>Enter the path to the START sound</label></text>
   <entry>
    <variable>START</variable>
    <input>echo $START</input>
    </entry>
  </hbox>
  <hbox>
  <button>
   <label>Sound</label>
   <input file stock=\"gtk-directory\"></input>
   <action>exec rox /usr/share/audio &</action>
  </button>
  <button>
   <label>Colour</label>
   <input file stock=\"gtk-select-color\"></input>
   <action>exec gcolor2 &</action>
  </button>
  <button>
   <label>Go!</label>
   <input file stock=\"gtk-yes\"></input>
   <action>YAF &</action>
   <action>BELL &</action>
   <action>KILLSWITCH &</action>
  </button>
 </hbox>
</vbox>"
gtkdialog3 -p clockgui
unset clockgui
Thanks again to all those who contributed.

David S.

User avatar
01micko
Posts: 8741
Joined: Sat 11 Oct 2008, 13:39
Location: qld
Contact:

#23 Post by 01micko »

David...

I wonder what would happen if you forked the $NOISE calls ie, add '&' on each call...


I'll let you experiment :wink:

Cheers
Puppy Linux Blog - contact me for access

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#24 Post by abushcrafter »

01micko wrote:David...

I wonder what would happen if you forked the $NOISE calls ie, add '&' on each call...


I'll let you experiment :wink:

Cheers
That does not work. You end up with all the sounds being played at the next min.

I really would love the feature of being able to set multiple sounds to be played for every specified amount of times. E.G for every 3 sec play alarm or for each 1/2 hour play a piece of audio and for every 10 secs play a piece audio. Hopefully you get the idea.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

npierce
Posts: 858
Joined: Tue 29 Dec 2009, 01:40

#25 Post by npierce »

davids45 wrote:Precise synchronising of the beep sound with the display was a bit tricky . . .
davids45 wrote:. . . Anyway, here is my current script. Please suggest any improvements.
The key thing to remember is that you don't want it to beep whenever the seconds count is 55 (or 56, 57, etc.). You want it to just beep when the seconds count becomes 55 (or 56, 57, etc.).

You are testing for 55, so if aplay takes less than a second to make the beep, the seconds count will still be 55 when it finishes, so if it tests for 55 again it will beep again.

To avoid multiple beeps you have put the script to sleep for a fraction of a second. But, as you have discovered, if that fraction is too short, you get an extra beep, and if it is too long you delay the beep for the next second.

So it is a race. Which will happen first? Will the clock tick to the next second, or will the script awaken from its sleep?

(Perhaps it is fitting that there is a race condition in a script used to time races.)

I would suggest wrapping your tests in another if/fi that only executes when the second count changes. To do so add these two lines after the do in the BELL() function:

Code: Select all

NOW=`date +%T|cut -d ':' -f3`
if [ "$NOW" != "$THEN" ] ; then
And add these two lines just before the done:

Code: Select all

fi
THEN=$NOW
You can now eliminate the calls to sleep. And since you now have $NOW, you can use it in place of `date +%T|cut -d ':' -f3` in your tests.


That should keep the beeps in sync without the need to fine tune a sleep value. But I have one more suggestion.

The script now spends most of its time polling the clock. It does this as often as it can. Except for the six times you put it to sleep, it is running at full-tilt, which is putting a big load on the system. It is likely that your laptop's fan comes on often when you run the script.

If you give it a vacation of, say, 0.05 seconds each time through the loop, it should run cooler. So you could add this line just before done:

Code: Select all

sleep 0.05
(If you wanted to get fancy, you could write something in C that would wait for the next second to arrive, and call it from your script instead of sleep, but calling sleep should be adequate for your needs.)

So now your BELL() function will look something like this:

Code: Select all

function BELL (){
  until [ -f  /tmp/killclock ]
    do
      NOW=`date +%T|cut -d ':' -f3`
      if [ "$NOW" != "$THEN" ] ; then
        if [ "$NOW" = "00" ];then aplay $START ; fi
        if [ "$NOW" = "59" ];then aplay $NOISE ; fi
        if [ "$NOW" = "58" ];then aplay $NOISE ; fi
        if [ "$NOW" = "57" ];then aplay $NOISE ; fi
        if [ "$NOW" = "56" ];then aplay $NOISE ; fi
        if [ "$NOW" = "55" ];then aplay $NOISE ; fi
      fi
      THEN=$NOW
      sleep 0.05
    done
}
davids45 wrote:The battery life or cell-number of the lap-top is important if the clock has to run for a couple of hours away from any mains or back-up power (inverter, generator).
Good point. And you should find that the little sleep 0.05 vacations added above will cause the script to drain your battery more slowly than previously.

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#26 Post by abushcrafter »

@npierce That does not work also.
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

User avatar
davids45
Posts: 1326
Joined: Sun 26 Nov 2006, 23:33
Location: Chatswood, NSW

#27 Post by davids45 »

G'day abushcrafter,
npierce's modification worked well for me, in giving good beep and display synchronicity.
I just cut and pasted his code into the script over the older section.
David S.

User avatar
davids45
Posts: 1326
Joined: Sun 26 Nov 2006, 23:33
Location: Chatswood, NSW

FatDog - sound but no display

#28 Post by davids45 »

G'day,

Just had a successful beeping clock use, sending off individually about 200 Sydney-siders to orienteer around the Sydney suburb of Dundas. Being daylight, the major problem was the high reflectivity of the laptop screen - a black numbers on white background had best visibility. But most people just waited for the on-the-minute long beep as the signal to start.
I was using Wary 5.0 via a Windows Installer v1.1 inside a Windows 7 partition.

In playing with putting other Pups onto the laptop, I installed FatDog-5.10 which runs very well on the 64bit laptop.

However, when I run the beeping clock script, I get no full-screen clock display, just the small "Killbutton". The sound is working as the beeps occur at the required times.

Is there someway to get this script to display in 64bit FatDog?

Thanks.

David S.

User avatar
abushcrafter
Posts: 1418
Joined: Fri 30 Oct 2009, 16:57
Location: England
Contact:

#29 Post by abushcrafter »

I worked out my confusion and have done some work on it and put it into a PET :).

Code: Select all

#ChangeLog --------------------------------------------------------------------
#	2011/02/22 22:53:17 abushcrafter Email=http://www.google.com/recaptcha/mailhide/d?k=01uNeUuXxeNm9FA3Zciuoqzw==&c=nVfKeb7kjqZVVIQanqJwEC2DP5zrALkSERTopYvj_pU=
#		* 0.9: Uses a different font for clock because previous one was squashed in the 5 series of Puppy GNU/Linux.
#		* 0.9: Added sounds for every 10 secs.
#		* 0.9: Sound player is set by "defaultsoundplayer". However it has been overrider by a function for this reason: "Mplayer does not work well for the last 5 secs with a sound for each sec of a min, if the sounds are more than 1 sec long.".
#		* 0.9: No longer kills the setup GUI. It now closes properly.
#		* 0.9: Added window title.
#		* 0.9: Added cancel button.
#		* 0.9: Removed kill sound button.
#		* 0.9: Improved full-screen.
#		* 0.9: Added comments like a changelog at the top of this script.
#		* 0.9: Tweaked Setup GUI text.
For the icon in the menu to work. You need to add a some paths to a XML config file.

Strings to add:

Code: Select all

	<IconPath>/usr/share/icons</IconPath>
	<IconPath>/usr/share/icons/locolor/16x16/apps</IconPath>
	<IconPath>/usr/share/icons/locolor/48x48/apps</IconPath>
	<IconPath>/usr/share/icons/hicolor/16x16/apps</IconPath>
	<IconPath>/usr/share/icons/hicolor/48x48/apps</IconPath>
XML config file to add string to:

Code: Select all

/etc/xdg/templates/_root_.jwmrc
The section you need to add it to:

Code: Select all

    <!-- <Icons> -->
    <!-- <IconPath>$HOME/.icons</IconPath> -->
	<IconPath>/usr/local/lib/X11/mini-icons</IconPath>
	<IconPath>/usr/local/lib/X11/pixmaps</IconPath>
	<IconPath>/usr/share/pixmaps</IconPath>
	<IconPath>/usr/local/share/pixmaps</IconPath>
    <!-- </Icons> -->
The results you are aiming for:

Code: Select all

    <!-- <Icons> -->
    <!-- <IconPath>$HOME/.icons</IconPath> -->
	<IconPath>/usr/local/lib/X11/mini-icons</IconPath>
	<IconPath>/usr/local/lib/X11/pixmaps</IconPath>
	<IconPath>/usr/local/share/pixmaps</IconPath>
	<IconPath>/usr/share/pixmaps</IconPath>
	<IconPath>/usr/share/icons</IconPath>
	<IconPath>/usr/share/icons/locolor/16x16/apps</IconPath>
	<IconPath>/usr/share/icons/locolor/48x48/apps</IconPath>
	<IconPath>/usr/share/icons/hicolor/16x16/apps</IconPath>
	<IconPath>/usr/share/icons/hicolor/48x48/apps</IconPath>
    <!-- </Icons> -->
Attachments
FullScreenClockWithAlarm-0.9.pet
(3.26 KiB) Downloaded 277 times
[url=http://www.adobe.com/flashplatform/]adobe flash is rubbish![/url]
My Quote:"Humans are stupid, though some are clever but stupid." http://www.dependent.de/media/audio/mp3/System_Syn_Heres_to_You.zip http://www.systemsyn.com/

Post Reply