From ec8defaa998f8c6f5b9cf2cd7624436bf0cd8e73 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Mon, 14 Oct 2013 11:24:51 +0200 Subject: [PATCH] added simple IR receiver burst recording --- src/main.c | 124 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 40 deletions(-) diff --git a/src/main.c b/src/main.c index 549d82f..dd4b4fa 100644 --- a/src/main.c +++ b/src/main.c @@ -10,22 +10,37 @@ #include "uart.h" /* global variables */ -volatile uint8_t pwr_ok; -volatile uint8_t fan; -volatile uint16_t tachometer = 0; -volatile uint8_t timer2_ovf = 0; +volatile uint8_t pwr_ok; /* is power ok */ +volatile uint8_t fan; /* fan signal state, to measure tachometer */ +volatile uint8_t timer2_ovf = 0; /* to measure fan speed using timer 2 */ +static const uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; /* timer 2 CS2[2:0] values */ +volatile uint16_t tachometer = 0; /* the tachometer time (from timer) */ +volatile uint8_t ir; /* IR signal state, to measure IR code */ +volatile uint8_t pulse_i = 1; /* pulse index */ +# define PULSE_MAX 64 /* maximum number of pulses to save */ +volatile uint16_t pulse[PULSE_MAX]; /* pulse times (from timer) */ -const uint16_t TIMER2_PRESCALE[8] = {0,1,8,32,64,128,256,1024}; -/* PWR_OK interrupt */ +/* power ok interrupt */ ISR(PCINT0_vect) { /* PCI0 Interrupt Vector for PCINT[7:0] */ if (pwr_ok!=(PINB&(1<0) { /* save pulse, except the first */ + pulse[pulse_i-1] = TCNT1; + pulse[pulse_i] = 0; + } + if (pulse_i0) { + pulse_i = 0; + OCR0A = ~OCR0A; } } @@ -59,9 +82,21 @@ static void ioinit(void) PCICR |= (1<0) { OCR0A--; } - printf("decreasing LED: %d\n",OCR0A); + printf("decreasing LED: %u\n",OCR0A); break; case '+': if (OCR0A<0xff) { OCR0A++; } - printf("increasing LED: %d\n",OCR0A); + printf("increasing LED: %u\n",OCR0A); break; case 't': if (tachometer) { uint16_t prescale = TIMER2_PRESCALE[TCCR2B&((1<