예제 #1
0
파일: main.c 프로젝트: novia713/raspi_lcd
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{ 
	int Contrast,Backlight;

	Contrast = 9;
	Backlight = 1;
			
	printf("RaspiLCD Demo V0.9 by Martin Steppuhn [" __DATE__ " " __TIME__"]\n");
	printf("RaspberryHwRevision=%i\r\n",GetRaspberryHwRevision());
		
	if(!RaspiLcdHwInit()) { printf("RaspiLcdHwInit() failed!\r\n"); return 1; }
	LCD_Init();			// Init Display
	SetBacklight(1);	// Turn Backlight on
	
	DemoView = 0;
	DemoCpuTemperatureInit();
	DemoBubblesInit();
		
	while(1)
	{
		DemoCount++;
		SleepMs(100);
		UpdateButtons();
		//	printf("Buttons: %02X (%02X) Contrast=%i Backlight=%u\r\n",Button,ButtonPressed,Contrast,Backlight);

		if((DemoCount & 3) == 0) LogCpuTemperature();			
			
		if(BUTTON_PRESSED_UP || BUTTON_PRESSED_DOWN)
		{
			if(BUTTON_PRESSED_UP   && (Contrast < 20))  Contrast++; 
			if(BUTTON_PRESSED_DOWN && (Contrast > 0))   Contrast--; 
			LCD_SetContrast(Contrast); 
		}
		if(BUTTON_PRESSED_CENTER)
		{
			Backlight = (Backlight) ? 0 : 1;	// Toggle Backlight
			SetBacklight(Backlight);			// Write to Hardware
		}		
		if(BUTTON_PRESSED_LEFT  && DemoView) DemoView--;		
		if(BUTTON_PRESSED_RIGHT && (DemoView < 6)) DemoView++;		
	
		if(     DemoView == 0)	 DemoLogo();
		else if(DemoView == 1)	 { if((DemoCount & 3) == 0) DemoCpuTemperature(); }
		else if(DemoView == 2)  DemoBitmap();
		else if(DemoView == 3)  DemoFont();
		else if(DemoView == 4)	 DemoVector();
		else if(DemoView == 5)	 DemoBubbles();
		else if(DemoView == 6)	 DemoText();
					
		LCD_WriteFramebuffer();
	}
	return(0);
}
char Execute_M(char *ok,char *esc)
{
  char endprg=0, arghhhh=*esc,
       Mbuffer[6],buf[20];
  int  m_wert;
  int  xi_wert,
       zk_wert,
       flkt_wert,
       h_wert;

  Status("Simulation");
  Meldung("Bearbeite M-Befehl.");

  /* G/M umkopieren zwecks Veraenderung */
  strcpy(Mbuffer,cncprg[ip].GM);

  /* M-Zeichen eliminieren & Wert feststellen */
  Mbuffer[0]=' ';
  m_wert=atoi(Mbuffer);

  strcpy(buf,cncprg[ip].XI);
  ElimSpaces(buf);
  ElimSpaces(buf);
  if (isdigit((int)buf[0]) || buf[0]=='-')
     xi_wert=atoi(buf);
    else xi_wert=atoi(buf+1);

  strcpy(buf,cncprg[ip].ZK);
  ElimSpaces(buf);
  ElimSpaces(buf);
  if (isdigit((int)buf[0]) || buf[0]=='-')
     zk_wert=atoi(buf);
    else zk_wert=atoi(buf+1);

  strcpy(buf,cncprg[ip].FLKT);
  ElimSpaces(buf);
  ElimSpaces(buf);
  if (isdigit((int)buf[0]) || buf[0]=='-')
     flkt_wert=atoi(buf);
    else flkt_wert=atoi(buf+1);

  h_wert=atoi(cncprg[ip].H);

  /* M-Befehle verzweigen */
  switch(m_wert)
  {
     /**************** M00 *******************/
     case 0:{
	      Meldung("Taste zur Fortsetzung.");
	      getch();
	      Meldung(" ");
	    } break; /* No Action */
     /**************** M01: Pseudo: Stueck neuzeichnen *******************/
     case 1:{
	      DemoText();
	      Zeichne_stueck();
	    }break;
     /**************** M03 *******************/
     case 3:break; /* No Action */
     /**************** M05 *******************/
     case 5:break; /* No Action */
     /**************** M06 *******************/
     case 6: /* werkzeugwechsel */
	     if (cncprg[ip].FLKT[0]=='T' && flkt_wert>0 && flkt_wert<=max_tools)
	     {
	       _settextposition(3,37);
	       _outtext(cncprg[ip].FLKT);
	       _outtext("        ");

	       Setzte_Stahl(xrad,zpos,(char)flkt_wert);
	       endprg=Ziehe_Gerade(xrad,zpos,xrad+xi_wert,zpos+zk_wert,
					 prgconfig.wait_g00,schritt_g00,checkTasten);
	       xrad=xrad+xi_wert;
	       zpos=zpos+zk_wert;

	       xcorr=xi_wert;
	       zcorr=zk_wert;
	     } else { *ok=0; endprg=1; }
	     break;
     /**************** M17 *******************/
     case 17:if (sp>0)
	     {
	       ip=stack[--sp];
	       ip++;
	     } else
	     {
	       Meldung("Fehler im RETURN-M17-Befehl: Keine Subroutine!");
	       Status("Fehler!");
	       endprg=1; *ok=0;
	     }break;
     /**************** M30 *******************/
     case 30:{
	       Status("M30-Ende");
	       Meldung(" ");
	       endprg=1;
	     } break;
     /**************** M98 *******************/
     case 98:break; /* No Action */
     /**************** M99 *******************/
     case 99:{
	       /* nur in Verbindung mit G02/G03 */
	       Meldung("Einzelner M99 Befehl gefunden!!");
	       Status("Fehler!");
	       endprg=1;
	       *ok=0;
	     }
     /**************** Error *******************/
     default:/* Unbekannter M-Befehl */
	     {
	       *ok=0;	 /* Fehlerflag */
	       endprg=1; /* Prg-Ende-Flag */
	     }
  }/* von switch m_wert */

  /* Returnwert */
  if (!*ok && endprg)
	    {
	      Status("E-Unterbrechung");
	      Meldung("M-Befehl in der aktuellen Zeile ist unbekannt oder unkorrekt!");
	    }

  return endprg;
}