Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Perl to cook you coffee

by kirillm (Friar)
on Feb 06, 2011 at 22:35 UTC ( #886566=CUFP: print w/replies, xml ) Need Help??

... well, not really cook it (yet), but at least weight it give you a hint when it's time to re-fill.

Coffee is a magic beverage. We all know that. Some are immune to magic, but that does not change the fact that the coffee has magic qualities. And it is frustrating to come to a coffee pot which is empty. So, my friends at Copyleft in Oslo screwed together an online monitor to graph current state of the coffee pot and also show some historical trends.

The thing is built with USB-scale and some other things glued together with a Perl-script. And you do not dare to see how this all looks like. It is really horrible. But works.

Enjoy your coffe :)

Note: I did not write the code, I'm just sharing another CUFP.

Replies are listed 'Best First'.
Re: Perl to cook you coffee
by jwkrahn (Monsignor) on Feb 07, 2011 at 07:33 UTC
    if ($device eq undef) { die "Usage: <app> /dev/hidrawN"; exit; }

    undef is neither a string nor a number.    You have to use the defined function to test whether a variable is defined or not.    Or you could just test whether @ARGV was empty or not.    die exits from the program so using exit there is superfluous.

    @ARGV or die "Usage: <app> /dev/hidrawN";


    my $report = ord(substr($data, 1, 1)); my $status = ord(substr($data, 2, 1)); my $unit = ord(substr($data, 3, 1)); my $exp = ord(substr($data, 4, 1)); my $lsb = ord(substr($data, 5, 1)); my $msb = ord(substr($data, 6, 1)); my $weight = ($msb * 255 + $lsb) / 10; if($exp != 255 && $exp != 0) { $weight ^= $exp; }

    If you used unpack you could extract all your data in one statement and you wouldn't have to calculate the $weight value yourself, which is calculated wrong because you should be multiplying by 256, not 255.

    my ( $report, $status, $unit, $exp, $weight ) = unpack 'xCCCCS', $ +data $weight /= 10; if ( $exp != 255 && $exp != 0 ) { $weight ^= $exp; }

      Ah, uh, die() and exit()... I'll let 'em know about the suggestions.

Re: Perl to cook you coffee
by ack (Deacon) on Feb 07, 2011 at 16:15 UTC

    Wow! That's definitely a CUFP! I wish I had the creativity or time to do something like that. It's about 200 steps for me to go from my office to the coffee pot and I, too, hate it when I get there and find out its empty.

    jwkrahn's comments are good, too. Thanks, kirillm and jwkrahn. That made for a lighter Monday morning here for me.

    ack Albuquerque, NM
Re: Perl to cook you coffee
by elwarren (Curate) on Feb 08, 2011 at 15:50 UTC
    Cool. I could probably use the same setup to track the coffee mug on my desk.
Re: Perl to cook you coffee
by gnusosa (Initiate) on Feb 09, 2011 at 20:04 UTC
    This reminds me of Coffee-HOW-TO.
Re: Perl to cook you coffee
by blakew (Monk) on Feb 11, 2011 at 04:32 UTC
    Could you post the data?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: CUFP [id://886566]
Approved by Corion
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2020-10-31 20:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (291 votes). Check out past polls.

    Notices?