Ce site contient essentiellement des notes de travail. Le contenu est en constante évolution, et loin d'être achevé. (+ d'infos)
La plupart des documentations informatiques sont orientées Debian / Ubuntu.

Electronique/Hardware/Divers/Télécommandes RF/Intertechno

De Ordinoscope.net
Sauter à la navigation Sauter à la recherche

Introduction

Les télécommandes Intertechno sont du type KAKU, supportées par les librairies

Remote Switch v2

Réception

#include <RemoteReceiver.h>

void setup() {
  Serial.begin (115200);
  RemoteReceiver::init (0, 3, showCode);  // input signal is on pin 2
}

void loop() {
}

void showCode(unsigned long receivedCode, unsigned int period) {
  Serial.print ("Code: ");
  Serial.print (receivedCode);
  Serial.print (", period duration: ");
  Serial.print (period);
  Serial.println ("us.");
}
Code: 118124, period duration: 362us.
Code: 118122, period duration: 361us.
Code: 118124, period duration: 362us.
Code: 118122, period duration: 361us.

Emission

#include <RemoteSwitch.h>

void setup() {
}

void loop() {
  digitalWrite (13, true);
  send_code (118124);
  delay (5000);
  digitalWrite (13, false);
  send_code (118122);
  delay (5000);
}

void send_code (unsigned long receivedCode) {
  unsigned long code;
  unsigned int period = 362;
  code = receivedCode & 0xFFFFF;
  code |= (unsigned long)period << 23;
  code |= 3L << 20;
  RemoteSwitch::sendTelegram (code, 11);  // output signal is on pin 11
}

RCSwitch

Attention: RC-Switch (1.31 beta) n'est pas compatible avec Arduino 1.0 ! Beaucoup de librairies ne sont pas compatibles avec les changements de l'API dans la version 1.0. Utiliser de préférence la version 0023, jusqu'à ce que les librairies aient été adaptées.

Réception

RCSwitch est beaucoup plus nerveux que Remote Switch v2. L'avantage est d'accélérer la réception, mais au prix d'un bouncing très marqué (duplicas).

Exemple

Un exemple de la librairie RCSwitch, modifié pour décoder les codes Intertechno

#include <RCSwitch.h>

RCSwitch mySwitch = RCSwitch();

void setup () {
  Serial.begin (115200);
  Serial.println ("setup");
  mySwitch.enableReceive (0, output);
}

void loop() {

}

/**
 * Decode intertechno
 * Return a 4 char string (family [A-P], group [1-4], device [1-4], state [0-1])
 */
String it_decode (unsigned long decimal) {
  int8_t f = decimal >> 16;
  int8_t gd = decimal >> 8;
  int8_t g = gd & B00001111;
  int8_t d = gd & B11110000;
  int8_t s = decimal;
  char itc[5] = "????";
    
  switch (f) {
    case 0:  itc[0] = 'a'; break;
    case 64: itc[0] = 'b'; break;
    case 16: itc[0] = 'c'; break;
    case 80: itc[0] = 'd'; break;
    case 4:  itc[0] = 'e'; break;
    case 68: itc[0] = 'f'; break;
    case 20: itc[0] = 'g'; break;
    case 84: itc[0] = 'h'; break;
    case 1:  itc[0] = 'i'; break;
    case 65: itc[0] = 'j'; break;
    case 17: itc[0] = 'k'; break;
    case 81: itc[0] = 'l'; break;
    case 5:  itc[0] = 'm'; break;
    case 69: itc[0] = 'n'; break;
    case 21: itc[0] = 'o'; break;
    case 85: itc[0] = 'p'; break;
  }

  switch (g) {
    case 0: itc[1] = '1'; break;
    case 4: itc[1] = '2'; break;
    case 1: itc[1] = '3'; break;
    case 5: itc[1] = '4'; break;
  }

  switch (d) {
    case 0:  itc[2] = '1'; break;
    case 64: itc[2] = '2'; break;
    case 16: itc[2] = '3'; break;
    case 80: itc[2] = '4'; break;
  }

  switch (s) {
    case 21: itc[3] = '1'; break;
    case 20: itc[3] = '0'; break;
  }

  return itc; 
}

void output(unsigned long decimal, unsigned int length, unsigned int delay, unsigned int* raw) {

  if (decimal == 0) {
      //Serial.println("Unknown encoding.");
  } else {
    if (length == 24) {
      Serial.print ("itc: ");
      Serial.println (it_decode (decimal));
    } else {
      char* b = dec2binWzerofill(decimal, length);
      Serial.print (" - Decimal: ");
      Serial.print(decimal);
      Serial.print(" (");
      Serial.print( length );
      Serial.print("Bit) Binary: ");
      Serial.print( b );
      Serial.print(" Tri-State: [");
      Serial.print( bin2tristate( b) );
      Serial.print("] PulseLength: ");
      Serial.print(delay);
      Serial.println(" microseconds");
      
      Serial.print("Raw data: ");
      for (int i=0; i<= length*2; i++) {
        Serial.println(raw[i]);
      }
    }
  }
}

static char* bin2tristate(char* bin) {
  char returnValue[50];
  int pos = 0;
  int pos2 = 0;
  while (bin[pos]!='\0' && bin[pos+1]!='\0') {
    if (bin[pos]=='0' && bin[pos+1]=='0') {
      returnValue[pos2] = '0';
    } else if (bin[pos]=='1' && bin[pos+1]=='1') {
      returnValue[pos2] = '1';
    } else if (bin[pos]=='0' && bin[pos+1]=='1') {
      returnValue[pos2] = 'F';
    } else {
      return "not applicable";
    }
    pos = pos+2;
    pos2++;
  }
  returnValue[pos2] = '\0';
  return returnValue;
}



static char * dec2binWzerofill(unsigned long Dec, unsigned int bitLength){
  static char bin[64]; 
  unsigned int i=0;

  while (Dec > 0) {
    bin[32+i++] = (Dec & 1 > 0) ? '1' : '0';
    Dec = Dec >> 1;
  }

  for (unsigned int j = 0; j< bitLength; j++) {
    if (j >= bitLength - i) {
      bin[j] = bin[ 31 + i - (j - (bitLength - i)) ];
    }else {
      bin[j] = '0';
    }
  }
  bin[bitLength] = '\0';
  
  return bin;
}

Références