コード例 #1
0
ファイル: mendel.c プロジェクト: Myndale/ESPrint
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();
	}
}
コード例 #2
0
ファイル: soupcup.c プロジェクト: Nanomid/SoupCup_Firmware
void serial_getline() {
	do {
		if (serial_rxchars())
			gcode_parse_char(c = serial_popchar());

		loopstuff();
	} while (c >= 32);
}
コード例 #3
0
ファイル: testbuild.cpp プロジェクト: JacobChrist/demitasse
int main(int argc, char**argv )
{
  NumericParser f;
  f.Parse("999");
  std::cout << f.AsInt(false) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";
  f.Parse("999.001");
  std::cout << f.AsInt(false) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";
  f.Parse("999.000001");
  std::cout << f.AsInt(false) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";
  f.Parse("1.000001");
  std::cout << f.AsInt(false) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";
  f.Parse("1.0000015");
  std::cout << f.AsInt(false) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";
  f.Parse("1.0000005");
  std::cout << f.AsInt(false) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";
  f.Parse("1.0000004");
  std::cout << f.AsInt(false) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";
  f.Parse("1.0000004");
  std::cout << f.AsInt(true) << " " << f.AsPosition( false ) << " " << f.AsPosition( true ) << "\n";

/*
				if (c >= '0' && c <= '9') {
					if (read_digit.exponent < DECFLOAT_EXP_MAX &&
							((next_target.option_inches == 0 &&
							read_digit.mantissa < DECFLOAT_MANT_MM_MAX) ||
							(next_target.option_inches &&
							read_digit.mantissa < DECFLOAT_MANT_IN_MAX)))
					{
						// this is simply mantissa = (mantissa * 10) + atoi(c) in different clothes
						read_digit.mantissa = (read_digit.mantissa << 3) + (read_digit.mantissa << 1) + (c - '0');
						if (read_digit.exponent)
							read_digit.exponent++;
					}
				}
*/


    //gSerial.Init( "octopusv10block_fixed_sc055 - half size_export.gcode" );
  MotionPlanner::Init();
    gSerial.Init( "test.gcode" );
    int c;
    while( (c = gSerial.GetCharNoBlocking()) != -1 )
    {
        std::cout << (unsigned char)c;
        gcode_parse_char( c );
    }
    return 0;
}
コード例 #4
0
ファイル: mendel.c プロジェクト: sgawad/Teacup_Firmware
/// 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();
		}
}
コード例 #5
0
ファイル: soupcup.c プロジェクト: Nanomid/SoupCup_Firmware
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();
	};
}
コード例 #6
0
eParseResult gcode_parse_line (tLineBuffer *pLine) 
{
  int j;
  eParseResult result = PR_OK;

  for (j=0; j < pLine->len; j++)
  {
    gcode_parse_char (pLine->data [j]);
  }

  // end of line
  //if ((c == 10) || (c == 13))
  {
    if (
    #ifdef	REQUIRE_LINENUMBER
        (next_target.N >= next_target.N_expected) && (next_target.seen_N == 1)
    #else
        1
    #endif
        ) {
          if (
              #ifdef	REQUIRE_CHECKSUM
              ((next_target.checksum_calculated == next_target.checksum_read) && (next_target.seen_checksum == 1))
              #else
              ((next_target.checksum_calculated == next_target.checksum_read) || (next_target.seen_checksum == 0))
              #endif
              )
      {
        if (sd_writing_file)
        {
          if (next_target.seen_M && (next_target.M >= 20) && (next_target.M <= 29))
          {
            if (next_target.seen_M && next_target.M == 29)
            {
              // M29 - stop writing
              sd_writing_file = false;
              sd_close (&file);
              serial_writestr("Done saving file\r\n");
            }
            else
            {
              // else - do not write SD M-codes to file
              serial_writestr("ok\r\n");
            }
          }
          else
          {
            // lines in files must be LF terminated for sd_read_file to work
            if (pLine->data [pLine->len-1] == 13)
            {
              pLine->data [pLine->len-1] = 10;
            }

            if (sd_write_to_file(pLine->data, pLine->len))
            {
              serial_writestr("ok\r\n");
            }
            else
            {
              serial_writestr("error writing to file\r\n");
            }
          }
        }
        else
        {
          // process
          result = process_gcode_command();

          // expect next line number
          if (next_target.seen_N == 1)
          {
            next_target.N_expected = next_target.N + 1;
          }
        }
      }
      else
      {
        serial_writestr("Expected checksum ");
        serwrite_uint8(next_target.checksum_calculated);
        serial_writestr("\r\n");
        request_resend();
      }
    }
    else
    {
      serial_writestr("Expected line number ");
      serwrite_uint32(next_target.N_expected);
      serial_writestr("\r\n");
      request_resend();
    }

    // reset variables
    next_target.seen_X = next_target.seen_Y = next_target.seen_Z = \
    next_target.seen_E = next_target.seen_F = next_target.seen_S = \
    next_target.seen_P = next_target.seen_N = next_target.seen_M = \
    next_target.seen_checksum = next_target.seen_semi_comment = \
    next_target.seen_parens_comment = next_target.checksum_read = \
    next_target.checksum_calculated = 0;
    next_target.chpos = 0;
    last_field = 0;
    read_digit.sign = read_digit.exponent = 0;
    value = 0;

    // dont assume a G1 by default
    next_target.seen_G = 0;
    next_target.G = 0;

    if (next_target.option_relative)
    {
      next_target.target.x = next_target.target.y = next_target.target.z = 0.0;
      next_target.target.e = 0.0;
    }
  }

  return result;
}