From e7a03df5aedc83f3198057ea78f9cea4957959fa Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Wed, 18 May 2011 02:20:50 +0200
Subject: [PATCH 01/19] brmd::Alphasign: Improved input checking
---
brmd/brmd.pl | 2 ++
1 file changed, 2 insertions(+)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index d2bc4f4..ab7e86d 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -837,6 +837,8 @@ sub text {
my ($heap, $self, $mode, $string) = (@_[HEAP, OBJECT, ARG0, ARG1]);
$mode = $modes{$mode};
$self->{last_text} = $string;
+ $string = substr($string, 0, 256);
+ $string =~ s/[\000-\037]//g;
$string =~ s/<\/(.*?)>/$markup{$1}->[1]/gei;
$string =~ s/<(.*?)>/$markup{$1}->[0]/gei;
$_[KERNEL]->yield('rawtext', $mode, $string);
From 387820a60d6a1ecbc9e8dcc0a922ad6e5ce293bc Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Wed, 18 May 2011 02:30:13 +0200
Subject: [PATCH 02/19] brmd::Alphasign: Remember last mode too
---
brmd/brmd.pl | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index ab7e86d..0255d24 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -414,10 +414,11 @@ sub web_alphasign_text {
$response->push_header("Content-Type", "text/html");
disable_caching($response);
my $text = $alphasign->last_text_escaped();
+ my $lm = $alphasign->last_mode();
my $help = $alphasign->markup_help();
$help =~ s/&/&/g; $help =~ s/</g; $help =~ s/>/>/g;
$help =~ s/\n/
/g;
- my $modes = join("\n", map { "" } $alphasign->mode_list());
+ my $modes = join("\n", map { "" } $alphasign->mode_list());
$response->content(<
@@ -665,7 +666,7 @@ use Tie::IxHash;
sub new {
my $class = shift;
- my $self = bless { last_text => '' }, $class;
+ my $self = bless { last_text => '', last_mode => 'hold' }, $class;
POE::Session->create(
object_states => [
@@ -835,6 +836,7 @@ sub markup_help {
sub text {
my ($heap, $self, $mode, $string) = (@_[HEAP, OBJECT, ARG0, ARG1]);
+ $self->{last_mode} = $mode;
$mode = $modes{$mode};
$self->{last_text} = $string;
$string = substr($string, 0, 256);
@@ -843,6 +845,10 @@ sub text {
$string =~ s/<(.*?)>/$markup{$1}->[0]/gei;
$_[KERNEL]->yield('rawtext', $mode, $string);
}
+sub last_mode {
+ my $self = shift;
+ return $self->{last_mode};
+}
sub last_text {
my $self = shift;
return $self->{last_text};
From e5d62db85155e66250267eb4a1f330f7a0874d98 Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Wed, 18 May 2011 02:30:28 +0200
Subject: [PATCH 03/19] brmd::Alphasign: Beep on stream_start()
---
brmd/brmd.pl | 1 +
1 file changed, 1 insertion(+)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 0255d24..68685fa 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -862,6 +862,7 @@ sub last_text_escaped {
sub stream_start {
$_[KERNEL]->yield('text', 'hold', "ON AIR");
+ $_[KERNEL]->yield('beep');
}
sub stream_stop {
From 76355651201b4e53ef7f1ce7d1fb4a908148728f Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Wed, 18 May 2011 02:30:59 +0200
Subject: [PATCH 04/19] brmd::Alphasign: Add beep checkbox to web interface
---
brmd/brmd.pl | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 68685fa..81e7066 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -433,6 +433,7 @@ sub web_alphasign_text {
New text:
+ beep
@@ -450,8 +451,12 @@ sub web_alphasign_set {
my $q = new CGI($request->content);
my $mode = $q->param('mode');
my $text = $q->param('text');
+ my $beep = $q->param('beep');
- $streaming or $poe_kernel->post($alphasign, 'text', $mode, $text);
+ if (not $streaming) {
+ $poe_kernel->post($alphasign, 'text', $mode, $text);
+ $beep and $poe_kernel->post($alphasign, 'beep');
+ }
$response->protocol("HTTP/1.1");
$response->code(302);
From 5398773e1b199e43c9b8f8676ea5df586d25dc94 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Wed, 22 Jun 2011 17:53:01 +0200
Subject: [PATCH 05/19] add wolfram alpha (!alpha) command
---
brmd/brmd.pl | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index bd03595..096bf84 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -1,10 +1,12 @@
#!/usr/bin/perl
# 2011 (c) Petr Baudis , brmlab
+# 2011 (c) Pavol Rusnak , brmlab
# You can distribute this under the same terms as Perl itself.
use strict;
use warnings;
use POE;
+use WWW::WolframAlpha;
our $channel = "#brmlab";
our $streamurl = "http://video.hrach.eu:8090/brmstream.asf";
@@ -538,10 +540,30 @@ sub irc_public {
my $nick = ( split /!/, $who )[0];
my $channel = $where->[0];
- if ( my ($rot13) = $what =~ /^rot13 (.+)/ ) {
+ if ( my ($rot13) = $what =~ /^!rot13 (.+)/ ) {
$rot13 =~ tr[a-zA-Z][n-za-mN-ZA-M];
$irc->yield( privmsg => $channel => "$nick: $rot13" );
}
+
+ if ( my ($alpha) = $what =~ /^!alpha (.+)/ ) {
+ my $answer = '';
+ my $wa = WWW::WolframAlpha->new ( appid => 'P6XPHG-URK5HXVWXL', );
+ my $query = $wa->query( input => $alpha, );
+ if ($query->success) {
+ foreach my $pod (@{$query->pods}) {
+ if (!$pod->error) {
+ foreach my $subpod (@{$pod->subpods}) {
+ if ($subpod->plaintext) {
+ $answer += ($pod->title . ': ') if $pod->title;
+ $answer += ($subpod->title . ': ') if $subpod->title;
+ $answer += ($subpod->plaintext . "\n");
+ }
+ }
+ }
+ }
+ }
+ $irc->yield( privmsg => $channel => $answer ) if $answer;
+ }
}
sub irc_332 {
From fdac0b1044feb76ae6b266d5777c7c45cd935632 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Wed, 22 Jun 2011 18:07:02 +0200
Subject: [PATCH 06/19] fix concatenation
---
brmd/brmd.pl | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 096bf84..72a61aa 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -554,9 +554,9 @@ sub irc_public {
if (!$pod->error) {
foreach my $subpod (@{$pod->subpods}) {
if ($subpod->plaintext) {
- $answer += ($pod->title . ': ') if $pod->title;
- $answer += ($subpod->title . ': ') if $subpod->title;
- $answer += ($subpod->plaintext . "\n");
+ $answer .= ($pod->title . ': ') if $pod->title;
+ $answer .= ($subpod->title . ': ') if $subpod->title;
+ $answer .= ($subpod->plaintext . "\n");
}
}
}
From db22869e4e5c72618ecea57d30e94ea05fe24ada Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Wed, 22 Jun 2011 18:11:20 +0200
Subject: [PATCH 07/19] rework answer
---
brmd/brmd.pl | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 72a61aa..25c9262 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -546,7 +546,6 @@ sub irc_public {
}
if ( my ($alpha) = $what =~ /^!alpha (.+)/ ) {
- my $answer = '';
my $wa = WWW::WolframAlpha->new ( appid => 'P6XPHG-URK5HXVWXL', );
my $query = $wa->query( input => $alpha, );
if ($query->success) {
@@ -554,15 +553,16 @@ sub irc_public {
if (!$pod->error) {
foreach my $subpod (@{$pod->subpods}) {
if ($subpod->plaintext) {
+ my $answer = '';
$answer .= ($pod->title . ': ') if $pod->title;
$answer .= ($subpod->title . ': ') if $subpod->title;
- $answer .= ($subpod->plaintext . "\n");
+ $answer .= $subpod->plaintext;
+ $irc->yield( privmsg => $channel => $answer );
}
}
}
}
}
- $irc->yield( privmsg => $channel => $answer ) if $answer;
}
}
From fc805c78cbfe8938ebe1926e399d261e864a8850 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Wed, 22 Jun 2011 18:12:55 +0200
Subject: [PATCH 08/19] add nick
---
brmd/brmd.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 25c9262..b615771 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -557,7 +557,7 @@ sub irc_public {
$answer .= ($pod->title . ': ') if $pod->title;
$answer .= ($subpod->title . ': ') if $subpod->title;
$answer .= $subpod->plaintext;
- $irc->yield( privmsg => $channel => $answer );
+ $irc->yield( privmsg => $channel => "$nick: $answer" );
}
}
}
From f057156b42582409e3127f07a41603ee39b0fa5f Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Wed, 22 Jun 2011 18:14:40 +0200
Subject: [PATCH 09/19] use - instead of :
---
brmd/brmd.pl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index b615771..6935ce0 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -554,8 +554,8 @@ sub irc_public {
foreach my $subpod (@{$pod->subpods}) {
if ($subpod->plaintext) {
my $answer = '';
- $answer .= ($pod->title . ': ') if $pod->title;
- $answer .= ($subpod->title . ': ') if $subpod->title;
+ $answer .= ($pod->title . ' - ') if $pod->title;
+ $answer .= ($subpod->title . ' - ') if $subpod->title;
$answer .= $subpod->plaintext;
$irc->yield( privmsg => $channel => "$nick: $answer" );
}
From ced66e2f113d629a695dde693a73613285ed87b3 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Wed, 22 Jun 2011 18:17:25 +0200
Subject: [PATCH 10/19] sanitise newlines
---
brmd/brmd.pl | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 6935ce0..8f95f7c 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -554,9 +554,10 @@ sub irc_public {
foreach my $subpod (@{$pod->subpods}) {
if ($subpod->plaintext) {
my $answer = '';
- $answer .= ($pod->title . ' - ') if $pod->title;
- $answer .= ($subpod->title . ' - ') if $subpod->title;
+ $answer .= ($pod->title . ': ') if $pod->title;
+ $answer .= ($subpod->title . ': ') if $subpod->title;
$answer .= $subpod->plaintext;
+ $answer =~ s/\n/, /g;
$irc->yield( privmsg => $channel => "$nick: $answer" );
}
}
From adaaad8084e3b1f4ad81c1f069aa11c8cbd61aa1 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Tue, 5 Jul 2011 21:57:09 +0200
Subject: [PATCH 11/19] allow change of alphasign even while streaming
---
brmd/brmd.pl | 8 +++-----
1 file changed, 3 insertions(+), 5 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 8f95f7c..b5a13c4 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -286,7 +286,7 @@ sub web_index {
my $astext = $alphasign->last_text_escaped();
my $a_link = '';
- $streaming or $a_link .= 'change';
+ $a_link .= 'change';
$response->content(<
@@ -455,10 +455,8 @@ sub web_alphasign_set {
my $text = $q->param('text');
my $beep = $q->param('beep');
- if (not $streaming) {
- $poe_kernel->post($alphasign, 'text', $mode, $text);
- $beep and $poe_kernel->post($alphasign, 'beep');
- }
+ $poe_kernel->post($alphasign, 'text', $mode, $text);
+ $beep and $poe_kernel->post($alphasign, 'beep');
$response->protocol("HTTP/1.1");
$response->code(302);
From 6b9575013ba33d7f469781fa9390bfe0585cc4c8 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Tue, 5 Jul 2011 22:08:15 +0200
Subject: [PATCH 12/19] Revert "allow change of alphasign even while streaming"
This reverts commit adaaad8084e3b1f4ad81c1f069aa11c8cbd61aa1.
---
brmd/brmd.pl | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index b5a13c4..8f95f7c 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -286,7 +286,7 @@ sub web_index {
my $astext = $alphasign->last_text_escaped();
my $a_link = '';
- $a_link .= 'change';
+ $streaming or $a_link .= 'change';
$response->content(<
@@ -455,8 +455,10 @@ sub web_alphasign_set {
my $text = $q->param('text');
my $beep = $q->param('beep');
- $poe_kernel->post($alphasign, 'text', $mode, $text);
- $beep and $poe_kernel->post($alphasign, 'beep');
+ if (not $streaming) {
+ $poe_kernel->post($alphasign, 'text', $mode, $text);
+ $beep and $poe_kernel->post($alphasign, 'beep');
+ }
$response->protocol("HTTP/1.1");
$response->code(302);
From 3812b24d11066f1afd4ce19328fb5c7d24548f89 Mon Sep 17 00:00:00 2001
From: Pavol Rusnak
Date: Sun, 31 Jul 2011 19:00:19 +0200
Subject: [PATCH 13/19] fix output
---
brmdoor/brmdoor.pde | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/brmdoor/brmdoor.pde b/brmdoor/brmdoor.pde
index 774eef6..f509763 100644
--- a/brmdoor/brmdoor.pde
+++ b/brmdoor/brmdoor.pde
@@ -142,7 +142,7 @@ void readCard()
if (!known) {
comSerial.write("CARD UNKNOWN ");
for (int i = 0; i < 7; ++i) {
- if (buf[i+3] < 0xF) comSerial.write("0");
+ if (buf[i+3] <= 0xF) comSerial.write("0");
comSerial.print(buf[i+3], HEX);
}
comSerial.write("\n");
From ec3cabebf063b239aefa40cc2a35c7419cfe1fa5 Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Mon, 29 Aug 2011 21:59:53 +0200
Subject: [PATCH 14/19] Enhanced WolframAlpha output display, limit number of
lines
---
brmd/brmd.pl | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 8f95f7c..2c76ba2 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -473,6 +473,7 @@ sub web_alphasign_set {
package brmd::IRC;
use POE qw(Component::IRC Component::IRC::Plugin::Connector);
+use URI;
sub new {
my $class = shift;
@@ -549,20 +550,35 @@ sub irc_public {
my $wa = WWW::WolframAlpha->new ( appid => 'P6XPHG-URK5HXVWXL', );
my $query = $wa->query( input => $alpha, );
if ($query->success) {
- foreach my $pod (@{$query->pods}) {
+ my $first = 1;
+ my $npods = 3;
+ foreach my $pod (@{$query->pods}[0..$npods-1]) {
+ $pod or next;
if (!$pod->error) {
+ my @answers;
+ push @answers, $pod->title if $pod->title;
foreach my $subpod (@{$pod->subpods}) {
if ($subpod->plaintext) {
- my $answer = '';
- $answer .= ($pod->title . ': ') if $pod->title;
- $answer .= ($subpod->title . ': ') if $subpod->title;
- $answer .= $subpod->plaintext;
- $answer =~ s/\n/, /g;
- $irc->yield( privmsg => $channel => "$nick: $answer" );
+ my $sanswer = '';
+ $sanswer .= ($subpod->title . ': ') if $subpod->title;
+ $sanswer .= $subpod->plaintext;
+ push @answers, split (/\n+/, $sanswer);
}
}
+ if ($first) {
+ my $sanswer = URI->new("http://www.wolframalpha.com/input/?i=$alpha")->as_string;
+ $sanswer .= " (trimmed)" if (@{$query->pods} > $npods);
+ push @answers, $sanswer;
+ $first = 0;
+ }
+ my $answer = join(" \3"."14::\3 ", @answers);
+ $irc->yield( privmsg => $channel => "$nick: $answer" );
+ } else {
+ $irc->yield( privmsg => $channel => "$nick: Error " . $pod->error->code . ": " . $pod->error->msg );
}
}
+ } else {
+ $irc->yield( privmsg => $channel => "$nick: No results." );
}
}
}
From 91b2c16e696d50bebcb7d87784c56ffc1c68b082 Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Tue, 30 Aug 2011 03:13:10 +0200
Subject: [PATCH 15/19] brmd: Convert modes,markup from our to my, local to
Alphasign
---
brmd/brmd.pl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 2c76ba2..6c97d25 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -815,7 +815,7 @@ sub rawtext {
}
}
-our %modes;
+my %modes;
BEGIN {
tie(%modes, 'Tie::IxHash',
'hold' => 'b',
@@ -856,7 +856,7 @@ tie(%modes, 'Tie::IxHash',
sub mode_list {
return keys %modes;
}
-our %markup;
+my %markup;
BEGIN {
tie(%markup, 'Tie::IxHash',
red => ["\x1C1", "\x1C1"],
From beb0118ded77eb8f5d565540eb9adcef56bd67ea Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Tue, 30 Aug 2011 23:16:07 +0200
Subject: [PATCH 16/19] Sketch: Fix reading new video/status state
---
brmdoor/brmdoor.pde | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/brmdoor/brmdoor.pde b/brmdoor/brmdoor.pde
index f509763..ad99c3e 100644
--- a/brmdoor/brmdoor.pde
+++ b/brmdoor/brmdoor.pde
@@ -159,8 +159,8 @@ void readSerial()
unsigned char cmd = comSerial.read();
unsigned char data = comSerial.read();
switch (cmd) {
- case 's': statusState = data; statusStateOverride = 1; break;
- case 'v': videoState = data; videoStateOverride = 1; break;
+ case 's': statusState = data - '0'; statusStateOverride = 1; break;
+ case 'v': videoState = data - '0'; videoStateOverride = 1; break;
}
}
}
From e3935c031ec63bcd7d5bacbff67f0fdadc6c20e0 Mon Sep 17 00:00:00 2001
From: Petr Baudis
Date: Tue, 30 Aug 2011 23:18:01 +0200
Subject: [PATCH 17/19] Fix manual status change desyncing arduino
---
brmd/brmd.pl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index 6c97d25..d774acb 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -116,7 +116,7 @@ sub _start {
Handle => serial_open($devdoor),
Filter => POE::Filter::Line->new(
InputLiteral => "\x0A", # Received line endings.
- OutputLiteral => "\x0A", # Sent line endings.
+ OutputLiteral => "", # Sent line endings.
),
InputEvent => "serial_input",
ErrorEvent => "serial_error",
@@ -396,7 +396,7 @@ sub web_brmstatus_switch {
my $q = new CGI($request->content);
my $nick = $q->param('nick');
- my $newstatus = not $status;
+ my $newstatus = 0 + not $status;
foreach (@{$self->{observers}}) {
$poe_kernel->post($_, 'status_update', $newstatus, 'web', $nick);
}
From 0a770684eacc577c821b43b7644890760e973fbc Mon Sep 17 00:00:00 2001
From: Ruzicka Pavel
Date: Thu, 8 Sep 2011 00:38:16 +0200
Subject: [PATCH 18/19] stream URL simplification
---
brmd/brmd.pl | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/brmd/brmd.pl b/brmd/brmd.pl
index d774acb..b8c805b 100755
--- a/brmd/brmd.pl
+++ b/brmd/brmd.pl
@@ -9,7 +9,7 @@ use POE;
use WWW::WolframAlpha;
our $channel = "#brmlab";
-our $streamurl = "http://video.hrach.eu:8090/brmstream.asf";
+our $streamurl = "http://brmlab.cz/stream";
our $devdoor = $ARGV[0]; $devdoor ||= "/dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A700e1qB-if00-port0";
our $devasign = $ARGV[1]; $devasign ||= "/dev/serial/by-id/usb-1a86_USB2.0-Serial-if00-port0";
our ($status, $streaming, $topic) = (0, 0, 'BRMLAB OPEN');
From 5834f727025f5e6ab0ee489dabec253091daa98e Mon Sep 17 00:00:00 2001
From: Ruzicka Pavel
Date: Thu, 8 Sep 2011 02:37:08 +0200
Subject: [PATCH 19/19] few lines to README
---
README | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/README b/README
index 444ec8c..1c10404 100644
--- a/README
+++ b/README
@@ -1 +1,8 @@
-Brmdoor control software
+=== Brmdoor control software ===
+
+brmd/ - integration hub that collects data from various sources and provides unified reporting on IRC and web etc.
+
+brmdoor/ - Arduino software
+
+
+Project webpage: http://brmlab.cz/project/brmdoor