 #include "Cosa/Memory.h"
 
 // Enable to allow the IR receiver interrupt handler to collect time periods
-// #define COLLECT_SAMPLES
+#define COLLECT_SAMPLES
 
-class IRreceiver : public InterruptPin {
+class IRreceiver : public InterruptPin, private Link {
 private:
+  static const uint16_t TIMEOUT = 512;
   static const uint16_t PRE_DATA = 0x20df;
   static const uint8_t PRE_DATA_BITS = 16;
   static const uint8_t SAMPLE_MAX = 40;

    m_sample[m_ix] = us;
#endif
    
    m_ix += 1;
    // Push event when all samples have been received
    if (m_ix == m_max) {
      if ((m_code >> PRE_DATA_BITS) == PRE_DATA) 
	Event::push(Event::READ_COMPLETED_TYPE, this, m_code);
      else
	reset();
    }
  }


      out.printf_P(PSTR("%d: %ud\n"), ix, m_sample[ix]);
    }
#endif
  }
};

// IR receiver for an LG is 36 samples and the binary threshold [1000..2000].
IRreceiver receiver(Board::EXT0, 36, 1500);

void setup()
