Skip to content

Instantly share code, notes, and snippets.

@trytone
Last active January 28, 2020 12:55
Show Gist options
  • Save trytone/a7e4b3719193f3c849c80d021b932a0b to your computer and use it in GitHub Desktop.
Save trytone/a7e4b3719193f3c849c80d021b932a0b to your computer and use it in GitHub Desktop.
Convert RAW IR to Pronto Hex
use Data::Dumper;
# inputs
my $data = {
'Home' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 1500 500 1500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 1500 500 1500 500 500 500 1500 500 1500 500 1500 500',
'Auto' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 500 500 500 500',
'Spot' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 1500 500 1500 500 1500 500 500 500 1500 500 500 500',
'Single room' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 500 500 1500 500 1500 500 1500 500 500 500 500 500',
'Max' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 500 500 1500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 1500 500 1500 500 1500 500 500 500 1500 500 1500 500',
'Wall' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 1500 500',
'Play/Pause' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 1500 500 1500 500 1500 500 500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 1500 500 1500 500 500 500 1500 500',
'Pause' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 1500 500 1500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 1500 500 500 500 500 500 500 500',
'Up' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 500 500',
'Right' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 1500 500 1500 500 1500 500 500 500 1500 500',
'Down' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 1500 500 500 500 500 500 1500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 1500 500 500 500 1500 500 1500 500',
'Left' => '3000 3000 500 500 500 1500 500 1500 500 500 500 1500 500 500 500 500 500 500 500 1500 500 1500 500 500 500 500 500 500 500 1500 500 1500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 500 1500 500 500 500 1500 500 1500 500 1500 500 500 500'
};
my $frequency = 38000; # in Hz
foreach my $keyName (keys %{$data}){
my $codeData = $data->{$keyName};
$codeData =~ s/-//g;
$codeData =~ s/\+//g;
my @dataArray = split /\s/, $codeData;
my $dataCount = scalar @dataArray;
if($dataCount % 2 != 0){ $dataCount++; }
my $burstCount = int($dataCount/2);
my @prontoArray = ('0000'); # Word 1 - 0000 means that code was learned
push(@prontoArray, freq_2_hex($frequency) ); # Word 2 - dec = 1000000 / 0.241246 * frequency
push(@prontoArray, dec_2_hex($burstCount) ); # Word 3 - number of Burst Pairs in Burst Pair Sequence #1 - non reapeated
push(@prontoArray, dec_2_hex(0) ); # Word 4 - number of Burst Pairs in Burst Pair Sequence #2 - reapeated
for(my $i = 0; $i < scalar @dataArray; $i=$i+2){
my $onTimeMs = $dataArray[$i];
my $offTimeMs = $dataArray[$i+1];
if(!$offTimeMs){ $offTimeMs = 3000; }
my $decOn = int( ($onTimeMs * $frequency) / 1000000 );
my $decOff = int( ($offTimeMs * $frequency) / 1000000 );
push(@prontoArray, dec_2_hex($decOn) );
push(@prontoArray, dec_2_hex($decOff) );
}
my $str = join " ", @prontoArray;
open(OUT,'>>','pronto.txt');
print OUT "$keyName : $str\n";
close(OUT);
}
sub freq_2_hex{
my $freq = shift;
my $dec = int(1000000 / (0.241246 * $freq));
return dec_2_hex($dec);
}
sub dec_2_hex{
my $dec = shift;
return sprintf("%04X", $dec);
}
#0000 - Means that code was learned
#006D - 109 DEC = 38kHz // Freq=1 000 000 / (109 * 0.241246) = ?38 028
#002A - 42 DEC // number of Burst Pairs in Burst Pair Sequence #1 - non reapeated
#0000 - 0 DEC // number of Burst Pairs in Burst Pair Sequence #2 - repeated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment