00001
00002
00003
00004
00005
00006 package com.phidgets;
00012 public final class IRCodeInfo
00013 {
00017 public static final int ENCODING_UNKNOWN = 1;
00021 public static final int ENCODING_SPACE = 2;
00025 public static final int ENCODING_PULSE = 3;
00029 public static final int ENCODING_BIPHASE = 4;
00033 public static final int ENCODING_RC5 = 5;
00037 public static final int ENCODING_RC6 = 6;
00038
00042 public static final int LENGTH_UNKNOWN = 1;
00046 public static final int LENGTH_CONSTANT = 2;
00050 public static final int LENGTH_VARIABLE = 3;
00051
00052 private int encoding=ENCODING_UNKNOWN, length=LENGTH_UNKNOWN, bitCount=0, gap=0, trail=0, minRepeat=1, carrierFrequency=38000, dutyCycle=33;
00053 private int[] header=null, one=new int[] {0,0}, zero=new int[] {0,0}, repeat=null;
00054 private IRCode toggleMask=null;
00055
00060 public IRCodeInfo(int bitCount) throws PhidgetException
00061 {
00062 this.bitCount = bitCount;
00063 }
00064
00072 public IRCodeInfo(int encoding, int bitCount) throws PhidgetException
00073 {
00074 this.encoding = encoding;
00075 this.bitCount = bitCount;
00076 }
00077
00090 public IRCodeInfo(int encoding, int bitCount, int[] header, int[] zero, int[] one, int trail, int gap) throws PhidgetException
00091 {
00092 this.encoding = encoding;
00093 this.bitCount = bitCount;
00094
00095 if(header != null)
00096 {
00097 if(header.length != 2)
00098 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
00099 this.header = new int[] { header[0], header[1] };
00100 }
00101
00102 if(zero==null || zero.length != 2)
00103 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
00104 this.zero = new int[] { zero[0], zero[1] };
00105
00106 if(one==null || one.length != 2)
00107 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
00108 this.one = new int[] { one[0], one[1] };
00109
00110 this.trail = trail;
00111 this.gap = gap;
00112 }
00113
00127 public IRCodeInfo(int encoding, int bitCount, int[] header, int[] zero, int[] one, int trail, int gap, int[] repeat) throws PhidgetException
00128 {
00129 this.encoding = encoding;
00130 this.bitCount = bitCount;
00131
00132 if(header != null)
00133 {
00134 if(header.length != 2)
00135 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
00136 this.header = new int[] { header[0], header[1] };
00137 }
00138
00139 if(zero==null || zero.length != 2)
00140 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
00141 this.zero = new int[] { zero[0], zero[1] };
00142
00143 if(one==null || one.length != 2)
00144 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
00145 this.one = new int[] { one[0], one[1] };
00146
00147 this.trail = trail;
00148 this.gap = gap;
00149
00150 if(repeat != null)
00151 {
00152 this.repeat = new int[repeat.length];
00153 for(int i=0; i<repeat.length; i++)
00154 this.repeat[i] = repeat[i];
00155 }
00156 }
00157
00176 public IRCodeInfo(
00177 int encoding,
00178 int bitCount,
00179 int[] header,
00180 int[] zero,
00181 int[] one,
00182 int trail,
00183 int gap,
00184 int[] repeat,
00185 int minRepeat,
00186 IRCode toggleMask,
00187 int length,
00188 int carrierFrequency,
00189 int dutyCycle) throws PhidgetException
00190 {
00191 this.encoding = encoding;
00192 this.bitCount = bitCount;
00193
00194 if(header != null)
00195 {
00196 if(header.length != 2)
00197 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "header must have 2 elements");
00198 this.header = new int[] { header[0], header[1] };
00199 }
00200
00201 if(zero==null || zero.length != 2)
00202 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "zero must have 2 elements");
00203 this.zero = new int[] { zero[0], zero[1] };
00204
00205 if(one==null || one.length != 2)
00206 throw new PhidgetException(PhidgetException.EPHIDGET_INVALIDARG, "one must have 2 elements");
00207 this.one = new int[] { one[0], one[1] };
00208
00209 this.trail = trail;
00210 this.gap = gap;
00211
00212 if(repeat != null)
00213 {
00214 this.repeat = new int[repeat.length];
00215 for(int i=0; i<repeat.length; i++)
00216 this.repeat[i] = repeat[i];
00217 }
00218
00219 this.minRepeat = minRepeat;
00220
00221 if(toggleMask != null)
00222 toggleMask = new IRCode(toggleMask.getData(), toggleMask.getBitCount());
00223
00224 this.length = length;
00225 this.carrierFrequency = carrierFrequency;
00226 this.dutyCycle = dutyCycle;
00227 }
00228
00233 public int getEncoding()
00234 {
00235 return encoding;
00236 }
00241 public int getLength()
00242 {
00243 return length;
00244 }
00249 public int getBitCount()
00250 {
00251 return bitCount;
00252 }
00257 public int getGap()
00258 {
00259 return gap;
00260 }
00265 public int getTrail()
00266 {
00267 return trail;
00268 }
00273 public int getMinRepeat()
00274 {
00275 return minRepeat;
00276 }
00281 public int getCarrierFrequency()
00282 {
00283 return carrierFrequency;
00284 }
00289 public int getDutyCycle()
00290 {
00291 return dutyCycle;
00292 }
00297 public int[] getHeader()
00298 {
00299 return header;
00300 }
00305 public int[] getZero()
00306 {
00307 return zero;
00308 }
00313 public int[] getOne()
00314 {
00315 return one;
00316 }
00321 public int[] getRepeat()
00322 {
00323 return repeat;
00324 }
00329 public IRCode getToggleMask()
00330 {
00331 return toggleMask;
00332 }
00333
00334
00335 public String toString()
00336 {
00337 String out = "";
00338 out = out + " Encoding: " + encoding + "\n";
00339 out = out + " Zero: " + zero[0] + ", " + zero[1] + "\n";
00340 out = out + " One: " + one[0] + ", " + one[1] + "\n";
00341 if (header != null)
00342 {
00343 if (header[0] != 0)
00344 out = out + " Header: " + header[0] + ", " + header[1] + "\n";
00345 }
00346
00347 if (trail != 0)
00348 out = out + " Trail: " + trail + "\n";
00349 if (gap != 0)
00350 out = out + " Gap: " + gap + "\n";
00351 if (repeat != null)
00352 {
00353 out = out + " Repeat: ";
00354 for(int i=0;i<repeat.length;i++)
00355 out = out + repeat[i] + ", ";
00356 out = out + "\n";
00357 }
00358 return out;
00359 }
00360 }