コード例 #1
0
ファイル: RCSwitch.cpp プロジェクト: manlogit/rc-switch
void RCSwitch::handleInterrupt() {

    static unsigned int duration;
    static unsigned int changeCount;
    static unsigned long lastTime;
    static unsigned int repeatCount;


    long time = micros();
    duration = time - lastTime;

    if (duration > RCSwitch::nSeparationLimit && diff(duration, RCSwitch::timings[0]) < 200) {
        repeatCount++;
        changeCount--;
        if (repeatCount == 2) {
            if (receiveProtocol(1, changeCount) == false) {
                if (receiveProtocol(2, changeCount) == false) {
                    if (receiveProtocol(3, changeCount) == false) {
                        //failed
                    }
                }
            }
            repeatCount = 0;
        }
        changeCount = 0;
    } else if (duration > RCSwitch::nSeparationLimit) {
        changeCount = 0;
    }

    if (changeCount >= RCSWITCH_MAX_CHANGES) {
        changeCount = 0;
        repeatCount = 0;
    }
    RCSwitch::timings[changeCount++] = duration;
    lastTime = time;
}
コード例 #2
0
ファイル: RCSwitch.cpp プロジェクト: cyberpunk2350/rc-switch
void RECEIVE_ATTR RCSwitch::handleInterrupt() {

  static unsigned int changeCount = 0;
  static unsigned long lastTime = 0;
  static unsigned int repeatCount = 0;

  const long time = micros();
  const unsigned int duration = time - lastTime;

  if (duration > RCSwitch::nSeparationLimit) {
    // A long stretch without signal level change occurred. This could
    // be the gap between two transmission.
    if (diff(duration, RCSwitch::timings[0]) < 200) {
      // This long signal is close in length to the long signal which
      // started the previously recorded timings; this suggests that
      // it may indeed by a a gap between two transmissions (we assume
      // here that a sender will send the signal multiple times,
      // with roughly the same gap between them).
      repeatCount++;
      if (repeatCount == 2) {
        for(unsigned int i = 1; i <= numProto; i++) {
          if (receiveProtocol(i, changeCount)) {
            // receive succeeded for protocol i
            break;
          }
        }
        repeatCount = 0;
      }
    }
    changeCount = 0;
  }
 
  // detect overflow
  if (changeCount >= RCSWITCH_MAX_CHANGES) {
    changeCount = 0;
    repeatCount = 0;
  }

  RCSwitch::timings[changeCount++] = duration;
  lastTime = time;  
}