Dennis Smith / Mbed 2 deprecated NixieClock800Max

Dependencies:   PCF8583_rtc mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers IRremote.cpp Source File

IRremote.cpp

00001 #include <mbed.h>
00002 #include "IRremote.h"
00003 
00004 int  IR_cnt, IR_state, IR_bit_cnt, IR_temp;
00005 char IR_buf[4] = {0xFF, 0xFF, 0xFF, 0xFF};
00006 
00007 //IR Timer
00008 void IR_check()
00009 {
00010     if(IR_cnt < 150) {
00011         IR_cnt++;
00012     } else
00013         IR_state = 1;
00014 }
00015 
00016 //IR Receive
00017 void IR_start()
00018 {
00019     switch(IR_state) {
00020         case 1:
00021             if((IR_cnt > 80) && (IR_cnt < 140)) {
00022                 IR_state = 2;    // Lead
00023                 IR_bit_cnt = IR_temp = 0;
00024             }
00025             break;
00026         case 2:
00027             if(IR_cnt > 30) {
00028                 IR_state = 1;    // Error
00029                 break;
00030             } else if(IR_cnt >= 15) {
00031                 IR_temp |= 0x80;      // Data 1 : 2.250ms(22)(0.56ms+1.69ms) / 2ms
00032             } else if(IR_cnt >= 8) {
00033                 IR_temp |= 0x00;      // Data 0 : 1.125ms(12)(0.56ms+0.565ms) / 1ms
00034             } else               {
00035                 IR_state = 1;    // Error
00036                 break;
00037             }
00038             
00039             if((++IR_bit_cnt %8) == 0) {
00040                 IR_buf[(IR_bit_cnt / 8) -1] = IR_temp;
00041                 IR_temp = 0;
00042                 if(IR_bit_cnt >= 32) {
00043                     IR_state = 1;
00044                     IR_bit_cnt = 0;
00045                 }
00046             }
00047             IR_temp >>= 1;
00048             break;
00049     }
00050     
00051     IR_cnt = 0;
00052 }
00053 
00054 IRremote::IRremote(PinName pin) : _pin(pin)
00055 {
00056     _pin.mode(PullUp);
00057     _pin.fall(&IR_start);
00058     IR_timer.attach_us(&IR_check, 100.0);
00059 }
00060 
00061 char IRremote::read(int ir_i)
00062 {
00063     return IR_buf[ir_i];
00064 }
00065 
00066 char IRremote::readclear(int ir_i)
00067 {
00068     char IR_rx;
00069     IR_rx = IR_buf[ir_i];
00070     IR_buf[ir_i] = 0xFF;
00071     return IR_rx;
00072 }
00073 
00074 void IRremote::clear()
00075 {
00076     for(int i = 0; i < 4; i++) {
00077         IR_buf[i] = 0xFF;
00078     }
00079 }