void parseByte (int newByte) // parse an incoming commandbyte from serial interface, perform command if valid { static uint8_t cmdlen=0; if (CimParserActive) parse_CIM_protocol(newByte); // handle AsTeRICS CIM protocol messages ! else { switch (readstate) { case 0: if ((newByte=='A') || (newByte=='a')) readstate++; if (newByte=='@') { readstate++; CimParserActive=1; } // switch to AsTeRICS CIM protocol parser break; case 1: if ((newByte=='T') || (newByte=='t')) readstate++; else readstate=0; break; case 2: if ((newByte=='\r') || (newByte=='\n')) // AT reply: "OK" { Serial.println("OK"); readstate=0; } else if (newByte==' ') { cmdlen=0; readstate++; } else goto err; break; case 3: if ((newByte=='\r') || (newByte=='\n') || (cmdlen>=MAX_CMDLEN-1)) { tmpstring[cmdlen]=0; parseCommand(tmpstring); readstate=0; } else tmpstring[cmdlen++]=newByte; break; default: err: Serial.println("?");readstate=0; } } }
/** Main program entry point. This routine contains the overall program flow, including initial * setup of all components and the main program loop. */ int main(void) { setupHardware(); init_CIM_frame(); LEDs_SetAllLEDs(LEDMASK_USB_NOTREADY); sei(); for (;;) { parse_CIM_protocol(); HID_Device_USBTask(&Keyboard_HID_Interface); parse_CIM_protocol(); HID_Device_USBTask(&Mouse_HID_Interface); parse_CIM_protocol(); HID_Device_USBTask(&Joystick_HID_Interface); parse_CIM_protocol(); USB_USBTask(); } }
int main(void ) { setupHardware(); init_CIM_frame(); old_PIND=PIND; old_PINB=PINB; sei(); // enable global interrupts while (1) { parse_CIM_protocol(); if (send_ADCFrame_now) // this is updated in the timer ISR !! { send_ADCFrame_now=0; autoreply_num++; if (autoreply_num==0) autoreply_num=0x80; CIM_frame.cim_feature=ARDUINO_CIM_FEATURE_ADCREPORT; CIM_frame.serial_number=autoreply_num; CIM_frame.reply_code=CMD_EVENT_REPLY; generate_ADCFrame(); reply_DataFrame(); //DDRB |= (1<<5); PORTB ^= (1<<5); // indicate frame send with led } if (check_PINChange_now) // this is updated in the timer ISR !! { check_PINChange_now=0; // has a selected pin changed ? if ( ((old_PIND ^ PIND) & PIND_Mask) || ((old_PINB ^ PINB) & PINB_Mask)) { old_PIND=PIND; old_PINB=PINB; autoreply_num++; if (autoreply_num==0) autoreply_num=0x80; CIM_frame.cim_feature=ARDUINO_CIM_FEATURE_GET_PINVALUES; CIM_frame.serial_number=autoreply_num; CIM_frame.reply_code=CMD_EVENT_REPLY; generate_PINFrame(); reply_DataFrame(); } } } }
int main(void) { init(); while (1) { parse_CIM_protocol(); switch(set_ir_status) { case 0: // Idle break; case 1: // Sending get_ir_status = 1; // Sending stop_send_ir(); stop_record_ir(); start_send_ir(); set_ir_status = 0; break; case 2: // Recording get_ir_status = 2; // Recording stop_send_ir(); stop_record_ir(); start_record_ir(); set_ir_status = 0; break; default: stop_send_ir(); stop_record_ir(); set_ir_status = 0; break; } } }