aboutsummaryrefslogtreecommitdiffstats
path: root/Java/com/phidgets/IRCodeInfo.java
blob: dd2529f09bd1c19c894a9b05c4293521699c7d79 (plain)
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/*
 * Copyright 2012 Phidgets Inc.  All rights reserved.
 */

package com.phidgets;
/**
 * This class represents IR Code Properties needed for transmit.
 *
 * @author Phidget Inc.
 */
public final class IRCodeInfo
{
	/**
	* Unknown encoding.  This is used with {@link #getEncoding getEncoding}
	*/
	public static final int ENCODING_UNKNOWN = 1;
	/**
	* Space encoding.  This is used with {@link #getEncoding getEncoding}
	*/
	public static final int ENCODING_SPACE = 2;
	/**
	* Pulse encoding.  This is used with {@link #getEncoding getEncoding}
	*/
	public static final int ENCODING_PULSE = 3;
	/**
	* BiPhase encoding.  This is used with {@link #getEncoding getEncoding}
	*/
	public static final int ENCODING_BIPHASE = 4;
	/**
	* RC5 encoding.  This is used with {@link #getEncoding getEncoding}
	*/
	public static final int ENCODING_RC5 = 5;
	/**
	* RC6 encoding.  This is used with {@link #getEncoding getEncoding}
	*/
	public static final int ENCODING_RC6 = 6;
	
	/**
	* Unknown length.  This is used with {@link #getLength getLength}
	*/
	public static final int LENGTH_UNKNOWN = 1;
	/**
	* Constant length.  This is used with {@link #getLength getLength}
	*/
	public static final int LENGTH_CONSTANT = 2;
	/**
	* Variable length.  This is used with {@link #getLength getLength}
	*/
	public static final int LENGTH_VARIABLE = 3;
	
	private int encoding=ENCODING_UNKNOWN, length=LENGTH_UNKNOWN, bitCount=0, gap=0, trail=0, minRepeat=1, carrierFrequency=38000, dutyCycle=33;
	private int[] header=null, one=new int[] {0,0}, zero=new int[] {0,0}, repeat=null;
	private IRCode toggleMask=null;
	
	/**
	* Creates a new IR Code Info object.
	* @param bitCount the bit count
	*/
	public IRCodeInfo(int bitCount) throws PhidgetException
	{
		this.bitCount = bitCount;
	}
	
	/**
	* Creates a new IR Code Info object.
	* @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE}, 
	* {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE}, 
	* {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
	* @param bitCount the bit count
	*/
	public IRCodeInfo(int encoding, int bitCount) throws PhidgetException
	{
		this.encoding = encoding;
		this.bitCount = bitCount;
	}
	
	/**
	* Creates a new IR Code Info object.
	* @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE}, 
	* {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE}, 
	* {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
	* @param bitCount the bit count
	* @param header the header (pulse,space)
	* @param zero the zero (pulse, space)
	* @param one the one (pulse, space)
	* @param trail the trailing pulse
	* @param gap the trailing gap
	*/
	public IRCodeInfo(int encoding, int bitCount, int[] header, int[] zero, int[] one, int trail, int gap) throws PhidgetException
	{
		this.encoding = encoding;
		this.bitCount = bitCount;
		
		if(header != null)
		{
			if(header.length != 2)
				throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
			this.header = new int[] { header[0], header[1] };
		}
		
		if(zero==null || zero.length != 2)
			throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
		this.zero = new int[] { zero[0], zero[1] };
		
		if(one==null || one.length != 2)
			throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
		this.one = new int[] { one[0], one[1] };
		
		this.trail = trail;
		this.gap = gap;
	}
	
	/**
	* Creates a new IR Code Info object.
	* @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE}, 
	* {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE}, 
	* {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
	* @param bitCount the bit count
	* @param header the header (pulse,space)
	* @param zero the zero (pulse, space)
	* @param one the one (pulse, space)
	* @param trail the trailing pulse
	* @param gap the trailing gap
	* @param repeat the special repeat code
	*/
	public IRCodeInfo(int encoding, int bitCount, int[] header, int[] zero, int[] one, int trail, int gap, int[] repeat) throws PhidgetException
	{
		this.encoding = encoding;
		this.bitCount = bitCount;
		
		if(header != null)
		{
			if(header.length != 2)
				throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
			this.header = new int[] { header[0], header[1] };
		}
		
		if(zero==null || zero.length != 2)
			throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
		this.zero = new int[] { zero[0], zero[1] };
		
		if(one==null || one.length != 2)
			throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
		this.one = new int[] { one[0], one[1] };
		
		this.trail = trail;
		this.gap = gap;
		
		if(repeat != null)
		{
			this.repeat = new int[repeat.length];
			for(int i=0; i<repeat.length; i++)
				this.repeat[i] = repeat[i];
		}
	}
	
