IRCode.java
Go to the documentation of this file.
00001 
00002 /*
00003  * Copyright 2012 Phidgets Inc.  All rights reserved.
00004  */
00005 
00006 package com.phidgets;
00012 public final class IRCode
00013 {
00014         private short[] data;
00019         public short[] getData()
00020         {
00021                 return data;
00022         }
00023         private int bitCount;
00027         public int getBitCount()
00028         {
00029                 return bitCount;
00030         }
00031 
00037         public IRCode(String code, int bitCount)
00038         { 
00039                 this.data = HexToData(code);
00040                 this.bitCount = bitCount;
00041         }
00042 
00048         public IRCode(short[] data, int bitCount)
00049         { 
00050                 int length = (bitCount / 8) + ((bitCount % 8 > 0) ? 1 : 0);
00051 
00052                 this.data = new short[length];
00053                 for (int i = 0; i < length; i++)
00054                         this.data[i] = data[i];
00055 
00056                 this.bitCount = bitCount;
00057         }
00058 
00059         private short[] HexToData(String hexString)
00060         {
00061                 if (hexString == null)
00062                         return null;
00063 
00064                 if (hexString.startsWith("0x")){
00065                         hexString = hexString.substring(2);
00066                 }
00067         
00068                 if (hexString.length() % 2 == 1)
00069                         hexString = '0' + hexString; // Up to you whether to pad the first or last byte
00070 
00071                 short[] data = new short[hexString.length() / 2];
00072 
00073                 for (int i = 0; i < data.length; i++){
00074                         data[i] = (short) Integer.parseInt(hexString.substring(i * 2, (i * 2) + 2), 16);
00075                 }
00076 
00077                 return data;
00078         }
00079     private char[] hexlookup = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
00083         public String toString()
00084         {
00085                 String out = "";
00086                 for(int i=0;i<data.length;i++)
00087                 {
00088                         out = out + (hexlookup[data[i] / 16]);
00089                         out = out + (hexlookup[data[i] % 16]);
00090                 }
00091                 return out;
00092         }
00093 }


pedal_monitor
Author(s): Pedro Mendes
autogenerated on Fri Jun 6 2014 18:37:21