int main(void) { SetupHardware(); /* Create a regular character stream for the interface so that it can be used with the stdio.h functions */ CDC_Device_CreateStream(&VirtualSerial_CDC_Interface, &USBSerialStream); GlobalInterruptEnable(); while(1) { DebounceUpdate(); EncoderUpdate(); LedUpdate(); SendSerial(); /* Must throw away unused bytes from the host, or it will lock up while waiting for the device */ CDC_Device_ReceiveByte(&VirtualSerial_CDC_Interface); CDC_Device_USBTask(&VirtualSerial_CDC_Interface); HID_Device_USBTask(&Mouse_HID_Interface); HID_Device_USBTask(&Keyboard_HID_Interface); USB_USBTask(); } }
bool CAction::Alive( uint8_t inSrcNodeID, uint8_t inDstNodeID) { if(inDstNodeID == gConfig.GetVal(eConfigVar_NodeID)) { SendSerial(inSrcNodeID, "CC:%d ALIVE v=%s date=%s %s\n", gConfig.GetVal(eConfigVar_NodeID), gVersionStr, __DATE__, __TIME__); } else { gCANBus.SendMsg(inDstNodeID, eMsgType_Alive, 0, 0, NULL); } return true; }
uint32_t IsConfig_Command(uint8_t *command, uint32_t size) { //Write Setting if (command[0] == 'W') { if (command[1] == 'S') { if (WS_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } else if (command[1] == 'C') { if (WC_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } else if (command[1] == 'O') { if (WO_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } else if (command[1] == 'H') { if (WH_Command(&command[2], size - 2)) SetOK(); else SetERR(); return 1; } } //Read Setting else if (command[0] == 'R') { if (command[1] == 'S') { RS_Command(ReadSetting, 30); return 1; } else if (command[1] == 'C') { RC_Command(ReadSetting, 30); return 1; } else if (command[1] == 'H') { RH_Command(&command[2], size - 2); return 1; } } //System else if (command[0] == 'S') { if (command[1] == 'R') { SetOK(); SendSerial(ReadSetting, 3); _delay_ms(100); NVIC_SystemReset(); } else if (command[1] == 'V') { write_flash(); SetOK(); return 1; } else if (command[1] == 'F') { reset_flash(); SetOK(); return 1; } } //Firmware else if (command[0] == 'F') { if (command[1] == 'U') { SetOK(); option.isISP = true; write_flash(); SendSerial(ReadSetting, 3); _delay_ms(100); NVIC_SystemReset(); //ReinvokeISP(); } else if (command[1] == 'V') { FV_Command(ReadSetting, 30); return 1; } } return 0; }