Example #1
0
void serial_getline() {
	do {
		if (serial_rxchars())
			gcode_parse_char(c = serial_popchar());

		loopstuff();
	} while (c >= 32);
}
Example #2
0
/** Read one character.
*/
uint8_t serial_popchar(void) {
  uint8_t c = 0;

  if (serial_rxchars())
    c = LPC_UART->RBR;

  return c;
}
Example #3
0
int main (int argc, char** argv)
{
  sim_start(argc, argv);
#else
int main (void)
{
#endif
	init();

	// main loop
	for (;;)
	{
		// if queue is full, no point in reading chars- host will just have to wait
    if (queue_full() == 0) {
      if (serial_rxchars() != 0) {
        uint8_t c = serial_popchar();
        gcode_parse_char(c);
      }

      #ifdef CANNED_CYCLE
        /**
          WARNING!

          This code works on a per-character basis.

          Any data received over serial WILL be randomly distributed through
          the canned gcode, and you'll have a big mess!

          The solution is to either store gcode parser state with each source,
          or only parse a line at a time.

          This will take extra ram, and may be out of scope for the Teacup
          project.

          If ever print-from-SD card is implemented, these changes may become
          necessary.
        */
        static uint32_t canned_gcode_pos = 0;

        gcode_parse_char(pgm_read_byte(&(canned_gcode_P[canned_gcode_pos])));

        canned_gcode_pos++;
        if (pgm_read_byte(&(canned_gcode_P[canned_gcode_pos])) == 0)
          canned_gcode_pos = 0;

      #endif /* CANNED_CYCLE */
		}

		clock();
	}
}
Example #4
0
/// this is where it all starts, and ends
///
/// just run init(), then run an endless loop where we pass characters from the serial RX buffer to gcode_parse_char() and check the clocks
int main (void)
{
	init();

	// main loop
	for (;;)
	{
		// if queue is full, no point in reading chars- host will just have to wait
		if ((serial_rxchars() != 0) && (queue_full() == 0)) {
			uint8_t c = serial_popchar();
			gcode_parse_char(c);
		}

		clock();
		}
}
Example #5
0
// read one character
uint8_t serial_popchar(void) {
  uint8_t c = 0;
  ssize_t count = 0;
  int fd = serial_fd ? serial_fd : gcode_fd;

  sim_assert(serial_initialised, "serial interface not initialised");
  sim_assert(serial_rxchars() > 0, "no chars to read");
  while (fd && !count) {
    count = read(fd, &c, 1);
    if (!gcode_fd || count)
      break;
    // EOF: try to open next file
    open_file();
    fd = serial_fd ? serial_fd : gcode_fd;
  }
  return c;
}
Example #6
0
void main() {
	stdout = &mystdio;
	stderr = &mystdio;
	stdin = &mystdio;

	analog_init();

	serial_init();

	timer_init();

	sei();

	printf_P(PSTR("start\n"));

	for (;;) {
		// read serial
		if (serial_rxchars())
			serial_getline();

		// read SDCARD
		if (state_flags & STATE_READ_SD) {
			if (file.fs == &fatfs) {
				UINT i;
				do {
					if (f_read(&file, &c, 1, &i) == FR_OK) {
						if (i)
							gcode_parse_char(c);
					}
					else
						i = 0;
				} while ((i != 0) && (c >= 32));
			}
		}

		loopstuff();
	};
}
Example #7
0
int app_main (void)
{
  long timer1 = 0;
  eParseResult parse_result;

  buzzer_init();
  buzzer_play(1500, 100); /* low beep */
	buzzer_wait();
  buzzer_play(2500, 200); /* high beep */

  init();

  read_config();

  // grbl init
  plan_init();      
  st_init();    
  
  // main loop
  for (;;)
  {

    // process characters from the serial port
    while (!serial_line_buf.seen_lf && (serial_rxchars() != 0) )
    {
      unsigned char c = serial_popchar();
      
      if (serial_line_buf.len < MAX_LINE)
        serial_line_buf.data [serial_line_buf.len++] = c;

      if ((c==10) || (c==13))
      {
        if (serial_line_buf.len > 1)
          serial_line_buf.seen_lf = 1;
        else
          serial_line_buf.len = 0;
      }      
    }

    // process SD file if no serial command pending
    if (!sd_line_buf.seen_lf && sd_printing)
    {
      if (sd_read_file (&sd_line_buf))
      {
          sd_line_buf.seen_lf = 1;
      } 
      else
      {
        sd_printing = false;
        serial_writestr ("Done printing file\r\n");
      }
    }

    // if queue is full, we wait
    if (!plan_queue_full())
    {
  
      /* At end of each line, put the "GCode" on movebuffer.
       * If there are movement to do, Timer will start and execute code which
       * will take data from movebuffer and generate the required step pulses
       * for stepper motors.
       */
  
      // give priority to user commands
      if (serial_line_buf.seen_lf)
      {
        parse_result = gcode_parse_line (&serial_line_buf);
        serial_line_buf.len = 0;
        serial_line_buf.seen_lf = 0;
      }
      else if (sd_line_buf.seen_lf)
      {
        parse_result = gcode_parse_line (&sd_line_buf);
        sd_line_buf.len = 0;
        sd_line_buf.seen_lf = 0;
      }

    }

    /* Do every 100ms */
    #define DELAY1 100
    if (timer1 < millis())
    {
      timer1 = millis() + DELAY1;

      /* If there are no activity during 30 seconds, power off the machine */
      if (steptimeout > (30 * 1000/DELAY1))
      {
        power_off();
      }
      else
      {
        steptimeout++;
      }
    }

#ifdef USE_BOOT_BUTTON
    // OPTION: enter bootloader on "Boot" button
    check_boot_request();
#endif

  }
}
int serial_getc_fdev(FILE *stream)
{
	for (;serial_rxchars() == 0;);
	return (int) serial_popchar();
}