#!/usr/bin/perl # # Script to take a LIRC configuration file for skyplus and try to turn it # into sanitized ascii waveform diagrams # # (C) Copyright Joseph Heenan 2005 # Released into the public domain; please do whatever you want with this, # but don't hold me liable if it does something bad for you. my $sink = 1; my $text = ""; while (<>) { chomp; if (/begin raw_codes/) { $sink=0; next; } next if ($sink); $sink=0; if (!/name/ && !/end raw_codes/) { $text .= $_; next; } if ($text !~ /\w/) { $text = $_; next; } my @data = split(/\s+/, $text); my $key; shift @data; # sink empty first field shift @data; # "name" $key = shift @data; # keyname printf "%-24s",$key; my $state = 1; print "___"; my $cnt = 0; my $data = ""; foreach my $v (@data) { my $c; my $n; if ($state == 1) { $c = "-"; $n = 6 if ($v >2620 && $v < 2910); $n = 2 if ($v >800 && $v < 1489); $n = 1 if ($v >430 && $v < 695); } else { $c = "_"; $n = 2 if ($v >640 && $v < 900); $n = 1 if ($v >188 && $v < 460); } if (!defined($n)) { print "unknown val $v in state $state\n"; exit; } $cnt += $n; print " " if ($cnt == 29); if ($cnt >= 29) { $data .= "$c"x$n; } print "$c"x$n; $state=1-$state; } $data .= "___"; print "___ "; my $fullval; foreach my $x (1 .. 2) { my $val = 0; foreach my $x (1 .. 8) { $data =~ /^(..)/; $val <<= 1; if ($1 eq "_-") { # nothing } elsif ($1 eq "-_") { $val++; } else { print "unknown bits: $1 "; } $data =~ s/^..//; } print "$val "; $fullval = ($fullval << 8) + $val; } printf "(%04x)", $fullval; print "\n"; last if (/end raw_codes/); $text = $_; }