Fix: setting to "0" works now.
authorHeiko Schlittermann <hs@schlittermann.de>
Tue, 06 Jan 2009 22:52:09 +0100
changeset 20 94281ba012c8
parent 19 6acf8ea44e0a
child 21 298db85d9c1d
Fix: setting to "0" works now. And some more improved example.
examples/client
lib/Quancom.pm
--- a/examples/client	Tue Jan 06 22:33:39 2009 +0100
+++ b/examples/client	Tue Jan 06 22:52:09 2009 +0100
@@ -6,14 +6,21 @@
 use strict;
 use warnings;
 use Quancom;
+use Time::HiRes qw(usleep);
 use Data::Dumper;
 
 MAIN: {
     my $q = new Quancom $ARGV[0];
 
     my $r;
-    $q->set(1, 8  => 1)->ok or die $q->last_result->error_message;
-    $q->set(2, 64 => 1)->ok or die $q->last_result->error_message;
+    foreach (1..64) {
+	$q->set($_ => 1);
+	usleep 1e6/20;
+    }
+    foreach (1..64) {
+	$q->set($_ => 0);
+	usleep 1e6/20;
+    }
 
     # reset
     $q->full_reset->ok or warn "err: " . $q->last_result->error_message . "\n";
--- a/lib/Quancom.pm	Tue Jan 06 22:33:39 2009 +0100
+++ b/lib/Quancom.pm	Tue Jan 06 22:52:09 2009 +0100
@@ -94,8 +94,11 @@
         my $bit   = $_ % 8;
         $groups[$group] |= (1 << $bit);
     }
-    $_ = "SX 0100 " . join "", map { sprintf "%02x ", $_ } reverse @groups;
-    $self->cmd($_);
+
+    my $cmd = $value ? "S" : "C";
+    $cmd .= "X 0100";
+    $cmd .= join "", map { sprintf "%02x ", $_ } reverse @groups;
+    $self->cmd($cmd);
 }
 
 sub set_timeout {
@@ -187,6 +190,10 @@
 this disables the socket communication and just simulates the Quancom
 module.
 
+=item B<set>( $bit, ... => $value )
+
+This sets one or more bits the specified values (true, false).
+
 =item B<cmd>( I<string> )
 
 Send a Quancom string to the device. The string here should be