Major changes to away system
[tpope-extra.git] / perl / mobile-phone-monitor
index 246cad502b0ed1c5a32c3b7fec8e1f021377b13d..535b4f67d898edd4e8e6ae4e4663bd95c6b0cf5e 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/perl
-# Author: Tim Pope
+# $Id$
+# -*- perl -*- vim: ft=perl sw=4 sts=4
 
 # Monitors a bluetooth mobile phome for calls.  You'll need to bind rfcomm1 to
 # your mobile phone's SP service.  You'll also need my Device::Nokia module
@@ -9,6 +10,8 @@ use strict;
 use Device::Nokia;
 my $number;
 my %status;
+my $quiton;
+my $daemonize;
 
 my $gsm = new Device::Nokia( port => '/dev/rfcomm1', log => 'file,/dev/null');
 
@@ -26,7 +29,12 @@ sub initialize {
 
 initialize($gsm) || die "Could not initialize modem: $!";
 
-daemonize() if (shift eq "-d");
+while($_=shift) {
+    $daemonize=1 if ($_ eq "-d");
+    $quiton=1 if ($_ eq "-b");
+}
+
+daemonize() if $daemonize;
 
 while(1) {
 %status=("is_active"=>1);
@@ -48,6 +56,7 @@ while($status{"is_active"} ne 0) {
     }
     undef $status{"number"} if (!$number && $status{"callsetup"}==0 && $status{"call"}==0);
     output_status(%status);
+    death() if ($status{"source"}==0 && $status{"callsetup"}==0 && $status{"call"}==0 && $quiton);
 }
 $gsm->disconnect();
 #print "Chillin'...\n";