void loop() { uint8_t c; uint16_t newKeys; //read in characters if we got them. if (Serial.available() > 0) { c = (uint8_t)Serial.read(); no_data = 0; command_word[serial_count++] = c; } else { no_data++; delayMicroseconds(100); } //if theres a pause or we got a real command, do it if (serial_count && (c == '\n' || no_data > 100)) { command_word[serial_count] = 0; //change \n to null terminator process_string(command_word); //do init_process_string(); //clear } /* //keypad actions newKeys = keypad_scan(); if (newKeys != oldKeys) { Serial.println(newKeys,HEX); oldKeys = newKeys; switch(newKeys) { case _BV(1): case _BV(2): case _BV(3): case _BV(4): case _BV(5): case _BV(6): case _BV(7): case _BV(8): case _BV(9): case _BV(10): case _BV(11): case _BV(12): case _BV(13): case _BV(14): case _BV(15): default: break; } } */ //no data? turn off steppers if (no_data > 1000) { disable_steppers(); } }
void setup() { //serial Serial.begin(9600); //my init code // keypad_init(); myStepper_init(); motor_init(); _feedrate = getMaxFeedrate(); //reprap init code init_steppers(); init_process_string(); //increase clock resolution TCCR0B &= ~_BV(CS00); //for ATmega168!! XXX: this will mess up millis,micros,delay,delayMicroseconds Serial.println("start"); }
void setupGcodeProcessor() { gc.LastLineNrRecieved = -1; init_process_string(); }
// Get a command and process it void get_and_do_command() { c = ' '; while(talkToHost.gotData() && c != '\n') { c = talkToHost.get(); sharedMachineModel.blink(); if(c == '\r') c = '\n'; // Throw away control chars except \n if(c >= ' ' || c == '\n') { //newlines are ends of commands. if (c != '\n') { // Start of comment - ignore any bytes received from now on if (c == ';' || c=='(') comment = true; if(!comment) { if(c == '\"') { stringArg=!stringArg; strArgBuffer[strArgCount]=0x0; } else if(stringArg) { if(strArgCount<STRING_BUFFER_SIZE) strArgBuffer[strArgCount++] = c; } else // If we're not in comment mode (and string mode), add it to our array. cmdbuffer[serial_count++] = toupper(c); } } } // Buffer overflow? if(serial_count >= COMMAND_SIZE) init_process_string(); } //if we've got a real command, do it if ((comment || serial_count) && c == '\n') { if(serial_count>0) { // Terminate string cmdbuffer[serial_count] = 0; if(SendDebug & DEBUG_ECHO) sprintf(talkToHost.string(), "Echo: %s", cmdbuffer); //process our command! process_string(cmdbuffer, serial_count); } //clear command. init_process_string(); // Say we're ready for the next one talkToHost.sendMessage(SendDebug & DEBUG_INFO); } }