Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated USB_UIRT to work with longer codes #546

Merged
merged 1 commit into from
Nov 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions code/common/USB_UIRT_learning.pl
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,8 @@ sub usb_uirt_update_html {
my $device = $current_device;
my $function = $current_function;
my $repeat = state $usb_uirt_function_repeat;
$repeat = 3 unless $repeat =~ /^\d+$/ and $repeat > 0 and $repeat < 16;
$repeat = 3 unless $repeat =~ /^\d+$/ and $repeat > 0;
$repeat = 50 unless $repeat =~ /^\d+$/ and $repeat < 50;
my $frequency = state $usb_uirt_function_frequency;
my ($code1, $code2);
$code1 = $usb_uirt_function_code;
Expand All @@ -311,7 +312,8 @@ sub usb_uirt_update_html {
$current_function = $funcnew if $funcnew;
my $frequency = state $usb_uirt_function_frequency;
my $repeat = state $usb_uirt_function_repeat;
$repeat = 3 unless $repeat =~ /^\d+$/ and $repeat > 0 and $repeat < 16;
$repeat = 3 unless $repeat =~ /^\d+$/ and $repeat > 0;
$repeat = 50 unless $repeat =~ /^\d+$/ and $repeat < 50;
my ($code1, $code2);
$code1 = $usb_uirt_function_code;
if ($code1 =~ /^0000 /) {
Expand All @@ -332,7 +334,8 @@ sub usb_uirt_update_html {
my ($frequency, $repeat, $code1, $code2) = USB_UIRT::get_ir_code($current_device, $current_function);
$frequency = state $usb_uirt_function_frequency;
$repeat = state $usb_uirt_function_repeat;
$repeat = 3 unless $repeat =~ /^\d+$/ and $repeat > 0 and $repeat < 16;
$repeat = 3 unless $repeat =~ /^\d+$/ and $repeat > 0;
$repeat = 50 unless $repeat =~ /^\d+$/ and $repeat < 50;
print_log "Modifying device $device function $function";
USB_UIRT::set_ir_code($device, $function, $frequency, $repeat, $code1, $code2);
}
Expand Down Expand Up @@ -426,4 +429,4 @@ sub dump_codes {
foreach (sort @functions) {
print "$_ = " . USB_UIRT::get_ir_string($current_device, $_) . "\n\n";
}
}
}
17 changes: 12 additions & 5 deletions lib/USB_UIRT.pm
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ To enable this module, add these entries to your .ini file:
usb_uirt_module=USB_UIRT
usb_uirt_port=/dev/ttyUSB1 # optional, defaults to /dev/ttyUSB0, not used on Windows
usb_uirt_tx_timeout=XXX #defaults to 500. Increase if long codes don't send
usb_uirt_rx_timeout=XXX #defaults to 600. Increase if long codes don't arrive
Learning
Expand Down Expand Up @@ -69,6 +71,10 @@ my $learning = 0;
my $dbm_file ="$main::config_parms{data_dir}/usb_uirt_codes.dbm";
my ($db, %DBM, @learned, $device, $function, $frequency, $repeat, @transmit_queue, @learn_queue, @learn_frequencies, $transmit_timeout, $learn_timeout, $receive_timeout);
my ($DrvHandle);
my $tx_timeout = 500;
$tx_timeout = $main::config_parms{usb_uirt_tx_timeout} if (defined $main::config_parms{usb_uirt_tx_timeout});
my $rx_timeout = 600;
$rx_timeout = $main::config_parms{usb_uirt_rx_timeout} if (defined $main::config_parms{usb_uirt_rx_timeout});

use constant UUIRTDRV_CFG_LEDRX => 0x01; # Indicator LED on USB-UIRT blinks when remote signals are received
use constant UUIRTDRV_CFG_LEDTX => 0x02; # Indicator LED on USB-UIRT lights during IR transmission
Expand Down Expand Up @@ -200,7 +206,7 @@ sub receive_code {
my $code = uc unpack 'H*', pack 'C*', @bytes;
return if $code eq $prev;
$prev = $code;
$receive_timeout = &main::get_tickcount + 600;
$receive_timeout = &main::get_tickcount + $rx_timeout;

&main::main::print_log("USB_UIRT Code: $code");
&main::process_serial_data($code);
Expand Down Expand Up @@ -401,6 +407,7 @@ sub get_config {
$UirtConfig & UUIRTDRV_CFG_XLEARN ? 1 : 0,
$UirtConfig & UUIRTDRV_CFG_PREVUIR ? 1 : 0,
);
print "USB-UIRT TX timeout:" . $tx_timeout . " RX timeout:" . $rx_timeout . "\n";
return $UirtConfig;
}

Expand Down Expand Up @@ -515,16 +522,16 @@ sub transmit_raw {
get_response(1);
}
}
$transmit_timeout = &main::get_tickcount + 500;
$transmit_timeout = &main::get_tickcount + $tx_timeout;
return;
}

sub transmit_pronto {
my $pronto = shift;
my $repeat = shift;
$pronto =~ s/[^0-9a-f ]//igs;
print "\nTransmitting repeat $repeat code $pronto via USB-UIRT device...\n";
if ($^O eq 'MSWin32') {
print "\nTransmitting repeat $repeat code $pronto via USB-UIRT device...\n";
my ($reserved0, $reserved1);
my $IRCodeFormat = UUIRTDRV_IRFMT_PRONTO;
if (!UUIRTTransmitIR($DrvHandle, $pronto, $IRCodeFormat, $repeat, 0, 0, $reserved0, $reserved1)) {
Expand All @@ -534,7 +541,7 @@ sub transmit_pronto {
else {
print("...IR Transmission Complete!\n");
}
$transmit_timeout = &main::get_tickcount + 500;
$transmit_timeout = &main::get_tickcount + $tx_timeout;
}
else {
&transmit_raw(&encode_ir_string(&pronto_to_raw($pronto, $repeat)));
Expand All @@ -544,7 +551,7 @@ sub transmit_pronto {

sub transmit_struct {
my @bytes = unpack('C*', pack 'H*', shift);
$transmit_timeout = &main::get_tickcount + 500;
$transmit_timeout = &main::get_tickcount + $tx_timeout;
usb_uirt_send(0x37, $#bytes + 2, @bytes);
get_response(1);
}
Expand Down