Permalink
Browse files

delete old scripts

  • Loading branch information...
Luke Closs
Luke Closs committed Nov 13, 2012
1 parent f36099b commit 057a813b28cd206c3d2e95dcd00fa342085a167a
Showing with 0 additions and 486 deletions.
  1. +0 −152 bin/arduino-daemon
  2. +0 −22 bin/arduino-hook
  3. +0 −45 bin/if-can-lock
  4. +0 −214 bin/serialserver.py
  5. +0 −53 bin/serialserverd
View
@@ -1,152 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-use FindBin;
-use lib "$FindBin::Bin/../lib";
-use VHS;
-use AnyEvent::Twitter::Stream;
-use Fatal qw/open close/;
-use Parallel::ForkManager;
-
-my $arduino_file = '/dev/ttyUSB0';
-
-my $done = AnyEvent->condvar;
-my $forkmanager = Parallel::ForkManager->new(1);
-open(my $arduino_rfh, $arduino_file);
-
-binmode STDOUT, ":utf8";
-
-$SIG{INT} = sub { print "Exiting... \n" };
-
-my @temp_requests;
-my $to_arduino_event = sub {
- my $tweet = shift;
- my $tweeter = $tweet->{user}{screen_name};
- print "TWITTER: $tweeter: $tweet->{text}\n";
-
- # Ignore our own tweets
- return if $tweeter eq 'vhs45w';
-
- if ($tweet->{text} =~ m/\btemp(erature)?\b/) {
- print " Sending temperature request\n";
- open(my $arduino_wfh, ">$arduino_file");
- print $arduino_wfh "temperature\n";
- close $arduino_wfh;
-
- push @temp_requests, $tweeter;
- }
-};
-my $streamer = AnyEvent::Twitter::Stream->new(
- username => VHS->config->{twitter_username},
- password => VHS->config->{twitter_password},
- method => 'follow',
- follow => '61112230',
- on_tweet => $to_arduino_event,
- on_error => sub {
- my $error = shift;
- warn "ERROR: $error";
- $done->send;
- },
- on_eof => sub {
- $done->send;
- },
-);
-
-my $hdl = AnyEvent::Handle->new(
- fh => $arduino_rfh,
- on_error => sub {
- my ($hdl, $fatal, $msg) = @_;
- warn "Arduino Read filehandle: $msg\n";
- $hdl->destroy;
- $done->send;
- },
- on_read => sub {
- my $handle = shift;
- $handle->push_read(
- line => sub {
- my ($h, $line, $eol) = @_;
- return unless length $line;
-
- if ($line =~ s/^#//) {
- warn "From arduino: $line\n";
- return;
- }
- my @args = split m/\s+/, $line;
-
- if ($line =~ m/temperature/ and scalar @temp_requests) {
- my $user = shift @temp_requests;
- if ($user eq 'STDIN') {
- print "$line\n";
- return;
- }
-
- push @args, $user;
- }
- run_command_from_arduino( @args );
- },
- );
- },
-);
-
-my $stdin_hdl = AnyEvent::Handle->new(
- fh => \*STDIN,
- on_error => sub {
- my ($hdl, $fatal, $msg) = @_;
- warn "STDIN: $msg\n";
- $hdl->destroy;
- },
- on_read => sub {
- my $handle = shift;
- $handle->push_read(
- line => sub {
- my ($h, $line, $eol) = @_;
- return unless length $line;
-
- if ($line eq 'quit') {
- $done->send;
- return;
- }
- my $tweet = {
- text => $line,
- user => { screen_name => 'STDIN' },
- };
- $to_arduino_event->($tweet);
- },
- );
- },
-);
-
-$done->recv;
-exit;
-
-
-sub run_command_from_arduino {
- my $command = shift;
- my @args = @_;
- my $now = localtime;
- print "$now: Received command: $command args: ("
- . join(', ', @args) . ")\n";
- log_it("$command @args");
-
- my $script_dir = "$FindBin::Bin/../hooks/${command}.d";
- return unless -d $script_dir;
- my @scripts = glob("$script_dir/*");
- for my $script (@scripts) {
- next unless -x $script;
-
- my $pid = $forkmanager->start and next;
- print "Running $script\n";
- local $ENV{PERL5LIB} = "$FindBin::Bin/../lib";
- system($script, @args);
- $forkmanager->finish;
- }
-}
-
-sub log_it {
- my $log_string = shift;
- my $log_file = "/var/log/vhs.log";
- open(my $fh, ">>$log_file");
- my $now = localtime;
- print $fh "$now: $log_string\n";
- close $fh;
-}
View
@@ -1,22 +0,0 @@
-#!/usr/bin/perl
-use strict;
-use warnings;
-use IO::Socket::INET;
-use FindBin;
-use lib "$FindBin::Bin/../lib";
-use VHS;
-
-my $sock = IO::Socket::INET->new(
- PeerAddr => 'localhost',
- PeerPort => '9994',
- Proto => 'tcp'
-);
-
-while (my $line = <$sock>) {
- chomp $line;
- VHS->run_command_from_arduino( split /\s+/, $line );
-}
-
-exit;
-
-
View
@@ -1,45 +0,0 @@
-#!/usr/bin/env perl
-use warnings;
-use strict;
-
-use Fcntl ':flock';
-
-sub usage {
- print <<'END_OF_HELP';
- USAGE:
- if-can-lock LOCKFILE [--contents=string] COMMAND [ARGS ...]
-
- Tries to acquire an exclusive lock on LOCKFILE. Exits nonzero
- immediately if LOCKFILE does not exist. Exits 0 immediately if it is
- unable to acquire the lock. Otherwise, execs COMMAND with ARGS (the
- lock will continue to be held after the exec). When COMMAND exits,
- the lock will automatically be released.
-END_OF_HELP
- exit 0;
-}
-
-usage() if @ARGV < 2;
-
-my $lockfile = shift or die "Must specify lockfile\n";
-my $contents;
-if ( $ARGV[0] && ( $ARGV[0] =~ m/--contents=(.+)/ ) ) {
- $contents = $1;
- shift @ARGV;
-}
-usage() unless @ARGV;
-
-my $mode = -e $lockfile ? '+<' : '>';
-
-open L, $mode, $lockfile or die "Can't open $mode $lockfile: $!\n";
-flock L, LOCK_EX|LOCK_NB or exit 1;
-if ( defined $contents ) {
- $|++;
- print L $contents, "\n";
-}
-
-system @ARGV;
-my $rc = $?;
-close L;
-unlink $lockfile;
-exit $rc;
-
Oops, something went wrong.

0 comments on commit 057a813

Please sign in to comment.