added lines for additional sensor
[vaillant-thermostat] / pgm2fb.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 my $path = shift @ARGV || die "usage: $0 image.pgm";
6
7 my $o_x = $ENV{O_X} || 0;
8 my $o_y = $ENV{O_Y} || 0;
9
10 open(my $in, '<', $path) || die "$path: $!";
11
12 my $magic = <$in>;
13 die "wrong magic $magic" unless $magic =~ m/^P5/;
14 my $size = <$in>;
15 chomp $size;
16 my ( $w, $h ) = split(/ /,$size);
17 <$in>;
18
19 my $fb;
20
21 my $y = 0;
22
23 seek($in, $w * $o_y, 1) if $o_y;
24
25 while(my $size = read($in, my $px, $w)) {
26
27         foreach my $x ( 0 .. $w / 2 - 1 ) {
28
29                 my ($a,$b);
30
31                 if ( length($px) < $x * 2 + $o_x + 2 ) {
32                         print "\x00";
33                 } else {        
34
35                         my ($a,$b) = unpack('CC', substr($px,$x * 2 + $o_x,2));
36                         print pack( 'C', (
37                                 ( $a & 0xf0 )
38                                 |
39                                 ( ( $b & 0xf0 ) >> 4 )
40                         ) ^ 0xff );
41
42                 }
43
44         }
45
46         $y++;
47         last if $y == $h;
48 }
49