Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Convert LIRC hex codes to Arduino IR Library Hex Codes

By: dougbtv on Apr 12th, 2012  |  syntax: PHP  |  size: 2.22 KB  |  hits: 795  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. <?php
  2.  
  3. // ---------------------------------------------------------
  4. // -- A script to convert LIRC remote codes into the
  5. // -- format used by the Ken Sheriff Arduino IR Library
  6. // -- http://www.arcfn.com/2010/12/64-bit-rc6-codes-arduino-and-xbox.html
  7. // ------ Usage --------------------------------------------
  8. // -- Run with:
  9. // -- php -q hexconvert.php 0x37FF07bff
  10. // -- or
  11. // -- php -q hexconvert.php 37FF07bff
  12. // --
  13. // -- It's case insensitive (but always returns lowercase)
  14. // ---------------------------------------------------------
  15.  
  16. //print_r($argv);
  17.  
  18. // Is this the input I want? If it is, great, otherwise, end.
  19. if (preg_match("/^[xa-f0-9]+$/i",$argv[1])) {
  20.  
  21.         // Clean up info, accept both 0x format, and hex without 0x.
  22.         $input = $argv[1];
  23.         $input = preg_replace("/^(0x)?(.+)$/","$2",$input);
  24.         $input = strtolower($input);
  25.  
  26.         // echo "input: ".$input."\n";
  27.  
  28. } else {
  29.  
  30.         echo "did not detect a hexidecimal number in your input\n";
  31.         echo "run like: php -q hexconvert.php 0x0b2FF4 etc\n";
  32.         die("\n");
  33.  
  34. }
  35.  
  36.         // Renaming the input, lame.
  37.         $hex = $input;
  38.         // A string of hex digits to reference.
  39.         $hexstr = "0123456789abcdef";
  40.  
  41.         // The variable where we'll store the result.
  42.         $keep = "";
  43.        
  44.         // Cycle through all the hex characters in the string.
  45.         for ($i=0; $i<strlen($hex); $i++) {
  46.                 // Get the hex character in question.
  47.                 $c = substr($hex,$i,1);
  48.                
  49.                 // What's it's decimal value? We get this from the reference string.
  50.                 $pos = strpos($hexstr,$c);
  51.                
  52.                 // We invert it's position (that's the whole point of this script)
  53.                 $inv = 15 - $pos;
  54.                
  55.                 // And then we string that onto our "keeper" string.
  56.                 // echo $c." --> ".$pos." --> ".$inv."\n";
  57.                 $keep .= substr($hexstr,$inv,1);
  58.         }
  59.  
  60.         // And give some output.
  61.         echo "0x".$keep." [Converted to IR Library format]\n";
  62.         echo "0x".$hex." [From your input (from LIRC)]\n";
  63.  
  64.         echo "\n";
  65.  
  66.  
  67.         // Some testing hex values from my MCE remote.
  68.         // x37FF07bff
  69.         /*
  70.                 Blue          0x00007ba1
  71.                 Yellow        0x00007ba2
  72.                 Green         0x00007ba3
  73.                 Red           0x00007ba4
  74.        
  75.         */
  76.         //      $code = 0x37FF07bff; // key ZERO
  77.         //      $code = 0x37FF07bed;
  78.         //      $code = 0x37FF06BFF; // Key 0
  79.         //      $code = 0x37FF08BF3; // Xbox On/Off
  80.  
  81. ?>