int main() { PCComms_SetCustomInterruptHandler(&SerialCB); DisableAll(); PCComms_Start(); MotorComms_Start(); Timer_1_Start(); CyGlobalIntEnable; OpenExhaust_Write(1); CloseExhaust_Write(1); for(;;) { CyDelay(10); if(linesz !=0) { if(line[linesz-1]=='\n' || line[linesz-1]=='\r') //Assume that the computer isn't doing anything funky. //Q. What is our computer's favorite dance? //A. The Robot! { parseSerial(line,linesz); line[linesz]='\0'; linesz=0; } } else MotorComms_UartPutString("Boop"); } }
void main(void) { // Initialise system setup(); // used for debugging. TRISBbits.RB4 = 0; PORTBbits.RB4 = 0; // Loop until the system is turned off while (req_state & POWER_ON) { int serial_data; switch (cur_state) { case ST_WEIGH: weigh(); break; case ST_COUNT_I: case ST_COUNT_F: count(); break; case ST_CALIBRATE: calibrate(); break; } serial_data = parseSerial(); if (serial_data != RS232_NO_DATA) { RS232writeByte(COMM_DEBUG); RS232writeByte(cur_state); RS232writeByte(disp_type); //RS232writeByte(serial_data); } if (req_state != ST_NONE) { // int timeout = 0xFFFF; // int serial_return; cur_state = req_state; // Send Change to GUI. if (!st_chng_rs232_flag) { if (cur_state == ST_COUNT_F) { RS232sendData_b_i(COMM_CHANGE_STATE, cur_state, number_items); } else { RS232sendData_b(COMM_CHANGE_STATE, cur_state); } } st_chng_rs232_flag = 0; req_state = ST_NONE; } } powerDown(); // Save state and power down. }
// Called when a byte arrived at UART void serialEvent() { // Read up to 5 bytes at once availableBytes = Serial.available(); if (availableBytes >5) availableBytes = 5; for (availableBytesCnt = 0; availableBytesCnt<availableBytes; ++availableBytesCnt) { inByte = (uint8_t)Serial.read(); lastReceivedByteMillis = currentMillis; // If a recent attempt to read a packet was aborted, // read all remaining bytes until the end of the packet is // reached. The end of the packet and the begining of the // new packet have the value '\0'. if(ignorePacket) { if(inByte == escape) { #ifndef OBLIFY Serial.println("\nReset ignorePacket"); #endif ignorePacket = 0; } else { #ifndef OBLIFY Serial.print("."); #endif return; } } #ifndef OBLIFY if (recPos < 11) { parseSerial(); return; } #endif processSerialEvent(); } }