Beispiel #1
0
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
int main(int argc, char **argv)
{ 
	uint32	Counter;
	int16 Temperature;
	uint8 Humidity;
	uint8 HwRev;
	char Mode;	
	
	Counter = 0;
	Mode = 0;
	
	HwRev = GetRaspberryHwRevision();
	
	if((argc > 1) &&  ((argv[1][0]=='S') || (argv[1][0]=='L') || (argv[1][0]=='C'))) Mode = argv[1][0];
		
	if(!Mode) 
	{
		printf("Raspi-SHT21 V3.0.0 by Martin Steppuhn (www.emsystech.de) [" __DATE__ " " __TIME__"]\n");
		printf("Options:\n");
		printf("   S : [20.0 99]\n");	
		printf("   L : [temperature=20.0][humidity=99]\n");	
		printf("   C : [Temperature,20,0][Humidity,99]\n");
		printf("RaspberryHwRevision=%i\r\n",HwRev);
	}	
	
	if(HwRev < 2) 	I2C_Open("/dev/i2c-0");	 // Hardware Revision 1.0
		else		I2C_Open("/dev/i2c-1");  // Hardware Revision 2.0
	I2C_Setup(I2C_SLAVE, 0x40);
	
	if(I2cError)
	{	
		I2C_PrintError();
		exit(1);
	}
			
	SHT21_Read(&Temperature,&Humidity);
	if(Sht21Error == 0)
	{
		if(     Mode == 'S') printf("%.1f\t%u\n",((float)Temperature)/10,Humidity);
		else if(Mode == 'L') printf("temperature=%.1f\nhumidity=%u\n",((float)Temperature)/10,Humidity);
		else if(Mode == 'C') printf("Temperature,%.1f\nHumidity,%u\n",((float)Temperature)/10,Humidity);
		else
		{
			while(1)
			{
				SHT21_Read(&Temperature,&Humidity);
				if(Sht21Error == 0) printf("%lu\t%.1f\t%u\n",Counter++,((float)Temperature)/10,Humidity);
					else		{	PrintSht21Error();	I2cError = 0;	}
				DelayMs(1000);
			}
		}
	}
	else
	{
		PrintSht21Error();
	}
	I2C_Close();
	return(0);
}
Beispiel #2
0
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
//--------------------------------------------------------------------------------------------------
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);
}
Beispiel #3
0
//--------------------------------------------------------------------------------------------------
// Name:      HalInit
// Function:  Setup GPIO for Raspi_LCD
//            
// Parameter: -
// Return:    -
//--------------------------------------------------------------------------------------------------
int RaspiLcdHwInit(void)
{
#ifdef QT_EMULATION
  return 1; // QT-Simul!
#endif
  int HwRev;

  HwRev = GetRaspberryHwRevision();

  if (!bcm2835_init()) return 0;

  // Buttons
  PinButton[0] = 17;
  PinButton[1] = 4;
  PinButton[2] = 24;
  PinButton[3] = 23;
  PinButton[4] = 22;
  PinButton[5] = (HwRev < 2) ? 21 : 27;;

  bcm2835_gpio_fsel(PinButton[0],BCM2835_GPIO_FSEL_INPT)	;	// Set GPIO Pin to Input
  bcm2835_gpio_fsel(PinButton[1],BCM2835_GPIO_FSEL_INPT)	;	// Set GPIO Pin to Input
  bcm2835_gpio_fsel(PinButton[2],BCM2835_GPIO_FSEL_INPT)	;	// Set GPIO Pin to Input
  bcm2835_gpio_fsel(PinButton[3],BCM2835_GPIO_FSEL_INPT)	;	// Set GPIO Pin to Input
  bcm2835_gpio_fsel(PinButton[4],BCM2835_GPIO_FSEL_INPT)	;	// Set GPIO Pin to Input
  bcm2835_gpio_fsel(PinButton[5],BCM2835_GPIO_FSEL_INPT)	;	// Set GPIO Pin to Input

  bcm2835_gpio_set_pud(PinButton[0],BCM2835_GPIO_PUD_UP); 	// Enable Pullup
  bcm2835_gpio_set_pud(PinButton[1],BCM2835_GPIO_PUD_UP); 	// Enable Pullup
  bcm2835_gpio_set_pud(PinButton[2],BCM2835_GPIO_PUD_UP); 	// Enable Pullup
  bcm2835_gpio_set_pud(PinButton[3],BCM2835_GPIO_PUD_UP); 	// Enable Pullup
  bcm2835_gpio_set_pud(PinButton[4],BCM2835_GPIO_PUD_UP); 	// Enable Pullup
  bcm2835_gpio_set_pud(PinButton[5],BCM2835_GPIO_PUD_UP); 	// Enable Pullup

  // LCD Display
  bcm2835_gpio_fsel(PIN_LCD_MOSI,     BCM2835_GPIO_FSEL_OUTP);	// GPIO10 Output: MOSI
  bcm2835_gpio_fsel(PIN_LCD_SCLK,     BCM2835_GPIO_FSEL_OUTP);	// GPIO11 Output: SCLK
  bcm2835_gpio_fsel(PIN_LCD_RST,      BCM2835_GPIO_FSEL_OUTP);	// GPIO25 Output: RST
  bcm2835_gpio_fsel(PIN_LCD_CS ,      BCM2835_GPIO_FSEL_OUTP);	// GPIO8  Output: CS
  bcm2835_gpio_fsel(PIN_LCD_RS,       BCM2835_GPIO_FSEL_OUTP);	// GPIO7  Output: RS
  bcm2835_gpio_fsel(PIN_LCD_BACKLIGHT,BCM2835_GPIO_FSEL_OUTP);	// GPIO18 Output: Backlight

  Button = ButtonMem = ButtonPressed = 0;

  return 1;
}