int main(void)                                // main function
{
  sd_mount(DO, CLK, DI, CS);                  // Mount SD card

  FILE* fp = fopen("test.txt", "w");          // Open a file for writing
  
  // Store values as text in test.txt.
  for(int i = -5; i < 15; i++)                // Repeat 20x (-5...14)
  {
    memset(s, ' ', 30);                       // 30 spaces into string
    s[30] = '\r';                             // Newline for Windows Notepad
    s[31] = '\n';                             
    val = i * 10;                             // Emulate sensor reading
    sprint(s, "i = %d , val = %d ", i, val);  // Data to s array as characters
    fwrite(s, 1, 32, fp);                     // Write line to file
  }  
  
  fclose(fp);                                 // Close file
  
  // Retrieve values from file and store in 
  // variables for program use.
  fp = fopen("test.txt", "r");                // Reopen file for reading

  int idx;
  for(int i = -5; i < 15; i++)                // go back through
  {
    memset(s, '\0', 32);                      // All characters to zero
    fread(s, 1, 32, fp);                      // Read the string
    sscan(s, "i = %d , val = %d ", &idx, &val);  // String values -> variables
    print("idx = %d, val = %d \n", idx, val);    // Print variables
  }  

  fclose(fp);                                 // Close the file
}
Ejemplo n.º 2
0
int composite_archinitialize(void)
{
    /* If examples/composite is built as an NSH command, then SD slot should
     * already have been initized in nsh_archinitialize() (see up_nsh.c).  In
     * this case, there is nothing further to be done here.
     *
     * NOTE: CONFIG_NSH_BUILTIN_APPS is not a fool-proof indication that NSH
     * was built.
     */

#ifndef CONFIG_NSH_BUILTIN_APPS
    return sd_mount(CONFIG_EXAMPLES_COMPOSITE_DEVMINOR1);
#else
    return OK;
#endif /* CONFIG_NSH_BUILTIN_APPS */
}
int main()                                        // main function
{
  int DO = 22, CLK = 23, DI = 24, CS = 25;        // SD I/O pins
  sd_mount(DO, CLK, DI, CS);                      // Mount SD card
 
  const char techloop[] = {"techloop.wav"};       // Set up techloop string
  wav_play(techloop);                             // Pass to wav player
 
  wav_volume(6);                                  // Adjust volume
  pause(3500);                                    // Play for 3.5 s
  wav_volume(4);                                  // Repeat twice more
  pause(2000);
  wav_volume(8);
  pause(3500);

  wav_stop();                                      // Stop playing
}
Ejemplo n.º 4
0
int main()                                   // Main function
{
    int DO = 22, CLK = 23;                     // SD I/O pins
    int DI = 24, CS = 25;
    sd_mount(DO, CLK, DI, CS);                 // Mount SD file system
    fp = fopen("navset.txt", "r");             // Open navset.txt

    fread(str, 1, 512, fp);                    // navset.txt -> str
    int strLength = strlen(str);               // Count chars in str
    int i = 0;                                 // Declare index variable

    drive_speed(0, 0);                         // Speed starts at 0

    while(1)                                   // Loop through commands
    {
        // Parse command
        while(!isalpha(str[i])) i++;             // Find 1st command char
        sscan(&str[i], "%s", cmdbuf);            // Command -> buffer
        i += strlen(cmdbuf);                     // Idx up by command char count
        if(!strcmp(cmdbuf, "end")) break;        // If command is end, break

        // Parse distance argument
        while(!isdigit(str[i])) i++;             // Find 1st digit after command
        sscan(&str[i], "%s", valbuf);            // Value -> buffer
        i += strlen(valbuf);                     // Idx up by value char count
        val = atoi(valbuf);                      // Convert string to value

        // Execute command
        if(strcmp(cmdbuf, "forward") == 0)       // If forward
            drive_goto(val, val);                  // ...go forward by val
        else if(strcmp(cmdbuf, "backward") == 0) // If backward
            drive_goto(-val, -val);                // ... go backward by val
        else if(strcmp(cmdbuf, "left") == 0)     // If left
            drive_goto(-val, val);                 // ...go left by val
        else if(strcmp(cmdbuf, "right") == 0)    // If right
            drive_goto(val, -val);                 // ... go right by val
    }

    fclose(fp);                                // Close SD file
}
int main()                                    // main function
{
  int DO = 22,CLK = 23, DI = 24, CS = 25;
  sd_mount(DO,CLK,DI,CS);
  wav_volume(10);
  freqout(4, 2000, 3000);                     // Speaker tone: P4, 2 s, 3 kHz
  while(1)                                    // Endless loop
  {
    int wL = input(7);                        // Left whisker -> wL variable
    int wR = input(8);                        // Right whisker -> wR variable
    //print("%c", HOME);                        // Terminal cursor home (top-left)
    //print("wL = %d  wR = %d", wL, wR);        // Display whisker variables
    drive_speed(128,128);
    if(input(7)==0 || input(8) == 0)
    {
    drive_speed(0,0);
    pause(500);
    wav_play("ouch.wav");
    drive_goto(-64,64);
    }
  }
}
int main()
{
  
  sd_mount(DO, CLK, DI, CS);                  // Mount SD card

  FILE* fp = fopen("test.txt", "w");          // Open a file for writing
  fwrite("Testing 123...\n", 1, 15, fp);      // Add contents to the file
  fclose(fp);                                 // Close the file
 
  char s[15];                                 // Buffer for characters
  fp = fopen("test.txt", "r");                // Reopen file for reading
  fread(s, 1, 15, fp);                        // Read 15 characters
  fclose(fp);                                 // Close the file

  print("First 15 chars in test.txt:\n");     // Display heading
  pause(500);
  for (int i = 0; i<15; i++)
  {
      print("%x\n", s[i]);                             // Display characters
      pause(500); 
  }  
  print("\n\n");       
  
  
  
  //hyperterminal();
  
  
  while(1)
  {
      
     
  }


  return 0;
}
Ejemplo n.º 7
0
void menu_process(void)
{
	int k;

	// Z80-Bus request
//	MZ_Brequest();
	do {
		k=menu(0,0,0);	// Root menu
		switch(k){
			case 0:
				if(view_inventory()==999) continue;
				break;
			case 3:
				direct_load();
				break;
			case 7:
				sd_mount();
				tname[0]='\0'; dname[0][0]='\0'; dname[1][0]='\0';
				break;
			case 10:
				if(tname[0]!='\0'){	// if tape file is not empty
					tape_unmount();
				}
				tape_mount();
				break;
			case 11:
			case 12:
				fd_mount(k);
				break;
			case 20:
				tape_unmount();
				break;
			case 21:
			case 22:
				fd_unmount(k);
				break;
			case 40:
			case 41:
			case 42:
			case 43:
			case 44:
			case 45:
			case 46:
			case 47:
			case 48:
				set_rom(k);
				if(view_inventory()==999) continue;
				fname[0]='\0';
				break;
			case 50:
			case 51:
			case 52:
			case 53:
			case 54:
			case 55:
			case 56:
			case 57:
			case 58:
				clear_rom(k);
				if(view_inventory()==999) continue;
				break;
			case 60:
			case 61:
			default:
				break;
		}
		break;
	}while(1);
	keybuf_clear();

	// Z80-Bus release
//	MZ_Brelease();
}
Ejemplo n.º 8
0
void System_Initialize(void)
{
	char SecName[8],buffer[512],data[4096];
	unsigned char *cgrom,*keymap;
	int k;
	UINT i,r;
	ROMS_t *romdata=(ROMS_t *)(CFI_BASE+0x100000);

	// Interrupt regist
	int_regist();

	sd_mount();
	tname[0]='\0'; dname[0][0]='\0'; dname[1][0]='\0';

	// Clear VRAM
	for(i=0;i<1000;i++)
		IOWR_8DIRECT(REG_BASE, MZ_VRAM+i, 0);
	// Clear GRAM
	for(i=0;i<65536;i++)
		MZ80B_GRAM(i)=0;
	cgrom=romdata->char80b;
	keymap=romdata->key80b;
	// CG ROM
	for(i=0;i<2048;i++){	// (0xc800-0xcfff)
		IOWR_8DIRECT(REG_BASE, MZ_CGROM+i, cgrom[i]);
	}
	// Key Map Data
	for(i=0;i<256;i++){	// (0xc000-0xc0ff)
		IOWR_8DIRECT(REG_BASE, MZ_KMAP+i, keymap[i]);
	}

	if(IORD_8DIRECT(REG_BASE, MZ_SYS_SW70)&0x20){
		// Select Section Name by MZ mode
		if((IORD_8DIRECT(REG_BASE, MZ_SYS_SW98)&0x2))
			strcpy(SecName, "MZ-2000");
		else
			strcpy(SecName, "MZ-80B");

		// CG ROM
		GetPrivateProfileString(SecName, "CGROM", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")==0)
			GetPrivateProfileString("COMMON", "CGROM", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")!=0){
			file_bulk_read(buffer, data, 2048);
			for(i=0;i<2048;i++){	// (0xc800-0xcfff)
				IOWR_8DIRECT(REG_BASE, MZ_CGROM+i, data[i]);
			}
		}
		// Key Map Data
		GetPrivateProfileString(SecName, "KEYMAP", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")==0)
			GetPrivateProfileString("COMMON", "KEYMAP", "NULL", buffer, "system.ini");
		if(strcmp(buffer,"NULL")!=0){
			file_bulk_read(buffer, data, 256);
			for(i=0;i<256;i++){	// (0xc000-0xc0ff)
				IOWR_8DIRECT(REG_BASE, MZ_KMAP+i, data[i]);
			}
		}
	}

}
Ejemplo n.º 9
0
void process_gcode_command() {
	uint32_t	backup_f;

	// convert relative to absolute
	if (next_target.option_all_relative) {
    next_target.target.axis[X] += startpoint.axis[X];
    next_target.target.axis[Y] += startpoint.axis[Y];
    next_target.target.axis[Z] += startpoint.axis[Z];
	}

	// E relative movement.
	// Matches Sprinter's behaviour as of March 2012.
	if (next_target.option_e_relative)
		next_target.target.e_relative = 1;
	else
		next_target.target.e_relative = 0;

	if (next_target.option_all_relative && !next_target.option_e_relative)
		next_target.target.axis[E] += startpoint.axis[E];

	// implement axis limits
	#ifdef	X_MIN
    if (next_target.target.axis[X] < (int32_t)(X_MIN * 1000.))
      next_target.target.axis[X] = (int32_t)(X_MIN * 1000.);
	#endif
	#ifdef	X_MAX
    if (next_target.target.axis[X] > (int32_t)(X_MAX * 1000.))
      next_target.target.axis[X] = (int32_t)(X_MAX * 1000.);
	#endif
	#ifdef	Y_MIN
    if (next_target.target.axis[Y] < (int32_t)(Y_MIN * 1000.))
      next_target.target.axis[Y] = (int32_t)(Y_MIN * 1000.);
	#endif
	#ifdef	Y_MAX
    if (next_target.target.axis[Y] > (int32_t)(Y_MAX * 1000.))
      next_target.target.axis[Y] = (int32_t)(Y_MAX * 1000.);
	#endif
	#ifdef	Z_MIN
    if (next_target.target.axis[Z] < (int32_t)(Z_MIN * 1000.))
      next_target.target.axis[Z] = (int32_t)(Z_MIN * 1000.);
	#endif
	#ifdef	Z_MAX
    if (next_target.target.axis[Z] > (int32_t)(Z_MAX * 1000.))
      next_target.target.axis[Z] = (int32_t)(Z_MAX * 1000.);
	#endif

	// The GCode documentation was taken from http://reprap.org/wiki/Gcode .

	if (next_target.seen_T) {
	    //? --- T: Select Tool ---
	    //?
	    //? Example: T1
	    //?
	    //? Select extruder number 1 to build with.  Extruder numbering starts at 0.

	    next_tool = next_target.T;
	}

	if (next_target.seen_G) {
		uint8_t axisSelected = 0;

		switch (next_target.G) {
			case 0:
				//? G0: Rapid Linear Motion
				//?
				//? Example: G0 X12
				//?
				//? In this case move rapidly to X = 12 mm.  In fact, the RepRap firmware uses exactly the same code for rapid as it uses for controlled moves (see G1 below), as - for the RepRap machine - this is just as efficient as not doing so.  (The distinction comes from some old machine tools that used to move faster if the axes were not driven in a straight line.  For them G0 allowed any movement in space to get to the destination as fast as possible.)
				//?
        temp_wait();
				backup_f = next_target.target.F;
				next_target.target.F = MAXIMUM_FEEDRATE_X * 2L;
				enqueue(&next_target.target);
				next_target.target.F = backup_f;
				break;

			case 1:
				//? --- G1: Linear Motion at Feed Rate ---
				//?
				//? Example: G1 X90.6 Y13.8 E22.4
				//?
				//? Go in a straight line from the current (X, Y) point to the point (90.6, 13.8), extruding material as the move happens from the current extruded length to a length of 22.4 mm.
				//?
        temp_wait();
				enqueue(&next_target.target);
				break;

				//	G2 - Arc Clockwise
				// unimplemented

				//	G3 - Arc Counter-clockwise
				// unimplemented

			case 4:
				//? --- G4: Dwell ---
				//?
				//? Example: G4 P200
				//?
				//? In this case sit still doing nothing for 200 milliseconds.  During delays the state of the machine (for example the temperatures of its extruders) will still be preserved and controlled.
				//?
				queue_wait();
				// delay
				if (next_target.seen_P) {
					for (;next_target.P > 0;next_target.P--) {
						clock();
						delay_ms(1);
					}
				}
				break;

			case 20:
				//? --- G20: Set Units to Inches ---
				//?
				//? Example: G20
				//?
				//? Units from now on are in inches.
				//?
				next_target.option_inches = 1;
				break;

			case 21:
				//? --- G21: Set Units to Millimeters ---
				//?
				//? Example: G21
				//?
				//? Units from now on are in millimeters.  (This is the RepRap default.)
				//?
				next_target.option_inches = 0;
				break;

			case 28:
				//? --- G28: Home ---
				//?
				//? Example: G28
				//?
        //? This causes the RepRap machine to search for its X, Y and Z
        //? endstops. It does so at high speed, so as to get there fast. When
        //? it arrives it backs off slowly until the endstop is released again.
        //? Backing off slowly ensures more accurate positioning.
				//?
        //? If you add axis characters, then just the axes specified will be
        //? seached. Thus
				//?
        //?   G28 X Y72.3
				//?
        //? will zero the X and Y axes, but not Z. Coordinate values are
        //? ignored.
				//?

				queue_wait();

				if (next_target.seen_X) {
					#if defined	X_MIN_PIN
						home_x_negative();
					#elif defined X_MAX_PIN
						home_x_positive();
					#endif
					axisSelected = 1;
				}
				if (next_target.seen_Y) {
					#if defined	Y_MIN_PIN
						home_y_negative();
					#elif defined Y_MAX_PIN
						home_y_positive();
					#endif
					axisSelected = 1;
				}
				if (next_target.seen_Z) {
          #if defined Z_MIN_PIN
            home_z_negative();
          #elif defined Z_MAX_PIN
            home_z_positive();
					#endif
					axisSelected = 1;
				}
				// there's no point in moving E, as E has no endstops

				if (!axisSelected) {
					home();
				}
				break;

			case 90:
				//? --- G90: Set to Absolute Positioning ---
				//?
				//? Example: G90
				//?
				//? All coordinates from now on are absolute relative to the origin
				//? of the machine. This is the RepRap default.
				//?
				//? If you ever want to switch back and forth between relative and
				//? absolute movement keep in mind, X, Y and Z follow the machine's
				//? coordinate system while E doesn't change it's position in the
				//? coordinate system on relative movements.
				//?

				// No wait_queue() needed.
				next_target.option_all_relative = 0;
				break;

			case 91:
				//? --- G91: Set to Relative Positioning ---
				//?
				//? Example: G91
				//?
				//? All coordinates from now on are relative to the last position.
				//?

				// No wait_queue() needed.
				next_target.option_all_relative = 1;
				break;

			case 92:
				//? --- G92: Set Position ---
				//?
				//? Example: G92 X10 E90
				//?
				//? Allows programming of absolute zero point, by reseting the current position to the values specified.  This would set the machine's X coordinate to 10, and the extrude coordinate to 90. No physical motion will occur.
				//?

				queue_wait();

				if (next_target.seen_X) {
          startpoint.axis[X] = next_target.target.axis[X];
					axisSelected = 1;
				}
				if (next_target.seen_Y) {
          startpoint.axis[Y] = next_target.target.axis[Y];
					axisSelected = 1;
				}
				if (next_target.seen_Z) {
          startpoint.axis[Z] = next_target.target.axis[Z];
					axisSelected = 1;
				}
				if (next_target.seen_E) {
          startpoint.axis[E] = next_target.target.axis[E];
					axisSelected = 1;
				}

				if (axisSelected == 0) {
          startpoint.axis[X] = next_target.target.axis[X] =
          startpoint.axis[Y] = next_target.target.axis[Y] =
          startpoint.axis[Z] = next_target.target.axis[Z] =
          startpoint.axis[E] = next_target.target.axis[E] = 0;
				}

				dda_new_startpoint();
				break;

			case 161:
				//? --- G161: Home negative ---
				//?
				//? Find the minimum limit of the specified axes by searching for the limit switch.
				//?
        #if defined X_MIN_PIN
          if (next_target.seen_X)
            home_x_negative();
        #endif
        #if defined Y_MIN_PIN
          if (next_target.seen_Y)
            home_y_negative();
        #endif
        #if defined Z_MIN_PIN
          if (next_target.seen_Z)
            home_z_negative();
        #endif
				break;

			case 162:
				//? --- G162: Home positive ---
				//?
				//? Find the maximum limit of the specified axes by searching for the limit switch.
				//?
        #if defined X_MAX_PIN
          if (next_target.seen_X)
            home_x_positive();
        #endif
        #if defined Y_MAX_PIN
          if (next_target.seen_Y)
            home_y_positive();
        #endif
        #if defined Z_MAX_PIN
          if (next_target.seen_Z)
            home_z_positive();
        #endif
				break;

				// unknown gcode: spit an error
			default:
				sersendf_P(PSTR("E: Bad G-code %d\n"), next_target.G);
				return;
		}
	}
	else if (next_target.seen_M) {
		uint8_t i;

		switch (next_target.M) {
			case 0:
				//? --- M0: machine stop ---
				//?
				//? Example: M0
				//?
				//? http://linuxcnc.org/handbook/RS274NGC_3/RS274NGC_33a.html#1002379
				//? Unimplemented, especially the restart after the stop. Fall trough to M2.
				//?

			case 2:
      case 84: // For compatibility with slic3rs default end G-code.
				//? --- M2: program end ---
				//?
				//? Example: M2
				//?
				//? http://linuxcnc.org/handbook/RS274NGC_3/RS274NGC_33a.html#1002379
				//?
				queue_wait();
				for (i = 0; i < NUM_HEATERS; i++)
					temp_set(i, 0);
				power_off();
        serial_writestr_P(PSTR("\nstop\n"));
				break;

			case 6:
				//? --- M6: tool change ---
				//?
				//? Undocumented.
				tool = next_tool;
				break;

      #ifdef SD
      case 20:
        //? --- M20: list SD card. ---
        sd_list("/");
        break;

      case 21:
        //? --- M21: initialise SD card. ---
        //?
        //? Has to be done before doing any other operation, including M20.
        sd_mount();
        break;

      case 22:
        //? --- M22: release SD card. ---
        //?
        //? Not mandatory. Just removing the card is fine, but results in
        //? odd behaviour when trying to read from the card anyways. M22
        //? makes also sure SD card printing is disabled, even with the card
        //? inserted.
        sd_unmount();
        break;

      case 23:
        //? --- M23: select file. ---
        //?
        //? This opens a file for reading. This file is valid up to M22 or up
        //? to the next M23.
        sd_open(gcode_str_buf);
        break;

      case 24:
        //? --- M24: start/resume SD print. ---
        //?
        //? This makes the SD card available as a G-code source. File is the
        //? one selected with M23.
        gcode_sources |= GCODE_SOURCE_SD;
        break;

      case 25:
        //? --- M25: pause SD print. ---
        //?
        //? This removes the SD card from the bitfield of available G-code
        //? sources. The file is kept open. The position inside the file
        //? is kept as well, to allow resuming.
        gcode_sources &= ! GCODE_SOURCE_SD;
        break;
      #endif /* SD */

			case 82:
				//? --- M82 - Set E codes absolute ---
				//?
				//? This is the default and overrides G90/G91.
				//? M82/M83 is not documented in the RepRap wiki, behaviour
				//? was taken from Sprinter as of March 2012.
				//?
				//? While E does relative movements, it doesn't change its
				//? position in the coordinate system. See also comment on G90.
				//?

				// No wait_queue() needed.
				next_target.option_e_relative = 0;
				break;

			case 83:
				//? --- M83 - Set E codes relative ---
				//?
				//? Counterpart to M82.
				//?

				// No wait_queue() needed.
				next_target.option_e_relative = 1;
				break;

			// M3/M101- extruder on
			case 3:
			case 101:
				//? --- M101: extruder on ---
				//?
				//? Undocumented.
        temp_wait();
				#ifdef DC_EXTRUDER
					heater_set(DC_EXTRUDER, DC_EXTRUDER_PWM);
				#endif
				break;

			// M5/M103- extruder off
			case 5:
			case 103:
				//? --- M103: extruder off ---
				//?
				//? Undocumented.
				#ifdef DC_EXTRUDER
					heater_set(DC_EXTRUDER, 0);
				#endif
				break;

			case 104:
				//? --- M104: Set Extruder Temperature (Fast) ---
				//?
				//? Example: M104 S190
				//?
        //? Set the temperature of the current extruder to 190<sup>o</sup>C
        //? and return control to the host immediately (''i.e.'' before that
        //? temperature has been reached by the extruder). For waiting, see M116.
        //?
        //? Teacup supports an optional P parameter as a zero-based temperature
        //? sensor index to address (e.g. M104 P1 S100 will set the temperature
        //? of the heater connected to the second temperature sensor rather
        //? than the extruder temperature).
        //?
				if ( ! next_target.seen_S)
					break;
        if ( ! next_target.seen_P)
          #ifdef HEATER_EXTRUDER
            next_target.P = HEATER_EXTRUDER;
          #else
            next_target.P = 0;
          #endif
				temp_set(next_target.P, next_target.S);
				break;

			case 105:
        //? --- M105: Get Temperature(s) ---
				//?
				//? Example: M105
				//?
        //? Request the temperature of the current extruder and the build base
        //? in degrees Celsius. For example, the line sent to the host in
        //? response to this command looks like
				//?
				//? <tt>ok T:201 B:117</tt>
				//?
        //? Teacup supports an optional P parameter as a zero-based temperature
        //? sensor index to address.
				//?
				#ifdef ENFORCE_ORDER
					queue_wait();
				#endif
				if ( ! next_target.seen_P)
					next_target.P = TEMP_SENSOR_none;
				temp_print(next_target.P);
				break;

			case 7:
			case 106:
				//? --- M106: Set Fan Speed / Set Device Power ---
				//?
				//? Example: M106 S120
				//?
				//? Control the cooling fan (if any).
				//?
        //? Teacup supports an optional P parameter as a zero-based heater
        //? index to address. The heater index can differ from the temperature
        //? sensor index, see config.h.

				#ifdef ENFORCE_ORDER
					// wait for all moves to complete
					queue_wait();
				#endif
        if ( ! next_target.seen_P)
          #ifdef HEATER_FAN
            next_target.P = HEATER_FAN;
          #else
            next_target.P = 0;
          #endif
				if ( ! next_target.seen_S)
					break;
        heater_set(next_target.P, next_target.S);
				break;

			case 110:
				//? --- M110: Set Current Line Number ---
				//?
				//? Example: N123 M110
				//?
				//? Set the current line number to 123.  Thus the expected next line after this command will be 124.
				//? This is a no-op in Teacup.
				//?
				break;

      #ifdef DEBUG
			case 111:
				//? --- M111: Set Debug Level ---
				//?
				//? Example: M111 S6
				//?
				//? Set the level of debugging information transmitted back to the host to level 6.  The level is the OR of three bits:
				//?
				//? <Pre>
				//? #define         DEBUG_PID       1
				//? #define         DEBUG_DDA       2
				//? #define         DEBUG_POSITION  4
				//? </pre>
				//?
				//? This command is only available in DEBUG builds of Teacup.

				if ( ! next_target.seen_S)
					break;
				debug_flags = next_target.S;
				break;
      #endif /* DEBUG */

      case 112:
        //? --- M112: Emergency Stop ---
        //?
        //? Example: M112
        //?
        //? Any moves in progress are immediately terminated, then the printer
        //? shuts down. All motors and heaters are turned off. Only way to
        //? restart is to press the reset button on the master microcontroller.
        //? See also M0.
        //?
        timer_stop();
        queue_flush();
        power_off();
        cli();
        for (;;)
          wd_reset();
        break;

			case 114:
				//? --- M114: Get Current Position ---
				//?
				//? Example: M114
				//?
				//? This causes the RepRap machine to report its current X, Y, Z and E coordinates to the host.
				//?
				//? For example, the machine returns a string such as:
				//?
				//? <tt>ok C: X:0.00 Y:0.00 Z:0.00 E:0.00</tt>
				//?
				#ifdef ENFORCE_ORDER
					// wait for all moves to complete
					queue_wait();
				#endif
				update_current_position();
				sersendf_P(PSTR("X:%lq,Y:%lq,Z:%lq,E:%lq,F:%lu\n"),
                        current_position.axis[X], current_position.axis[Y],
                        current_position.axis[Z], current_position.axis[E],
				                current_position.F);

        if (mb_tail_dda != NULL) {
          if (DEBUG_POSITION && (debug_flags & DEBUG_POSITION)) {
            sersendf_P(PSTR("Endpoint: X:%ld,Y:%ld,Z:%ld,E:%ld,F:%lu,c:%lu}\n"),
                       mb_tail_dda->endpoint.axis[X],
                       mb_tail_dda->endpoint.axis[Y],
                       mb_tail_dda->endpoint.axis[Z],
                       mb_tail_dda->endpoint.axis[E],
                       mb_tail_dda->endpoint.F,
                       #ifdef ACCELERATION_REPRAP
                         mb_tail_dda->end_c
                       #else
                         mb_tail_dda->c
                       #endif
            );
          }
          print_queue();
        }

				break;

			case 115:
				//? --- M115: Get Firmware Version and Capabilities ---
				//?
				//? Example: M115
				//?
				//? Request the Firmware Version and Capabilities of the current microcontroller
				//? The details are returned to the host computer as key:value pairs separated by spaces and terminated with a linefeed.
				//?
				//? sample data from firmware:
				//?  FIRMWARE_NAME:Teacup FIRMWARE_URL:http://github.com/traumflug/Teacup_Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:1 TEMP_SENSOR_COUNT:1 HEATER_COUNT:1
				//?

				sersendf_P(PSTR("FIRMWARE_NAME:Teacup FIRMWARE_URL:http://github.com/traumflug/Teacup_Firmware/ PROTOCOL_VERSION:1.0 MACHINE_TYPE:Mendel EXTRUDER_COUNT:%d TEMP_SENSOR_COUNT:%d HEATER_COUNT:%d\n"), 1, NUM_TEMP_SENSORS, NUM_HEATERS);
				break;

			case 116:
				//? --- M116: Wait ---
				//?
				//? Example: M116
				//?
				//? Wait for temperatures and other slowly-changing variables to arrive at their set values.
        temp_set_wait();
				break;

      case 119:
        //? --- M119: report endstop status ---
        //? Report the current status of the endstops configured in the
        //? firmware to the host.
        power_on();
        endstops_on();
        delay_ms(10); // allow the signal to stabilize
        {
          #if ! (defined(X_MIN_PIN) || defined(X_MAX_PIN) || \
                 defined(Y_MIN_PIN) || defined(Y_MAX_PIN) || \
                 defined(Z_MIN_PIN) || defined(Z_MAX_PIN))
            serial_writestr_P(PSTR("No endstops defined."));
          #else
            const char* const open = PSTR("open ");
            const char* const triggered = PSTR("triggered ");
          #endif

          #if defined(X_MIN_PIN)
            serial_writestr_P(PSTR("x_min:"));
            x_min() ? serial_writestr_P(triggered) : serial_writestr_P(open);
          #endif
          #if defined(X_MAX_PIN)
            serial_writestr_P(PSTR("x_max:"));
            x_max() ? serial_writestr_P(triggered) : serial_writestr_P(open);
          #endif
          #if defined(Y_MIN_PIN)
            serial_writestr_P(PSTR("y_min:"));
            y_min() ? serial_writestr_P(triggered) : serial_writestr_P(open);
          #endif
          #if defined(Y_MAX_PIN)
            serial_writestr_P(PSTR("y_max:"));
            y_max() ? serial_writestr_P(triggered) : serial_writestr_P(open);
          #endif
          #if defined(Z_MIN_PIN)
            serial_writestr_P(PSTR("z_min:"));
            z_min() ? serial_writestr_P(triggered) : serial_writestr_P(open);
          #endif
          #if defined(Z_MAX_PIN)
            serial_writestr_P(PSTR("z_max:"));
            z_max() ? serial_writestr_P(triggered) : serial_writestr_P(open);
          #endif
        }
        endstops_off();
        serial_writechar('\n');
        break;

      #ifdef EECONFIG
			case 130:
				//? --- M130: heater P factor ---
				//? Undocumented.
			  	//  P factor in counts per degreeC of error
        if ( ! next_target.seen_P)
          #ifdef HEATER_EXTRUDER
            next_target.P = HEATER_EXTRUDER;
          #else
            next_target.P = 0;
          #endif
				if (next_target.seen_S)
					pid_set_p(next_target.P, next_target.S);
				break;

			case 131:
				//? --- M131: heater I factor ---
				//? Undocumented.
			  	// I factor in counts per C*s of integrated error
        if ( ! next_target.seen_P)
          #ifdef HEATER_EXTRUDER
            next_target.P = HEATER_EXTRUDER;
          #else
            next_target.P = 0;
          #endif
				if (next_target.seen_S)
					pid_set_i(next_target.P, next_target.S);
				break;

			case 132:
				//? --- M132: heater D factor ---
				//? Undocumented.
			  	// D factor in counts per degreesC/second
        if ( ! next_target.seen_P)
          #ifdef HEATER_EXTRUDER
            next_target.P = HEATER_EXTRUDER;
          #else
            next_target.P = 0;
          #endif
				if (next_target.seen_S)
					pid_set_d(next_target.P, next_target.S);
				break;

			case 133:
				//? --- M133: heater I limit ---
				//? Undocumented.
        if ( ! next_target.seen_P)
          #ifdef HEATER_EXTRUDER
            next_target.P = HEATER_EXTRUDER;
          #else
            next_target.P = 0;
          #endif
				if (next_target.seen_S)
					pid_set_i_limit(next_target.P, next_target.S);
				break;

			case 134:
				//? --- M134: save PID settings to eeprom ---
				//? Undocumented.
				heater_save_settings();
				break;
      #endif /* EECONFIG */

      #ifdef DEBUG
			case 136:
				//? --- M136: PRINT PID settings to host ---
				//? Undocumented.
				//? This comand is only available in DEBUG builds.
        if ( ! next_target.seen_P)
          #ifdef HEATER_EXTRUDER
            next_target.P = HEATER_EXTRUDER;
          #else
            next_target.P = 0;
          #endif
				heater_print(next_target.P);
				break;
      #endif /* DEBUG */

			case 140:
				//? --- M140: Set heated bed temperature ---
				//? Undocumented.
				#ifdef	HEATER_BED
					if ( ! next_target.seen_S)
						break;
					temp_set(HEATER_BED, next_target.S);
				#endif
				break;

      case 220:
        //? --- M220: Set speed factor override percentage ---
        if ( ! next_target.seen_S)
          break;
        // Scale 100% = 256
        next_target.target.f_multiplier = (next_target.S * 64 + 12) / 25;
        break;

      case 221:
        //? --- M221: Control the extruders flow ---
        if ( ! next_target.seen_S)
          break;
        // Scale 100% = 256
        next_target.target.e_multiplier = (next_target.S * 64 + 12) / 25;
        break;

      #ifdef DEBUG
			case 240:
				//? --- M240: echo off ---
				//? Disable echo.
				//? This command is only available in DEBUG builds.
				debug_flags &= ~DEBUG_ECHO;
				serial_writestr_P(PSTR("Echo off\n"));
				break;

			case 241:
				//? --- M241: echo on ---
				//? Enable echo.
				//? This command is only available in DEBUG builds.
				debug_flags |= DEBUG_ECHO;
				serial_writestr_P(PSTR("Echo on\n"));
				break;
      #endif /* DEBUG */

				// unknown mcode: spit an error
			default:
				sersendf_P(PSTR("E: Bad M-code %d\n"), next_target.M);
		} // switch (next_target.M)
	} // else if (next_target.seen_M)
} // process_gcode_command()
Ejemplo n.º 10
0
/**
 *  A simple cog for painting the screen
 */
void LCD_Run(void) {

    FILE *fp;
    uint8_t buffer[500];
    uint16_t x, y, i, j;
    int dataOffset;
    int size;
    int counter = 0;

    LCD_Init();

    // Initialize the interface to the SD card
    sd_mount(SD_DO, SD_SCK, SD_DI, SD_SS);

    while(1) {
//    paint(0xF800);
//    pause(100);
//    paint(0x07E0);
//    pause(100);
//    paint(0x001F);
//    pause(100);

        // Open the first image
        if(counter == 0) {
            fp = fopen("1.bmp", "r");
            counter++;
        }
        else {
            fp = fopen("2.bmp", "r");
            counter = 0;
        }

        // Read in the header
        fread(buffer, 1, 54, fp);
        // Get the size of the image
        // 16 bit numbers, do some bit shifting
        x = buffer[18] + (buffer[19] << 8);
        y = buffer[22] + (buffer[23] << 8);
        //size = buffer[2] | (buffer[3] << 8) | (buffer[4] << 16) | (buffer[5] << 24);
        dataOffset = buffer[10] | (buffer[11] << 8) | (buffer[12] << 16) | (buffer[13] << 24);

        // Seek the file pointer to the start of the pixel data
        fseek(fp, dataOffset, SEEK_SET);


        LCD_SetWindow(0,0,239,400);

        for(i = 0; i < y; i++) {

            // Read a line in
            fread(buffer, 1, x * 2, fp);

            for(j = 0; j < x * 2; j += 2) {
                // Write the pixel data out to the display
                // Note that the pixel data is the Red, Green, Blue data in the 565 format, ie:
                //
                // Bit 0  1  2  3  4  5  6  7    8  9  10 11 12 13 14 15
                // Use B1 B2 B3 B4 B5 G0 G1 G2   G3 G4 G5 R1 R2 R3 R4 R5
                //
                // Notice that we only have 5 bits of Blue and Red?  The human eye is more sensitive
                // to the color green, so to make the RGB fit into 16 bits it is given priority
                LCD_Write_Data((buffer[j]) + (buffer[j+1] << 8));
            }
        }

        // Close and prepare for the next file
        fclose(fp);

    }
}