Skip to content

Instantly share code, notes, and snippets.

@jadonk
Created February 25, 2020 17:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jadonk/f6c23c9e567de832e1a60db8af4ec6f0 to your computer and use it in GitHub Desktop.
Save jadonk/f6c23c9e567de832e1a60db8af4ec6f0 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
#############################################################################
# PixelOverlay-Countdown.pl - Scroll a Countdown across a matrix
#############################################################################
# Set our library path to find the FPP Perl modules
use lib "/opt/fpp/lib/perl/";
# Use the FPP Memory Map module to talk to the daemon
use FPP::MemoryMap;
# Use POSIX for mktime()
use POSIX;
#############################################################################
# Setup some variables (this is the part you want to edit for font, color, etc.)
my $name = "Matrix #2"; # Memory Mapped block name
my $color = "#e45831"; # Text Color (also names like 'red', 'blue', etc.) - Orange: #e45831 - (228, 88, 49)
my $fill = "#000000"; # Fill color (not used currently)
my $font = "fixed"; # Font Name
my $size = "12"; # Font size
my $pos = "2,2"; # Position: 'scroll', 'center', 'x,y' (ie, '10,20')
my $dir = "R2L"; # Scroll Direction: 'R2L', 'L2R', 'T2B', 'B2T'
my $pps = 5; # Pixels Per Second
#############################################################################
# Some setup for our countdown
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
# In localtime, $year is current year minus 1900
# In locality, $mon is 0-11, so December is 11
my $target_date = mktime(0, 0, 0, 1, 6, $year, 0, 0); # July 1
# Some variables to hold the number of seconds in a time period
my $aDay = 24 * 60 * 60;
my $aHour = 60 * 60;
my $aMin = 60;
#############################################################################
# This function will get called once per second and returns the text string
# to be displayed at that point in time.
sub GetNextMessage
{
my $diff = $target_date - time;
my $daysDiff = int($diff / $aDay);
$diff -= $daysDiff * $aDay;
my $hoursDiff = int($diff / $aHour);
$diff -= $hoursDiff * $aHour;
my $minsDiff = int($diff / $aMin);
my $secsDiff = $diff % $aMin;
my $msg;
# Generate a 2-line string with the word Christmas on the top line
# and a countdown timer like "43d 12h 3m 32s" on the second line
# if (($secsDiff != 0) && ($secsDiff != 10) && ($secsDiff != 20) &&
# ($secsDiff != 30) && ($secsDiff != 40) && ($secsDiff != 50)) {
# $msg = sprintf("%d days\n%02d:%02d:%02d ",
# $daysDiff, $hoursDiff, $minsDiff, $secsDiff);
# } else {
# # 7 characters per line: $msg = " Merry \n X-mas ";
# $msg = "11 years\nof Beagle";
# }
# 7 characters per line: Ex: $msg = " Merry \n X-mas ";
if ((($secsDiff % 4) != 0) && (($secsDiff % 4) != 1)) {
$msg = "Beagle \nBoard.org";
} else {
$msg = "Hall 3A\nStand 238";
}
return $msg;
}
#############################################################################
# Main part of program
# Instantiate a new instance of the MemoryMap interface
my $fppmm = new FPP::MemoryMap;
# Open the maps
$fppmm->OpenMaps();
# Get info about the block we are interested in
my $blk = $fppmm->GetBlockInfo($name);
# Clear the block, probably not necessary
$fppmm->SetBlockColor($blk, 6, 48, 126); # Electric Blue - (6, 48, 126)
# Enable the block (pass 2 for transparent mode, or 3 for transparent RGB)
$fppmm->SetBlockState($blk, 1);
# Loop forever (ie, you'll need to CTRL-C to stop this script or kill it)
while (1) {
$fppmm->TextMessage($blk, \&GetNextMessage, $color, $fill, $font, $size, $pos, $dir, $pps);
}
# Disable the block
$fppmm->SetBlockState($blk, 0);
# Close the maps (shouldn't make it here with the above "while (1)" loop)
$fppmm->CloseMaps();
# Exit cleanly (shouldn't make it here with the above "while (1)" loop)
exit(0);
#############################################################################
[Unit]
Description=Ugh
[Service]
ExecStart=/home/fpp/script
StandardOutput=null
[Install]
WantedBy=multi-user.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment