int8_t set_handler(uint8_t *buf) { /* number of valid bytes in buf, -1 signifies error */ int8_t ret = 3; uint8_t idx; uint8_t tmp[SIZEOF_IR]; switch ((enum command) buf[2]) { case CMD_EMIT: delay_ms(130); irsnd_send_data((IRMP_DATA *) &buf[3], 1); break; case CMD_ALARM: memcpy(&AlarmValue, &buf[3], sizeof(AlarmValue)); break; case CMD_MACRO: idx = (MACRO_DEPTH + 1) * SIZEOF_IR/2 * buf[3] + SIZEOF_IR/2 * buf[4]; eeprom_store(idx, &buf[5]); /* validate stored value in eeprom */ eeprom_restore(tmp, idx); if (memcmp(&buf[5], tmp, sizeof(tmp))) ret = -1; break; case CMD_WAKE: idx = (MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS + SIZEOF_IR/2 * buf[3]; eeprom_store(idx, &buf[4]); /* validate stored value in eeprom */ eeprom_restore(tmp, idx); if (memcmp(&buf[4], tmp, sizeof(tmp))) ret = -1; break; default: ret = -1; } return ret; }
void NEC(int addr,int cmd) { irmp_data.protocol = IRMP_NEC_PROTOCOL; irmp_data.address = addr; irmp_data.command = cmd; irmp_data.flags = 0; irsnd_send_data (&irmp_data, FALSE); }
void RC5(uint16_t addr,uint16_t cmd, uint8_t repetitions) { irmp_data.protocol = IRMP_RC5_PROTOCOL; irmp_data.address = addr; irmp_data.command = cmd; irmp_data.flags = repetitions; irsnd_send_data (&irmp_data, FALSE); }
void doIRButtons(TouchButton * const aTheTouchedButton, int16_t aValue) { FeedbackToneOK(); if (aTheTouchedButton == TouchButtonsIRSend[0]) { sIRSendData.protocol = IRMP_NEC_PROTOCOL; // use NEC protocol sIRSendData.address = 64260; // set address LG 0XFB04 sIRSendData.command = 0x00FF; // set command to EZ Adjust sIRSendData.flags = 0; // don't repeat frame //irsnd_send_data(&sIRSendData, TRUE); // send frame, wait for completion irsnd_send_data(&sIRSendData, FALSE); // send frame, do not wait for completion } else if (aTheTouchedButton == TouchButtonsIRSend[1]) { sIRSendData.protocol = IRMP_NEC_PROTOCOL; // use NEC protocol sIRSendData.address = 64260; // set address sIRSendData.command = 251; // set command to In Start sIRSendData.flags = 0; irsnd_send_data(&sIRSendData, TRUE); // send frame, wait for completion } else if (aTheTouchedButton == TouchButtonsIRSend[2]) { float tNumber = getNumberFromNumberPad(NUMBERPAD_DEFAULT_X, 0, COLOR_GREEN); if (!isnan(tNumber) && tNumber != IN_STOP_CODE) { sCode = tNumber; } displayIRPage(); assertParamMessage((sCode != IN_STOP_CODE), sCode, ""); if (sCode != IN_STOP_CODE) { sIRSendData.protocol = IRMP_NEC_PROTOCOL; // use NEC protocol sIRSendData.address = 64260; // set address sIRSendData.command = sCode; // set command to sIRSendData.flags = 1; // repeat frame once irsnd_send_data(&sIRSendData, TRUE); // send frame, wait for completion } } else if (aTheTouchedButton == TouchButtonsIRSend[3]) { sIRSendData.protocol = IRMP_NEC_PROTOCOL; // use NEC protocol sIRSendData.address = 64260; // set address sIRSendData.command = sCode; // set command to Volume - sIRSendData.flags = 0x0F; // repeat frame forever irsnd_send_data(&sIRSendData, FALSE); // send frame, do not wait for completion delayMillis(2000); irsnd_stop(); } snprintf(StringBuffer, sizeof StringBuffer, "Cmd=%4d|%3X", sCode, sCode); BlueDisplay1.drawText(BUTTON_WIDTH_3_POS_2, BUTTON_HEIGHT_5_LINE_2 + TEXT_SIZE_22_HEIGHT, StringBuffer, TEXT_SIZE_22, COLOR_PAGE_INFO, COLOR_WHITE); }
void loopIRPage(void) { int tYawValue; int tPitchValue; int tLightValue; int tVelocityValue = sVelocitySliderDisplayValue; if (sSend) { // read Sensors readAccelerometerZeroCompensated(&AccelerometerCompassRawDataBuffer[0]); /* * YAW */ tYawValue = (AccelerometerCompassRawDataBuffer[0] / 20); // if (tYawValue > YAW_SUPPRESSED_RANGE) { tYawValue -= YAW_SUPPRESSED_RANGE; } else if (tYawValue < -YAW_SUPPRESSED_RANGE) { tYawValue += YAW_SUPPRESSED_RANGE; } else { tYawValue = 0; } tYawValue = YAW_ZERO_VALUE - tYawValue; if (tYawValue > YAW_MAX_VALUE - sYawTrimValue) { tYawValue = YAW_MAX_VALUE - sYawTrimValue; } else if (tYawValue < YAW_MIN_VALUE - sYawTrimValue) { tYawValue = YAW_MIN_VALUE - sYawTrimValue; } /* * Pitch */ tPitchValue = (AccelerometerCompassRawDataBuffer[1] / 20) + PITCH_ZERO_VALUE; if (tPitchValue > PITCH_MAX_VALUE) { tPitchValue = PITCH_MAX_VALUE; } else if (tPitchValue < 0) { tPitchValue = 0; } /* * send */ sIRSendData.address = (sVelocitySendValue << 8) | 0x80 | (tYawValue + sYawTrimValue); // set address 8*Velocity + ModelSelect(1) + 7*Yaw // sIRSendData.command = (1 << 15) | (TouchButtonToggleLights.getValue() << 14) | (tPitchValue << 8); // set ModelSelect(1) + Light + 6*Pitch sIRSendData.command = (1 << 15) | (tPitchValue << 8); // set ModelSelect(1) + Light + 6*Pitch sIRSendData.command |= (computeiHelicopterChecksum(sIRSendData.address, sIRSendData.command >> 8) << 4); // + Checksum sIRSendData.flags = 0; // send frame once irsnd_send_data(&sIRSendData, TRUE); // send frame, wait for completion of previous data } else if (irmp_get_data(&sIRReceiveData)) {
void transmit_macro(uint8_t macro) { uint8_t i, idx; uint8_t buf[SIZEOF_IR]; uint8_t zeros[SIZEOF_IR] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; //{0}; /* we start from 1, since we don't want to tx the trigger code of the macro*/ for (i=1; i < MACRO_DEPTH + 1; i++) { idx = (MACRO_DEPTH + 1) * SIZEOF_IR/2 * macro + SIZEOF_IR/2 * i; eeprom_restore(buf, idx); /* first encounter of zero in macro means end of macro */ if (!memcmp(buf, &zeros, sizeof(zeros))) break; /* Depending on the protocol we need a pause between the trigger and the transmission * and between two transmissions. The highest known pause is 130 ms for Denon. */ delay_ms(130); irsnd_send_data((IRMP_DATA *) buf, 1); } }
void transmit_macro(uint8_t macro) { uint8_t i, idx; uint8_t buf[SIZEOF_IR]; uint8_t zeros[SIZEOF_IR] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; /* we start from 1, since we don't want to tx the trigger code of the macro*/ for (i=1; i < MACRO_DEPTH + 1; i++) { idx = (MACRO_DEPTH + 1) * SIZEOF_IR/2 * macro + SIZEOF_IR/2 * i; eeprom_restore(buf, idx); /* first encounter of zero in macro means end of macro */ if (!memcmp(buf, &zeros, sizeof(zeros))) break; /* if macros are sent already, while the trigger IR data are still repeated, * the receiving device may crash * Depending on the protocol we need a pause between the trigger and the transmission * and between two transmissions. The highest known pause is 130 ms for Denon. */ yellow_short_on(); irsnd_send_data((IRMP_DATA *) buf, 1); } }
static void led3_thread_entry(void* parameter) { rt_kprintf ( "\r\n led3_thread_entry!!\r\n"); irmp_init(); // initialize irmp irsnd_init(); timer2_init(); // initialize timer2 rt_kprintf ( "\r\n 红外收发系统初始化完成!\r\n"); for (;;) { char *str; // rt_kprintf ( "IRMP is going!!!\r\n"); rt_thread_delay(1); if(RT_EOK== (rt_mb_recv(&dfs_mb,(rt_uint32_t*)&str,RT_WAITING_NO))) {rt_kprintf("接收到控制邮件,数据为 %s",str); // TIM_Cmd(TIM2, ENABLE); if(strcmp(str,"getremote")==0) hot_remote_state=1; if(strcmp(str,"sendremote")==0) hot_remote_send=1; } if (irmp_get_data (&irmp_data)) { rt_kprintf("接收红外信号编码方式: %s",irmp_protocol_names[irmp_data.protocol]); rt_kprintf(" 编码地址: 0x%2X",irmp_data.address); rt_kprintf(" 命令: 0x%2X",irmp_data.command); rt_kprintf(" 标志位: 0x%2X\r\n",irmp_data.flags ); if(1==hot_remote_state) { hot_remote_state=2; irmp_data1=irmp_data; rt_mb_send(&mb,(rt_uint32_t)get_remot1_mp3);//发送邮件 rt_kprintf("红外接收完成第一次\n" ); } else if(2==hot_remote_state) { if(irmp_data1.command==irmp_data.command) { rt_kprintf("红外接收完成第二次,验证通过\n" ); rt_mb_send(&mb,(rt_uint32_t)get_remot2_mp3);//发送邮件 hot_remote_state=0; // TIM_Cmd(TIM2, DISABLE); } else { rt_kprintf("红外接收完成第二次,验证不通过,再次接收红外数据\n" ); rt_mb_send(&mb,(rt_uint32_t)check_fail_mp3);//发送邮件 hot_remote_state=1; } } } if(hot_remote_send) { hot_remote_send=0; // TIM_Cmd(TIM2, ENABLE); /* irmp_data.protocol = IRMP_SAMSUNG32_PROTOCOL; // use NEC protocol irmp_data.address = 0x0e0e; // set address to 0x00FF irmp_data.command = 0xf30c; // set command to 0x0001 irmp_data.flags = 0; // don't repeat frame*/ irsnd_send_data (&irmp_data, TRUE); // send frame, wait for completion // don't repeat frame rt_mb_send(&mb,(rt_uint32_t)sen_remot_mp3); rt_kprintf("发送红外数据完成\n"); rt_kprintf("发射红外信号编码方式: %s",irmp_protocol_names[irmp_data.protocol]); rt_kprintf(" 编码地址: 0x%2X",irmp_data.address); rt_kprintf(" 命令: 0x%2X",irmp_data.command); rt_kprintf(" 标志位: 0x%2X\r\n",irmp_data.flags ); // TIM_Cmd(TIM2, DISABLE); } } }