Skip to content

Commit

Permalink
Merge pull request #619 from pmatis/fix_issue_330
Browse files Browse the repository at this point in the history
Fixed Audrey and amixer code for issue #330.
  • Loading branch information
hollie authored Sep 26, 2016
2 parents d50b376 + 1c5b95f commit b98828f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 35 deletions.
41 changes: 20 additions & 21 deletions code/common/pa_control.pl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#@ Allows the rooms= speak and play parm to target specific rooms via a weeder relay or X10 controled PA system.
#@ See comment at the end of this file for example .mht entries.

=begin comment
=begin
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
File:
Expand Down Expand Up @@ -52,7 +52,7 @@

# Hooks to flag which rooms to turn on based on "rooms=" parm in speak command
if ($Reload) {
print_log("PA: Hooking into speech events");
print_log("[PA] Hooking into speech events");
&Speak_parms_add_hook( \&pa_parms_stub );
&Speak_pre_add_hook( \&pa_control_stub );
&Play_parms_add_hook( \&pa_parms_stub );
Expand All @@ -61,8 +61,7 @@
if ( said $v_pa_test) {
my $state = $v_pa_test->{state};
$v_pa_test->respond('app=pa Testing PA...');
speak
"nolog=1 rooms=all mode=unmuted volume=80 Hello. This is a PA system test.";
speak "nolog=1 rooms=all mode=unmuted volume=80 Hello. This is a PA system test.";

#speak "nolog=1 rooms=downstairs mode=unmuted volume=100 Hi!";
}
Expand All @@ -72,7 +71,7 @@
my $state = $v_pa_speakers->{state};
$v_pa_speakers->respond("app=pa Turning speakers $state...");
$state = ( $state eq 'on' ) ? ON : OFF;
print_log("PA: Turning speakers $state") if $Debug{pa};
print_log("[PA] Turning speakers $state") if $Debug{pa};
$pactrl->set( 'allspeakers', $state, 'unmuted' );
}

