#! /home/pete/CitrusPerl/perl/bin/perl # LCDClock.pl # # Uses LCDdisplay.pm module to display an LCD Clock # Includes a flashing colon(:) to indicate seconds, if enabled # LCDdisplay.pm can display 0-F, :, -, _, and a few other special characters # Up/down count, display your favorite nationa debt, etc. # # James M. Lynes, Jr # Last Modified: February 4, 2013 # package main; use strict; use warnings; my $app = App->new(); $app->MainLoop; package App; use strict; use warnings; use base 'Wx::App'; sub OnInit { my $frame = Frame->new(); $frame->Show(1); } package Frame; use strict; use warnings; use Wx qw(:everything); use base qw(Wx::Frame); use Wx::Event qw(EVT_PAINT EVT_SIZE EVT_TIMER); use LCDdisplay; use Data::Dumper; sub new { my($self) = @_; $self = $self->SUPER::new(undef, -1, "LCD Clock", wxDefaultPosition, [400, 200]); EVT_PAINT( $self, \&onPaint ); # Initialize event handlers EVT_SIZE( $self, \&onSize ); EVT_TIMER( $self, -1, \&onTimer); $self->{LCD} = LCDdisplay::Data->new(); # Create an LCD object $self->{LCD}->mBlinkFlag(1); # Blink colon ? 1->yes $self->{LCD}->mNumberDigits(5); # 5 digit display including : $self->{LCD}->mValue(""); # Initialize the display $self->SetBackgroundColour($self->{LCD}->mDefaultColour); # Black background my $timer = Wx::Timer->new($self); # Initialize 1 second timer $timer->Start(1000); return $self; } 1; # # Dismiss a size event # sub onSize{ my($self, $event) = @_; $event->Skip(); } # # Draw the LCD # sub onPaint { my($self, $event) = @_; LCDdisplay->Draw($self, $self->{LCD}); } # # Format the time for display # sub onTimer { my($self, $event) = @_; my($min, $hour) = (localtime)[1,2]; my $colon = ":"; if($self->{LCD}->mBlinkFlag) { # Blink the colon? if($self->{LCD}->mToggle) { # yes, toggle the : $self->{LCD}->mToggle(0); $colon = ":"; } else { $self->{LCD}->mToggle(1); $colon = " "; } } my $minstr = sprintf("%02d", $min); my $hourstr = sprintf("%02d", $hour); $self->{LCD}->mValue($hourstr . $colon . $minstr); $self->Refresh(0); }