int main(void) { uint8_t buf[HID_OUT_BUFFER_SIZE-1], RepeatCounter = 0; IRMP_DATA myIRData; int8_t ret; /* first wakeup slot empty? */ uint8_t learn_wakeup = eeprom_restore(buf, (MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS); USB_HID_Init(); LED_Switch_init(); IRMP_Init(); irsnd_init(); FLASH_Unlock(); EE_Init(); Systick_Init(); while (1) { if (!AlarmValue) Wakeup(); wakeup_reset(); /* test if USB is connected to PC and command is received */ if (USB_HID_GetStatus() == USB_HID_CONNECTED && USB_HID_ReceiveData(buf) == RX_READY && buf[0] == STAT_CMD) { switch ((enum access) buf[1]) { case ACC_GET: ret = get_handler(buf); break; case ACC_SET: ret = set_handler(buf); break; case ACC_RESET: ret = reset_handler(buf); break; default: ret = -1; } if (ret == -1) { buf[0] = STAT_FAILURE; ret = 3; } else { buf[0] = STAT_SUCCESS; } /* send configuration data */ USB_HID_SendData(REPORT_ID_CONFIG, buf, ret); toggle_LED(); } /* poll IR-data */ if (irmp_get_data(&myIRData)) { if (learn_wakeup) { /* store received wakeup IRData in first wakeup slot */ eeprom_store((MACRO_DEPTH + 1) * SIZEOF_IR/2 * MACRO_SLOTS, (uint8_t *) &myIRData); learn_wakeup = 0; } if (!(myIRData.flags)) { RepeatCounter = 0; } else { RepeatCounter++; } if (RepeatCounter == 0 || RepeatCounter >= MIN_REPEATS) { toggle_LED(); /* if macros are sent already, while the trigger IR data are still repeated, * the receiving device may crash */ check_macros(&myIRData); check_wakeups(&myIRData); } /* send IR-data */ memcpy(buf, &myIRData, sizeof(myIRData)); USB_HID_SendData(REPORT_ID_IR, buf, sizeof(myIRData)); } } }
int main(void) { uint8_t buf[HID_OUT_BUFFER_SIZE-1]; IRMP_DATA myIRData; int8_t ret; LED_Switch_init(); Systick_Init(); USB_Reset(); USB_HID_Init(); USB_DISC_release(); IRMP_Init(); irsnd_init(); FLASH_Unlock(); EE_Init(); irmp_set_callback_ptr (led_callback); while (1) { if (!AlarmValue) Wakeup(); if (!send_ir_on_delay) send_magic(); wakeup_reset(); /* test if USB is connected to PC, sendtransfer is complete and configuration command is received */ if (USB_HID_GetStatus() == CONFIGURED && PrevXferComplete && USB_HID_ReceiveData(buf) == RX_READY && buf[0] == STAT_CMD) { switch ((enum access) buf[1]) { case ACC_GET: ret = get_handler(buf); break; case ACC_SET: ret = set_handler(buf); break; case ACC_RESET: ret = reset_handler(buf); break; default: ret = -1; } if (ret == -1) { buf[0] = STAT_FAILURE; ret = 3; } else { buf[0] = STAT_SUCCESS; } /* send configuration data */ USB_HID_SendData(REPORT_ID_CONFIG, buf, ret); blink_LED(); if(Reboot) reboot(); } /* poll IR-data */ if (irmp_get_data(&myIRData)) { myIRData.flags = myIRData.flags & IRMP_FLAG_REPETITION; if (!(myIRData.flags)) { store_wakeup(&myIRData); check_macros(&myIRData); check_wakeups(&myIRData); check_resets(&myIRData); check_reboot(&myIRData); } /* send IR-data */ USB_HID_SendData(REPORT_ID_IR, (uint8_t *) &myIRData, sizeof(myIRData)); } } }