This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
IRDevice.pde
104 lines (94 loc) · 2.34 KB
/
IRDevice.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* USB-UIRTJ is a Java wrapper for the USB-UIRT native dll provided by Jon Rhees.
* The project also includes a User Interface to transmit and capture signals from the UIRT device.
* http://sourceforge.net/projects/uirt-j/
*/
import util.*; //java wrapper for USBUIRT
public class IRDevice
{
private Hashtable irCodes;
private int IRInactivityWaitTime = 6;
private int repeatCount = 1;
private IRData irData = new IRData();
public IRDevice(String name)
{
this.irCodes = irData.getDeviceCodes(name);
if (this.irCodes == null)
println("Device not found: " + name);
this.setupUSBUIRT();
}
private void testDeviceAndData()
{
try
{
USBUIRT.open();
USBUIRT.UIRTInfo info = USBUIRT.getUIRTInfo();
println("Testing device: " + info.toString());
USBUIRT.close();
print("Testing codes: ");
for (int i = 0; i < 10; i++)
{
if (this.irCodes.get(Integer.toString(i)) == null)
{
println("Error - Missing required " + Integer.toString(i) + " IRCode");
exit();
}
}
if (this.irCodes.get("+Vol") == null || this.irCodes.get("-Vol") == null)
{
println("Error - Missing required IRCode (Vol)");
exit();
}
println("OK. Sending test IRCode (-Vol)...");
this.transmit("-Vol");
}
catch (Exception e)
{
println(e);
exit();
}
}
public void transmit(String data)
{
Object code = this.irCodes.get(data);
if (code == null)
{
print("IRDevice transmit error: Invalid code for " + data);
}
else
{
try
{
int r = repeatCount;
if (code.toString() == "+Vol" || code.toString() == "-Vol")
r = 3;
USBUIRT.open();
USBUIRT.transmitIR(code.toString(), USBUIRT.PRONTO, r, IRInactivityWaitTime);
USBUIRT.close();
}
catch (Exception e)
{
println(e);
exit();
}
}
}
private void setupUSBUIRT()
{
try
{
USBUIRT.open();
USBUIRT.UIRTConfig config = USBUIRT.getUIRTConfig();
config.setLedRX(true);
config.setLedTX(true);
config.setLegacyRX(true);
USBUIRT.setUIRTConfig(config);
USBUIRT.close();
this.testDeviceAndData();
}
catch (Exception e)
{
println(e);
}
}
}