Пример #1
0
static screen_t *
screen_init(const int _din, const int _sclk, const int _dc, const int _rst, const int _cs, const int contrast)
{
	screen_t *scretp;

	if (wiringPiSetup() == -1) {
		syslog(LOG_LOCAL0|LOG_ERR, "wiringPi-Error");
		return (NULL);
	}
	if (pcf8591Setup(200, 0x48) == -1) {
		syslog(LOG_LOCAL0|LOG_ERR, "wiringPi-Error");
		return (NULL);
  	}
  
	/* init and clear lcd */
	LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
	LCDclear();
  
	/* show logo */
	LCDshowLogo();

	if ((scretp = calloc(1, sizeof(screen_t))) == NULL) {
		return (NULL);
	}
	scretp->sc_contrast = contrast;
	snprintf(scretp->sc_line1_buf, sizeof(scretp->sc_line1_buf), "Pilab");
	cur_time(scretp->sc_line2_buf, sizeof(scretp->sc_line2_buf));
	return (scretp);
}
Пример #2
0
int main(int argc, char **argv)
{
	int i;
   setvbuf(stdout, NULL, _IOLBF, 0);

	setup_sighandlers();

    // check wiringPi setup
    if (wiringPiSetup() == -1)
    {
        printf("wiringPi-Error\n");
        exit(1);
    }

    // init and clear lcd
    pinMode(_bk, OUTPUT);
    digitalWrite(_bk, HIGH);

	unlink(DEVFILE);
	if (mkfifo(DEVFILE, 0666) < 0)
		fatal("dispd: Failed to create %s: %m\n", DEVFILE);
	if (chmod(DEVFILE, 0666) < 0)
		fatal("didpd: Failed to set permissions on %s: %m\n", DEVFILE);

	//if (daemon(0,1) < 0)
	//	fatal("dispd: Failed to daemonize process: %m\n");

    LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
    LCDclear();
    LCDshowLogo();
    delay(2000);

	go_go_go();

	return 0;
}
Пример #3
0
int main (void)
{
  // print infos
  printf("Raspberry Pi PCD8544 sysinfo display\n");
  printf("========================================\n");

  // check wiringPi setup
  if (wiringPiSetup() == -1)
  {
	printf("wiringPi-Error\n");
    exit(1);
  }

  // init and clear lcd
  LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
  LCDclear();

  // show logo
  LCDshowLogo();

  delay(2000);

  for (;;)
  {
	  // clear lcd
	  LCDclear();

	  // get system usage / info
	  struct sysinfo sys_info;
	  if(sysinfo(&sys_info) != 0)
	  {
		printf("sysinfo-Error\n");
	  }

	  // uptime
	  char uptimeInfo[15];
	  unsigned long uptime = sys_info.uptime / 60;
	  sprintf(uptimeInfo, "Uptime %ld min.", uptime);

	  // cpu info
	  char cpuInfo[10];
	  unsigned long avgCpuLoad = sys_info.loads[0] / 1000;
	  sprintf(cpuInfo, "CPU %ld%%", avgCpuLoad);

	  // ram info
	  char ramInfo[10];
	  unsigned long totalRam = sys_info.freeram / 1024 / 1024;
	  sprintf(ramInfo, "RAM %ld MB", totalRam);

	  // build screen
	  //LCDdrawstring(0, 0, "Raspberry Pi:");
	  LCDdrawstring(0, 0, "Sunfounder.com");
	  LCDdrawline(0, 10, 83, 10, BLACK);
	  LCDdrawstring(0, 12, uptimeInfo);
	  LCDdrawstring(0, 20, cpuInfo);
	  LCDdrawstring(0, 28, ramInfo);
	  LCDdisplay();

	  delay(1000);
  }

    //for (;;){
  //  printf("LED On\n");
  //  digitalWrite(pin, 1);
  //  delay(250);
  //  printf("LED Off\n");
  //  digitalWrite(pin, 0);
  //  delay(250);
  //}

  return 0;
}
Пример #4
0
static void go_go_go(void)
{
	int fd;
	struct timeval tv;
	static char line[128];
	int nchars = 0;
    int ntimes_out = 0;
    int ntimes_reset = 0;
	if ((fd = open(DEVFILE, O_RDWR|O_NONBLOCK)) == -1)
		fatal("dispd: Failed to open %s: %m\n", DEVFILE);

	for (;;) {
		int n, width, servo;
		fd_set ifds;
		char width_arg[64];

		FD_ZERO(&ifds);
		FD_SET(fd, &ifds);
        tv.tv_sec = 3;
        tv.tv_usec = 0;
		if ((n = select(fd+1, &ifds, NULL, NULL, &tv)) != 1)
        {
            // turn off backlight after 6 sec
            if(++ntimes_out > 2)
            {
                digitalWrite(_bk, LOW);
                delay(10);
            }
            if(++ntimes_reset > 20) // 60 sec
            {
                ntimes_reset = 0;
                LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
                LCDdisplay();
                delay(10);
            }
            //printf("%s : %d\n", __FILE__, __LINE__);
			continue;
        }   
		while (read(fd, line+nchars, 1) == 1) {
            //printf("%s : %d\n", __FILE__, __LINE__);
			if (line[nchars] == '\n') 
            {
				line[nchars] = '\0';
				nchars = 0;
                std::string str = line;

                // do whatever
                if(strcmp(line,"%clear%") == 0)                
                {
                    linebuff.clear();
                    update_display();
                    digitalWrite(_bk, HIGH);               
                }   
                else if(strcmp(line,"%logo%") == 0)
                {
                    linebuff.clear();
                    LCDclear();
                    LCDshowLogo();
                    digitalWrite(_bk, HIGH);
                }
                else if(str.substr(0,5) == "%bat%")
                {
                    std::string val = str.substr(6, str.npos);
                    battery_level = atoi(val.c_str());
                    update_display();
                }
                else if(str.substr(0,6) == "%plug%")
                {
                    std::string val = str.substr(7, str.npos);
                    battery_plugged = (atoi(val.c_str()) != 0);
                    update_display();
                }

                else
                {
                    int start = 0;  
                    int size = 14;  
                    while (start < str.size()) 
                    {  
                        int end = ((start + size) < str.size()) ? size : str.size() - start;                        
                        if(linebuff.size()>4)
                            linebuff.erase(linebuff.begin());	                  
                        linebuff.push_back(str.substr(start, end));
                        start += size;  
                    } 
                    update_display();
                    digitalWrite(_bk, HIGH);
                    ntimes_out = 0;
                }
                // turn off backlight after 5 sec
                if(++ntimes_out > 5)
                {
                    digitalWrite(_bk, LOW);
                    delay(10);
                }
                LCDdisplay();
                delay(10);
			} 
            else 
            {
				if (++nchars >= 126) {
					fprintf(stderr, "Input too long\n");
					nchars = 0;
				}
			}
		} // end while
	} // end for
}
Пример #5
0
int main (void)
{
  // print infos
  printf("Raspberry Pi PCD8544 test\n");
  printf("========================================\n");
  
  printf("CLK on Port %i \n", _sclk);
  printf("DIN on Port %i \n", _din);
  printf("DC on Port %i \n", _dc);
  printf("CS on Port %i \n", _cs);
  printf("RST on Port %i \n", _rst);  
  printf("========================================\n");
  
  // check wiringPi setup
  if (wiringPiSetup() == -1)
  {
	printf("wiringPi-Error\n");
    exit(1);
  }
  
  // init and clear lcd
  LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
  LCDclear();

  // turn all the pixels on (a handy test)
  printf("Test: All pixels on.\n");
  LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYALLON);
  delay(1000);
  // back to normal
  printf("Test: All pixels off.\n");
  LCDcommand(PCD8544_DISPLAYCONTROL | PCD8544_DISPLAYNORMAL);
  LCDclear();
  
  // display logo
  printf("Test: Display logo.\n");
  LCDshowLogo();
  delay(2000);
  LCDclear();
  
  // draw a single pixel
  printf("Test: Display single pixel.\n");
  LCDsetPixel(10, 10, BLACK);
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw many lines
  printf("Test: Draw many lines.\n");
  int i;
  for (i=0; i<84; i+=4) {
    LCDdrawline(0, 0, i, 47, BLACK);
  }  
  for (i=0; i<48; i+=4) {
    LCDdrawline(0, 0, 83, i, BLACK);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw rectangles
  printf("Test: Draw rectangles.\n");
  for (i=0; i<48; i+=2) {
    LCDdrawrect(i, i, 96-i, 48-i, BLACK);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw multiple rectangles
  printf("Test: Draw multiple rectangles.\n");
  for (i=0; i<48; i++) {
    // alternate colors for moire effect
    LCDfillrect(i, i, 84-i, 48-i, i%2);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw mulitple circles
  printf("Test: Draw multiple circles.\n");
  for (i=0; i<48; i+=2) {
    LCDdrawcircle(41, 23, i, BLACK);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  // draw the first ~120 characters in the font
  printf("Test: Draw the first ~120 chars.\n");
  for (i=0; i < 64; i++) {
    LCDdrawchar((i % 14) * 6, (i/14) * 8, i);
  }    
  LCDdisplay();
  delay(2000);
  for (i=0; i < 64; i++) {
    LCDdrawchar((i % 14) * 6, (i/14) * 8, i + 64);
  }
  LCDdisplay();
  delay(2000);
  LCDclear();
  
  return 0;
}
Пример #6
0
int main(void){

	LCDInit(CLK, DIN, DC, CE,RST, contrast);

  	LCDclear();
	LCDshowLogo();
	struct sGENERAL person;
	delay_ms(1000);

	system("clear");
	printf("Deseja Sobrescrever os Dados ? S/N\n");
	unsigned int choose;
	do{choose = (int)getchar();}while(choose != 115 && choose != 83 && choose != 110 && choose != 78);
	getchar();
	if(choose == 115 || choose == 83){
		LCDDrawBitmap(profile);
		if(healthProfile(&person) == false){
			printf("Falha ao realizar o Cadastro!\n");
			return -1;
		}
	}else{
		system("clear");
		LCDDrawBitmap(profile);
		if(importData(&person)==false){
			printf("Falha ao importar dados!\n");
			return -1;
		}
	}
	LCDDrawBitmap(sensors);
	int raspDuino = serialOpen(SERIAL_PORT[1],BAUDS[1]);
	if(raspDuino == -1){
		printf("Houve um erro ao Abrir a porta Serial!\n");
		return -1;
	}

	serialFlush(raspDuino);
	
	GPIOExport(changeDisplay);	GPIODirection(changeDisplay,INPUT);
	GPIOExport(backLight);		GPIODirection(backLight,INPUT);
	GPIOExport(BL);				GPIODirection(BL,OUTPUT);
	GPIOWrite(BL,HIGH);

	uint8_t change_Layer = 0;

	while(1){
		if(GPIORead(changeDisplay) == HIGH){
			while(GPIORead(changeDisplay) == HIGH){}
			change_Layer++;
			if(change_Layer > 2)	change_Layer = 0;
		}
		if(GPIORead(backLight) == HIGH){
			while(GPIORead(backLight) == HIGH){}
			GPIOWrite(BL,!GPIORead(BL));
		}
		switch(change_Layer){
			case 0:
				lcdDisplayMain(raspDuino);
				break;
			case 1:
				lcdDisplayProfile(person);
				break;
			case 2:
				lcdDisplaySensors(raspDuino,person);
				break;
		}
		/*if(serialDataAvail(raspDuino)!=-1){ // Usar Threads 
			Sensors.BPM = (unsigned int)serialGetchar(raspDuino);
			Sensors.Temp = ((float)serialGetchar(raspDuino)*5/(1023))/0.01;
			
			Sensors.BPMState = healthState(person,Sensors.BPM);
			Sensors.TempState = isNormal(Sensors.Temp);
		}*/
	}
}