	/**
	* Creates a new IR Code Info object.
	* @param encoding the encoding - one of {@link #ENCODING_SPACE ENCODING_SPACE}, 
	* {@link #ENCODING_PULSE ENCODING_PULSE}, {@link #ENCODING_BIPHASE ENCODING_BIPHASE}, 
	* {@link #ENCODING_RC5 ENCODING_RC5} or {@link #ENCODING_RC6 ENCODING_RC6}
	* @param bitCount the bit count
	* @param header the header (pulse,space)
	* @param zero the zero (pulse, space)
	* @param one the one (pulse, space)
	* @param trail the trailing pulse
	* @param gap the trailing gap
	* @param repeat the special repeat code
	* @param minRepeat the minimum number of times to repeat the code
	* @param toggleMask the bits to toggle when minRepeat is > 1
	* @param length the length style - one of {@link #LENGTH_CONSTANT LENGTH_CONSTANT} or {@link #LENGTH_VARIABLE LENGTH_VARIABLE}
	* @param carrierFrequency the carrier frequency in kHz
	* @param dutyCycle the duty cycle in percent
	*/
	public IRCodeInfo(
		int encoding, 
		int bitCount, 
		int[] header, 
		int[] zero, 
		int[] one, 
		int trail, 
		int gap, 
		int[] repeat, 
		int minRepeat, 
		IRCode toggleMask, 
		int length, 
		int carrierFrequency, 
		int dutyCycle) throws PhidgetException
	{
		this.encoding = encoding;
		this.bitCount = bitCount;
		
		if(header != null)
		{
			if(header.length != 2)
				throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
			this.header = new int[] { header[0], header[1] };
		}
		
		if(zero==null || zero.length != 2)
			throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
		this.zero = new int[] { zero[0], zero[1] };
		
		if(one==null || one.length != 2)
			throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
		this.one = new int[] { one[0], one[1] };
		
		this.trail = trail;
		this.gap = gap;
		
		if(repeat != null)
		{
			this.repeat = new int[repeat.length];
			for(int i=0; i<repeat.length; i++)
				this.repeat[i] = repeat[i];
		}
		
		this.minRepeat = minRepeat;
		
		if(toggleMask != null)
			toggleMask = new IRCode(toggleMask.getData(), toggleMask.getBitCount());
			
		this.length = length;
		this.carrierFrequency = carrierFrequency;
		this.dutyCycle = dutyCycle;
	}
	
	/**
	 * Returns the encoding.
	 * @return encoding
	 */
	public int getEncoding()
	{
		return encoding;
	}
	/**
	 * Returns the length style.
	 * @return length style
	 */
	public int getLength()
	{
		return length;
	}
	/**
	 * Returns the bit count.
	 * @return bit count
	 */
	public int getBitCount()
	{
		return bitCount;
	}
	/**
	 * Returns the gap.
	 * @return gap
	 */
	public int getGap()
	{
		return gap;
	}
	/**
	 * Returns the trail.
	 * @return trail
	 */
	public int getTrail()
	{
		return trail;
	}
	/**
	 * Returns the min repeat.
	 * @return min repeat
	 */
	public int getMinRepeat()
	{
		return minRepeat;
	}
	/**
	 * Returns the carrier frequency.
	 * @return carrier frequency
	 */
	public int getCarrierFrequency()
	{
		return carrierFrequency;
	}
	/**
	 * Returns the duty cycle.
	 * @return duty cycle
	 */
	public int getDutyCycle()
	{
		return dutyCycle;
	}
	/**
	 * Returns the header.
	 * @return header
	 */
	public int[] getHeader()
	{
		return header;
	}
	/**
	 * Returns the zero.
	 * @return zero
	 */
	public int[] getZero()
	{
		return zero;
	}
	/**
	 * Returns the one.
	 * @return one
	 */
	public int[] getOne()
	{
		return one;
	}
	/**
	 * Returns the repeat code.
	 * @return repeat code
	 */
	public int[] getRepeat()
	{
		return repeat;
	}
	/**
	 * Returns the toggle mask.
	 * @return toggle mask
	 */
	public IRCode getToggleMask()
	{
		return toggleMask;
	}
	
	
	public String toString()
	{
		String out = "";
		out = out + "  Encoding: " + encoding + "\n";
		out = out + "  Zero: " + zero[0] + ", " + zero[1] + "\n";
		out = out + "  One: " + one[0] + ", " + one[1] + "\n";
		if (header != null)
		{
			if (header[0] != 0)
				out = out + "  Header: " + header[0] + ", " + header[1] + "\n";
		}
		
		if (trail != 0)
			out = out + "  Trail: " + trail + "\n";
		if (gap != 0)
			out = out + "  Gap: " + gap + "\n";
		if (repeat != null)
		{
			out = out + "  Repeat: ";
			for(int i=0;i<repeat.length;i++)
				out = out + repeat[i] + ", ";
			out = out + "\n";
		}
		return out;
	}
}