Floorplan image overlay (improved floorplan.pl)

View: New views
1 Messages — Rating Filter:   Alert me  

Floorplan image overlay (improved floorplan.pl)

by Michael-546 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

It annoyed me how the floorplan.pl code in MH meant you couldn't simply include an image, jpg/gif etc, and overlay with x/y coords.

so .. i wrote a floorplan.pl replacement, which allows you to include a jpg/gif, then set simple x/y coords for your X10 devices.

You can also set an image for each of the items, so if its a light you select a light image etc, which has an on/off similar to the existing floorplan.pl code.

you can grab the perl code from here (and see cut down screenshot)
http://shellshovel.com/ha/mh-floorplan.html

or here it is:



#!/usr/bin/perl
# shellshovel.com/ha/

# user defined variables
my $floorplan = '/ap/floorplan.jpg';

# array of objects with manual positioning, and logo
# it would be nice to add/define these things in items.mht instead
my %ap_objects = (
        # name = name of the object (must match items.mht)
        # top = top position in pixels
        # left = left position in pixels
        # img = image you want to link too (note '-off' / '-on' is appended to the image)
        us_lamp1 => {
                top => '355', left => '280', img => 'ap-light'
        },
        ds_lamp1 => {
                top => '370', left => '75', img => 'ap-light'
        }
        hawkeye1 => {
               top => '5', left => '60', img => 'ap-motion'
        },
        eye1 => {
               top => '15', left => '70', img => 'ap-eye'
        },
        eye2 => {
               top => '20', left => '80', img => 'ap-eye'
        }
);

#
# end user configured variables.
#

use CGI;
my $a = new CGI;

print "Content-Type: text/html\n\n";
print qq|<head>\n<style type="text/css">\n|;
print qq|#container a {\nposition: absolute;\n}\n|;
print qq|#container a img {border-style: none;}\n|;

# positioning of each object
for my $obj ( keys %ap_objects ) {
        print "#$obj { left: " . $ap_objects{$obj}{'left'} . "px; ";
        print "top: " . $ap_objects{$obj}{'top'} . "px; }\n";
}
print qq|</style>\n</head>\n|;
# end header/styles

# start body
print qq|<body>\n<div id="container">\n|;

## you can use items.mht below, just replace
# my (@objects);
# @objects = &list_objects_by_type('Property');
# @objects = &list_objects_by_group('Property') unless @objects;
## or use our array map
my @objects = map { my $key = $_; } keys %ap_objects;

# run through them and display the href/img src
for my $item (sort @objects) {
        next unless $item;
        my $object = &get_object_by_name($item);
        next if $object->{hidden};
        # get state
        my $state = undef;
        if ($object->can('state_level')) {
                $state = $object->state_level();
        } elsif ($object->can('state')) {
                $state = $object->state();
        }
        my $state_new = (!defined $state or $state eq 'off') ? 'on' : 'off';
        # display the item
        print "<a id='$item' href='/SET?$item=$state_new'><img src='/graphics/" . $ap_objects{$item}{'img'} . "-" . $object->state . ".gif'></a>\n";
}


# floorplan image and /body
print qq|<img src='$floorplan' border='0'>\n|;
print qq|</div>\n</body>\n|;








------------------------------------------------------------------------------
Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9-12, 2009. Register now!
http://p.sf.net/sfu/devconf
________________________________________________________
To unsubscribe from this list, go to: http://sourceforge.net/mail/?group_id=1365