#!/usr/bin/perl -w # # vfdclock # John Simpson 2006-03-19 # # simple clock for IEE two-line VFD display # http://www.ieeinc.com/specs/S036x2.pdf # # meant to run continuously, under daemontools or similar. # daemontools run script will look like this: # # #!/bin/sh # exec ./vfdclock 2>&1 # # 2007-10-29 jms1 - added comments and copyright notice, suitable for # public release on http://www.jms1.net/code/#vfdclock # ############################################################################### # # Copyright (C) 2006-2007 John Simpson. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 2 or version 3 of the # license, at your option. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # ############################################################################### require 5.003 ; use strict ; use Time::HiRes qw ( usleep ) ; my $dev = "/dev/ttyS1" ; my @dow = qw ( u m t w r f a ) ; $| = 1 ; ############################################################################### # # convert a hex string into bytes (i.e. "48656C6c6f" => "Hello") sub hstr($) { my $hs = $_[0] ; my $rv = "" ; while ( $hs =~ s/^(..)// ) { $rv .= chr(hex($1)) ; } return $rv ; } ############################################################################### ############################################################################### ############################################################################### # # someone set up us the serial port # open and initialize the display system "stty 9600 cs8 -parenb -cstopb < $dev" ; open ( D , ">$dev" ) or die "Can\'t open $dev: $!\n" ; my $oh = select ( D ) ; $| = 1 ; select ( $oh ) ; ######################################## # reset, cursor off # http://www.ieeinc.com/specs/S036x2.pdf pages 26-37 #my $init = hstr ( "140E" ) ; # reset, cursor off- ugly blinky display my $init = hstr ( "0E1613" ) ; # cursor off, home, bottom row h-scroll ############################################################################### # # im in ur display, showin u teh time my $lt = 0 ; while ( 1 ) { my $now = time() ; # resolution one second next if ( $lt == $now ) ; my @l = localtime $now ; my @g = gmtime $now ; printf D "%s%s %s%02d-%02d %02d:%02d:%02d" , $init , ( $l[8] ? "EDT" : "EST" ) , $dow[$l[6]] , $l[4]+1 , $l[3] , $l[2] , $l[1] , $l[0] ; printf D "\r\nGMT %s%02d-%02d %02d:%02d:%02d" , $dow[$g[6]] , $g[4]+1 , $g[3] , $g[2] , $g[1] , $g[0] ; $lt = $now ; usleep ( 950_000 ) ; # sleep "most of" one second } close D ;