Expand All @@ -94,23 +93,22 @@ sub pa_parms_stub {
my $results = $pactrl->prep_parms($parms);
my %pa_zones = $pactrl->get_pa_zones();

if ( defined $pa_zones{audrey} && $pa_zones{audrey} ne '' ) {
print_log( "PA: audrey zone detected, hooking via web_hook. ("
. $pa_zones{audrey}
if ( defined $pa_zones{all}{audrey} && $pa_zones{all}{audrey} ne '' ) {
print_log( "[PA] audrey zone detected, hooking via web_hook. ("
. $pa_zones{all}{audrey}
. ")" )
if $Debug{pa};
push( @{ $parms->{web_hook} }, \&pa_web_hook );
}

print_log("PA: parms_stub set results: $results") if $Debug{pa} >= 2;
print_log("[PA] parms_stub set results: $results") if $Debug{pa} >= 2;

}
else {
#MH is already speaking, and other PA zones are already active. Delay speech.
#MH is already speaking, and other PA zones are already active. Delay speech.
if ( $main::Debug{voice} ) {
$parms->{clash_retry} = 0 unless $parms->{clash_retry};
&print_log(
"PA SPEECH CLASH($parms->{clash_retry}): Delaying speech call for "
&print_log("[PA] SPEECH CLASH($parms->{clash_retry}): Delaying speech call for "
. $parms->{text}
. "\n" )
unless $parms->{clash_retry} lt 1;
Expand All @@ -124,15 +122,15 @@ sub pa_parms_stub {
$parmstxt .= ', ' if $parmstxt;
$parmstxt .= "$pkey => q($pval)";
}
&print_log("PA SPEECH CLASH Parameters: $parmstxt")
&print_log("[PA] SPEECH CLASH Parameters: $parmstxt")
if $main::Debug{voice} && $parms->{clash_retry} eq 0;
&run_after_delay( $pa_clash_delay, "speak($parmstxt)" );

$parms->{no_speak} = 1; #To stop MH from speaking this time around
return;
}
if ( $parms->{clash_retry} ) {
&print_log("PA SPEECH CLASH: Resolved, continuing speech.");
&print_log("[PA] SPEECH CLASH: Resolved, continuing speech.");
}
}

Expand All @@ -142,10 +140,10 @@ sub pa_control_stub {
my $mode = $parms{pa_mode};
return if $mode eq 'mute' or $mode eq 'offline';

my $rooms = $parms{rooms};
print_log("PA: control_stub: rooms=$rooms, mode=$mode") if $Debug{pa};
print_log("[PA] control_stub: rooms=$parms{pa_zones}, mode=$mode")
if $Debug{pa};
my $results = $pactrl->audio_hook( ON, \%parms );
print_log("PA: control_stub set results: $results") if $Debug{pa} >= 2;
print_log("[PA] control_stub set results: $results") if $Debug{pa} >= 2;
set $pa_speaker_timer $pa_timer if $results;
return $results;
}
Expand All @@ -158,7 +156,7 @@ sub pa_web_hook {
#Turn off speakers when MH says it's done speaking/playing
if ( state_now $mh_speakers eq OFF ) {
unset $pa_speaker_timer;
print_log("PA: Turning speakers off") if $Debug{pa};
print_log("[PA] Turning speakers off") if $Debug{pa};
$pactrl->audio_hook( OFF, 'normal' );
$pactrl->active(0);
}
Expand All @@ -167,7 +165,7 @@ sub pa_web_hook {
$pa_speaker_timer = new Timer;
set $pa_speaker_timer 60 if state_now $mh_speakers eq ON;
if ( expired $pa_speaker_timer) {
print_log("PA: Timer expired. Forcing PA speakers off.") if $Debug{pa};
print_log("[PA] Timer expired. Forcing PA speakers off.") if $Debug{pa};
set $mh_speakers OFF;
}

Expand Down Expand Up @@ -222,9 +220,10 @@ sub pa_web_hook {
used.
Serial: The name of the serial port that you use for communcating to the IO device.
The default is "weeder". Note that this can be changed with an INI parm.
Leave this blank unless the "Type" of the PA control line is wdio, wdio_old or
aviosys. The default is "weeder". Note that this can be changed with an INI parm.
Other: Optional. Sets the type of PA control. Defaults to 'wdio'. Available options are:
Type: Optional. Sets the type of PA control. Defaults to 'wdio'. Available options are:
wdio,wdio_old,X10,xpl,xap,audrey,amixer,object
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Expand Down
29 changes: 15 additions & 14 deletions lib/PAobj.pm
Original file line number Diff line number Diff line change
Expand Up @@ -161,21 +161,21 @@ sub prep_parms {
for my $room (@speakers) {
my $ref = &::get_object_by_name("pa_$room");
my $type = $ref->get_type();
&::print_log("PAobj: speakers_$type: Adding $room")
if $main::Debug{pa} >= 3;
$pa_zone_types{$type}++ unless $pa_zone_types{$type};
push( @{ $speakertype{$type} }, $room );
&::print_log("PAobj: speakers_$type: Adding $room") if $main::Debug{pa} >=3;
# $pa_zone_types{$type}++ unless $pa_zone_types{$type};
push(@{$speakertype{$type}}, $room);
}

foreach my $type (keys(%pa_zone_types)) {
undef $pa_zones{active}{$type};
}

foreach my $type ( keys(%speakertype) ) {
my @thespeakers = @{ $speakertype{$type} };
&::print_log( "PAobj: speakers_$type: "
. ( $#thespeakers + 1 ) . ": "
. join( ',', @thespeakers ) )
if $main::Debug{pa};
$pa_zones{active}{$type} = join( ',', @thespeakers );
if ( $#thespeakers > -1 ) {
$parms->{web_file} = "web_file" if $type eq 'audrey';
foreach my $type (keys(%speakertype)) {
my @thespeakers = @{$speakertype{$type}};
&::print_log("PAobj: speakers_$type: ".($#thespeakers+1).": " . join(',',@thespeakers)) if $main::Debug{pa};
$pa_zones{active}{$type}=join(',',@thespeakers);
if ($#thespeakers > -1) {
$parms->{web_file}="web_file" if $type eq 'audrey';
}
}

Expand Down Expand Up @@ -729,7 +729,8 @@ sub new {
#Headphone:0:L
my ( $mixer, $mixernum, $channel ) = split( ':', $self->{address} );
&main::print_log("$mixer / $mixernum / $channel");
$self->{mixer} = "$mixer,$mixernum";
$self->{mixer} = "$mixer";
$self->{mixer} .= ",$mixernum" if $mixernum;
$self->{mixerchan} = lc $channel if $channel;
}

Expand Down

0 comments on commit b98828f

Please sign in to comment.