void ir_init(void) { __disable_interrupt(); IR_SEL &= ~IR_PIN; IR_DIR &= ~IR_PIN; timer_a1_init(); __enable_interrupt(); sys_messagebus_register(&ir_isr, SYS_MSG_TIMER1_CCR0); ir_resume(); }
// Decodes the received IR message // Returns 0 if no data ready, 1 if data ready. // Results of decoding are stored in results uint8_t ir_decode(decode_results * results) { results->rawbuf = irparams.rawbuf; results->rawlen = irparams.rawlen; if (irparams.rcvstate != STATE_STOP) { return ERR; } if (decode_rc5(results)) { return DECODED; } // decodeHash returns a hash on any input. // Thus, it needs to be last in the list. // If you add any decodes, add them before this. //if (decode_hash(results)) { // return DECODED; //} // Throw away and start over ir_resume(); return ERR; }
void main(void) { unsigned short pwkey = 0; TRISAbits.RA0 = 0; ir_enableIRIn(); ir_blink13(0); while(1) { if (ir_decode(&dec_results)) { if (dec_results.decode_type == NEC) { switch(dec_results.value) { case TERRATEC_1_KEY: pwkey = pwkey << 4; pwkey |= 1; break; case TERRATEC_2_KEY: pwkey = pwkey << 4; pwkey |= 2; break; case TERRATEC_3_KEY: pwkey = pwkey << 4; pwkey |= 3; break; case TERRATEC_4_KEY: pwkey = pwkey << 4; pwkey |= 4; break; case TERRATEC_5_KEY: pwkey = pwkey << 4; pwkey |= 5; break; case TERRATEC_6_KEY: pwkey = pwkey << 4; pwkey |= 6; break; case TERRATEC_7_KEY: pwkey = pwkey << 4; pwkey |= 7; break; case TERRATEC_8_KEY: pwkey = pwkey << 4; pwkey |= 8; break; case TERRATEC_9_KEY: pwkey = pwkey << 4; pwkey |= 9; break; case TERRATEC_0_KEY: pwkey = pwkey << 4; pwkey |= 0; break; case REPEAT: break; case TERRATEC_OK_KEY: ir_sendNEC(APPLE_PLAY_KEY,32); break; case TERRATEC_UP_KEY: ir_sendNEC(APPLE_UP_KEY,32); break; case TERRATEC_DOWN_KEY: ir_sendNEC(APPLE_DOWN_KEY,32); break; case TERRATEC_LEFT_KEY: ir_sendNEC(APPLE_LEFT_KEY,32); break; case TERRATEC_RIGHT_KEY: ir_sendNEC(APPLE_RIGHT_KEY,32); break; case TERRATEC_INFO_KEY: ir_sendNEC(APPLE_MENU_KEY,32); break; default: LATAbits.LATA0 = 0; pwkey = pwkey << 4; break; } if (pwkey == 0x7412) { LATAbits.LATA0 = 1; } else { LATAbits.LATA0 = 0; } } //do something here ir_resume(); // Receive the next value } } }