基于IRremote 红外发送编码

Changes to the IRremote library

As mentioned, this work included some changes to the IRremote library code, as described below. Note that there now are newer versions of the IRremote library, so some of this may not be required.

 

IRremote.cpp 

In this file, I added a new function for sending IR signals with the Panasonic TV protocol, and I also added a similar function for sending with the Samsung DVD protocol.

 

The original IRremote library does not support more than 32 bits, i.e. the send-out data must not exceed 32 bits. The Pansaonic, however, requires 48 bit and the Samsung 42. The solution was to add a second parameter for communicating the “over 32” bits to the library function.

 

So, I added functions sendPanasonic and sendSamsung as shown below. For the Panasonic, I had to add some space(30000); calls because I saw online someone else who had done that. I did not fully research why this is needed, but it works.

 

The IRremote library also includes code for receiving the various protocols, but I did not make such additions for these Panasonic & Samsung protocols.

 

//Added Panasonic --- a more than 32 bit protocol

// First 32 bit in data1

// Remaining bits leftadjusted in data2

void IRsend::sendPanasonic(unsigned long data1, unsigned long data2, int nbits) {

 

enableIROut(38);

mark(PANASONIC_HDR_MARK);

space(PANASONIC_HDR_SPACE);

 

for (int i = 0; i < 32; i++) {

   if (data1 & TOPBIT) {

     mark(PANASONIC_BIT_MARK);

     space(PANASONIC_ONE_SPACE);

   }

   else {

     mark(PANASONIC_BIT_MARK);

     space(PANASONIC_ZERO_SPACE);

   }

   data1 <<= 1;

}

 

nbits = nbits - 32;

for (int i = 0; i < nbits; i++) {

   if (data2 & TOPBIT) {

     mark(PANASONIC_BIT_MARK);

     space(PANASONIC_ONE_SPACE);

   }

   else {

     mark(PANASONIC_BIT_MARK);

     space(PANASONIC_ZERO_SPACE);

   }

   data2 <<= 1;

}

mark(PANASONIC_BIT_MARK);

space(30000);

space(30000);

space(14000);

}

 

// Added Samsung code - a 42 bit protocol

// First 32 bit in data1

// Remaining bits left-adjusted in data2

// Code is exact copy of NEC with extra loop for data2

void IRsend::sendSamsung(unsigned long data1, unsigned long data2, int nbits)

{

enableIROut(38);

mark(NEC_HDR_MARK);

space(NEC_HDR_SPACE);

for (int i = 0; i < 32; i++) {

   if (data1 & TOPBIT) {

     mark(NEC_BIT_MARK);

     space(NEC_ONE_SPACE);

   }

   else {

     mark(NEC_BIT_MARK);

     space(NEC_ZERO_SPACE);

   }

   data1 <<= 1;

}

 

//last bits

nbits = nbits -32;

for (int i = 0; i < nbits; i++) {

   if (data2 & TOPBIT) {

     mark(NEC_BIT_MARK);

     space(NEC_ONE_SPACE);

   }

   else {

     mark(NEC_BIT_MARK);

     space(NEC_ZERO_SPACE);

   }

   data2 <<= 1;

}

mark(NEC_BIT_MARK);

space(0);

}

 

 

IRremote.h

 

The above functions need to be declared in this file as well.

void sendPanasonic(unsigned long data1, unsigned long data2, int nbits);

void sendSamsung(unsigned long data1, unsigned long data2, int nbits);

 


The internal buffer for receiving IR data needs to be longer. Changed 76 to 140:

#define RAWBUF 140 // Length of raw duration buffer

 

 

 

IRremoteInt.h 

The above functions requires the following declarations in this file:

#define PANASONIC_HDR_MARK 3502

#define PANASONIC_HDR_SPACE 1750

#define PANASONIC_BIT_MARK 502

#define PANASONIC_ONE_SPACE 1244

#define PANASONIC_ZERO_SPACE 370

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值