libraries / rc-switch-2.52 / examples / ReceiveDemo_Advanced / output.inoon commit Added link to project report (97a3ba0)
   1void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw, unsigned int protocol) {
   2
   3  if (decimal == 0) {
   4    Serial.print("Unknown encoding.");
   5  } else {
   6    char* b = dec2binWzerofill(decimal, length);
   7    Serial.print("Decimal: ");
   8    Serial.print(decimal);
   9    Serial.print(" (");
  10    Serial.print( length );
  11    Serial.print("Bit) Binary: ");
  12    Serial.print( b );
  13    Serial.print(" Tri-State: ");
  14    Serial.print( bin2tristate( b) );
  15    Serial.print(" PulseLength: ");
  16    Serial.print(delay);
  17    Serial.print(" microseconds");
  18    Serial.print(" Protocol: ");
  19    Serial.println(protocol);
  20  }
  21  
  22  Serial.print("Raw data: ");
  23  for (int i=0; i<= length*2; i++) {
  24    Serial.print(raw[i]);
  25    Serial.print(",");
  26  }
  27  Serial.println();
  28  Serial.println();
  29}
  30
  31
  32static char* bin2tristate(char* bin) {
  33  char returnValue[50];
  34  int pos = 0;
  35  int pos2 = 0;
  36  while (bin[pos]!='\0' && bin[pos+1]!='\0') {
  37    if (bin[pos]=='0' && bin[pos+1]=='0') {
  38      returnValue[pos2] = '0';
  39    } else if (bin[pos]=='1' && bin[pos+1]=='1') {
  40      returnValue[pos2] = '1';
  41    } else if (bin[pos]=='0' && bin[pos+1]=='1') {
  42      returnValue[pos2] = 'F';
  43    } else {
  44      return "not applicable";
  45    }
  46    pos = pos+2;
  47    pos2++;
  48  }
  49  returnValue[pos2] = '\0';
  50  return returnValue;
  51}
  52