diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2006-01-06 11:21:23 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2006-01-06 11:21:23 +0000 |
commit | 44eacabbffe8127f528a9f09593910233d55cd86 (patch) | |
tree | ecd833f408b02b5f22b950d2d08655426fe252af /monitor-edid | |
parent | 53c3590bd16fd8a0392974b8c08961ea18c91b9b (diff) | |
download | monitor-edid-44eacabbffe8127f528a9f09593910233d55cd86.tar monitor-edid-44eacabbffe8127f528a9f09593910233d55cd86.tar.gz monitor-edid-44eacabbffe8127f528a9f09593910233d55cd86.tar.bz2 monitor-edid-44eacabbffe8127f528a9f09593910233d55cd86.tar.xz monitor-edid-44eacabbffe8127f528a9f09593910233d55cd86.zip |
- monitor-get-edid is now a perl script able to probe /proc/acpi/video
(or /proc/device-tree on PPC)
- binary monitor-get-edid is now monitor-get-edid-using-vbe
- monitor-edid is able to get more than one head
Diffstat (limited to 'monitor-edid')
-rwxr-xr-x | monitor-edid | 100 |
1 files changed, 98 insertions, 2 deletions
diff --git a/monitor-edid b/monitor-edid index de3ce0c..5bc0bea 100755 --- a/monitor-edid +++ b/monitor-edid @@ -1,2 +1,98 @@ -#!/bin/sh -monitor-get-edid "$@" | monitor-parse-edid "$@" +#!/usr/bin/perl + +use Getopt::Long; + +my %opt = ('acpi-dir' => "/proc/acpi/video"); +my @common_options = ('verbose', 'try-in-console', 'no-vbe', 'acpi-dir=s'); + +if ($0 =~ /monitor-get-edid/) { + GetOptions_(@common_options) or die "usage: monitor-get-edid [-v] [--acpi-dir <dir>] [--try-in-console]\n"; + + if (my @edids = get_edids(1)) { + print $edids[0][1]; + exit 0; + } else { + exit 1; + } +} else { + GetOptions_(@common_options, 'MonitorsDB', 'perl') + or die "usage: monitor-edid [-v] [--acpi-dir <dir>] [--perl] [--MonitorsDB] [--try-in-console]\n"; + + my $err = 1; + + if (my @edids = get_edids()) { + print "(\n" if $opt{perl}; + foreach (@edids) { + my ($f, $edid) = @$_; + warn "parsing EDID from $f\n" if $opt{verbose}; + open(my $F, '|' . parse_edid()); + print $F $edid; + close $F and $err = 0; + print ",\n" if $opt{perl}; + } + print ")\n" if $opt{perl}; + } + exit $err; +} + +sub GetOptions_ { + my (@l) = @_; + GetOptions('v' => \$opt{verbose}, map { $_ => \$opt{/([^=]*)/ && $1} } @l); +} + +sub propagate_options { + my (@l) = @_; + map { $_ eq 'verbose' ? '-v' : "--$_" } grep { $opt{$_} } @l; +} + +sub get_using_vbe() { + my $prog = '/usr/sbin/monitor-get-edid-using-vbe'; + -x $prog && join(' ', $prog, propagate_options('verbose', 'try-in-console')); +} + +sub parse_edid() { + join(' ', './monitor-parse-edid', propagate_options('verbose', 'MonitorsDB', 'perl')); +} + +sub get_edids { + my ($b_get_first) = @_; + my @l = map { my $s = slurp($_); $s ? [ $_ => $s ] : () } get_edid_files(); + + if (!@l || !$b_get_first && $< == 0) { + if (my $cmd = get_using_vbe()) { + warn "probind EDID using VBE\n" if $opt{verbose}; + my $edid = `$cmd`; + if (grep { $_->[1] eq $edid } @l) { + # already found, forget it + } else { + push @l, [ vbe => $edid ]; + } + } + } + @l; +} + +sub get_edid_files() { + my @l1 = find_EDID("/proc/device-tree"); + my @l2 = grep { + (my $state_f = $_) =~ s/EDID$/state/; + my ($state) = slurp($state_f) =~ /state:\s*0x(\w+)/; + hex($state) & 2; # bit 1 is "Output is activated" + } find_EDID($opt{'acpi-dir'}); + (@l1, @l2); +} + +sub find_EDID { + my ($dir) = @_; + my @l; + require File::Find; + File::Find::find(sub { $_ eq 'EDID' and push @l, $File::Find::name }, $dir); + @l; +} + +sub slurp { + my ($f) = @_; + open(my $F, '<', $f) or return; + local $/; + scalar <$F>; +} |