예제 #1
0
int show_net_info (int fd)
{
    struct ifaddrs * ifAddrStruct=NULL;
    void * tmpAddrPtr=NULL;
	char * s1="eth0";
	char buf[60];
	
	lcdPosition (fd, 0, 0); lcdPuts (fd, "Network Info:");
	
    getifaddrs(&ifAddrStruct);

    while (ifAddrStruct != NULL) {
        if (ifAddrStruct->ifa_addr->sa_family==AF_INET) { // check it is IP4
			sprintf(buf, "%s", ifAddrStruct->ifa_name);
			if(strcmp(buf, s1) == 0){
				// is a valid IP4 Address
				tmpAddrPtr=&((struct sockaddr_in *)ifAddrStruct->ifa_addr)->sin_addr;
				char addressBuffer[INET_ADDRSTRLEN];
				inet_ntop(AF_INET, tmpAddrPtr, addressBuffer, INET_ADDRSTRLEN);
				lcdPosition (fd, 0, 1);lcdPrintf (fd, "%s", addressBuffer) ; 
			}
        }
        ifAddrStruct=ifAddrStruct->ifa_next;
    }
    return 0;
}
예제 #2
0
int show_sys_info (int fd)
{
	FILE *fp;
    char temp_char[15]; //树莓派温度
    char Total[20]; //总内存量
    char Free[20]; //空闲内存量
	
	lcdPosition (fd, 0, 0); lcdPuts (fd, "System Info:");
	fp=fopen("/sys/class/thermal/thermal_zone0/temp","r"); //读取树莓派温度
	fgets(temp_char,9,fp);
	float Temp;
	Temp=atof(temp_char)/1000;
	lcdPosition (fd, 0, 1);lcdPrintf (fd, "%3.1fC", Temp) ; 
	fclose(fp);

	fp=fopen("/proc/meminfo","r"); //读取内存信息
	fgets(Total,19,fp);
	fgets(Total,4,fp);
	fgets(Free,9,fp);
	fgets(Free,19,fp);
	fgets(Free,4,fp);
	lcdPosition (fd, 7, 1);
	lcdPrintf (fd, "%3d/%3dMB", atoi(Free),atoi(Total)) ;
	fclose(fp);
}
예제 #3
0
static void pingPong (int lcd, int cols)
{
  static int position = 0 ;
  static int dir      = 0 ;

  if (dir == 0)		// Setup
  {
    dir = 1 ;
    lcdPosition (lcdHandle, 0, 3) ;
    lcdPutchar  (lcdHandle, '*') ;
    return ;
  }

  lcdPosition (lcdHandle, position, 3) ;
  lcdPutchar (lcdHandle, ' ') ;
  position += dir ;

  if (position == cols)
  {
    dir = -1 ;
    --position ;
  }
  
  if (position < 0)
  {
    dir = 1 ;
    ++position ;
  }

  lcdPosition (lcdHandle, position, 3) ;
  lcdPutchar  (lcdHandle, '#') ;
}
예제 #4
0
static long write_lcdout(lcdoutRecord *pstrout)
{
  struct Pin_Info *pin_info = pstrout->dpvt;

  int handle = pin_info->handle;
  int bits = pin_info->bits;

  lcdHome(handle);
  lcdClear(handle);

  int dirs = pstrout->dirs;

  if(dirs == 1)
  {
    char *val = pstrout->val;

    lcdPuts(handle, val);
//    lcdPrintf(handle, "%s", val);
  }
  else
  {
    double inpa = 0.0;
    double inpb = 0.0;
    double inpc = 0.0;
    double inpd = 0.0;

    long status;
    status = dbGetLink(&(pstrout->inpa), DBF_DOUBLE, &inpa, 0, 0);
    status = dbGetLink(&(pstrout->inpb), DBF_DOUBLE, &inpb, 0, 0);
    status = dbGetLink(&(pstrout->inpc), DBF_DOUBLE, &inpc, 0, 0);
    status = dbGetLink(&(pstrout->inpd), DBF_DOUBLE, &inpd, 0, 0);

    char *stra = pstrout->stra;
    char *strb = pstrout->strb;
    char *strc = pstrout->strc;
    char *strd = pstrout->strd;

    char *unia = pstrout->unia;
    char *unib = pstrout->unib;
    char *unic = pstrout->unic;
    char *unid = pstrout->unid;

    lcdPosition(handle, 0,0);
    lcdPrintf(handle, "%s%.2f%s", stra, inpa, unia);

    lcdPosition(handle, 0,1);
    lcdPrintf(handle, "%s%.2f%s", strb, inpb, unib);

    if(bits > 2)
    {
      lcdPosition(handle, 0,2);
      lcdPrintf(handle, "%s%.2f%s", strc, inpc, unic);

      lcdPosition(handle, 0,3);
      lcdPrintf(handle, "%s%.2f%s", strd, inpd, unid);
    }
  }

  return 0;
}
예제 #5
0
int main(void) {
	int lcd;
	//if(wiringPiSetupGpio() == -1) return EXIT_FAIL;
	lcd = lcd_start(); 
	setbuf(stdout,NULL);
	pinMode(LSW, INPUT);
	pinMode(RSW, INPUT);
	pinMode(TGSW, INPUT);
	pullUpDnControl(LSW, PUD_UP);
	pullUpDnControl(RSW, PUD_UP);
	pullUpDnControl(TGSW, PUD_UP);

	int curTab=0;
	int lsw,rsw,tgsw;
	int tabStat[4]={0};
	int occupied=0;
	char s[100];
	// ex) lsw == 0  => switch pushed..
	while(1) {
		delay(100);
		lsw = digitalRead(LSW);
		rsw = digitalRead(RSW);
		tgsw = digitalRead(TGSW);
		printf("lsw, rsw tgsw :%d %d %d\n",lsw,rsw,tgsw);
		if(!occupied) {
			if(lsw == 0) occupied = 1;
			else if(rsw == 0) occupied = 2;
			else if(tgsw == 0) occupied = 3;
		}
		else {
			if(lsw== 1 && occupied == 1) occupied = 0;
			else if(rsw == 1 && occupied == 2) occupied = 0;
			else if(tgsw == 1 && occupied == 3) occupied = 0;
		}

		if(occupied == 1 || occupied == 2) {
			if(occupied == 1) curTab = (curTab-1+MAXTAB)%MAXTAB;
			if(occupied == 2) curTab = (curTab+1)%MAXTAB;
			int ret = get_relay_value(curTab);
			tabStat[curTab] = ret;
			printf("ret:%d\n",ret);
			printf("lcd :%d\n",lcd);
			sprintf(s,"%dth tab is %3s%18s",curTab,ret?"ON":"OFF","");
			lcdPosition(lcd,0,0); 
			lcdPuts(lcd,s);
			delay(200);
		}
		else if(occupied==3) {
			set_relay_value(curTab,!tabStat[curTab]); 
			tabStat[curTab]= !tabStat[curTab];
			sprintf(s,"%dth tab is %3s%18s",curTab,
				tabStat[curTab]?"ON":"OFF","");
			lcdPosition(lcd,0,0); 
			lcdPuts(lcd,s);
			delay(200);
		}
	}
	return EXIT_SUCC;
}
예제 #6
0
int cls(int fd)
{
	lcdPosition (fd, 0, 0) ;
	lcdPuts (fd, "                ") ; //清空第一行
	lcdPosition (fd, 0, 1) ;
	lcdPuts (fd, "                ") ; //清空第二行
	return 0;
}
예제 #7
0
int main (int args, char *argv[])
{
    if (wiringPiSetup () == -1)
        exit (1) ;
    int fd = lcdInit (2, 16, 4, RS, EN, D0,D1,D2,D3,D0,D1,D2,D3) ;
    if (fd == -1)
    {
        printf ("lcdInit 1 failed\n") ;
        return 1 ;
    }
    sleep (1) ; //显示屏初始化
    
    lcdPosition (fd, 0, 0); lcdPuts (fd, "  Raspberry Pi!"); //启动信息
    sleep(1);
    
    if(argv[1])
    {
        lcdPosition (fd, 0, 0) ;
        lcdPuts (fd, "                ") ; //清空第一行
        lcdPosition (fd, 0, 0) ; lcdPuts (fd, argv[1]) ; //命令行参数显示至第一行
    } 
    
	int start,now;
    while(1)
    {
		show_date(fd);
		cls(fd);
		
		show_sys_info(fd);
		sleep(5);
		cls(fd);
		
		start = show_run_time(fd);
		while(now - start < 5){
			now = show_run_time(fd);
			sleep(1);
		}
		cls(fd);

		show_net_info(fd);
		sleep(5);
		cls(fd);
		
		show_client_count(fd);
		sleep(3);
		cls(fd);
		
		show_client_info(fd);
		cls(fd);
		
		show_temp(fd);
        sleep(5);
		cls(fd);
    }

    return 0;
    
}
예제 #8
0
void main(){
    wiringPiSetup();
    int fd = lcdInit(2, 16, 4, 6,5, 4,2,1,3, 0,0,0,0);

    lcdPosition(fd, 0, 0);
    lcdPuts(fd, "Steve Bertrand");
    lcdPosition(fd, 0, 1);
    lcdPuts(fd, "perlmonks.org");
    waitForEnter();
    lcdClear(fd);
}
예제 #9
0
void UART_1602_Init()
{
	uart3_init(9600);
	backlightOn() ;
	clearLCD();
    lcdPosition(0,0);
}
예제 #10
0
//prior.. wiringPiSetup() needed.
int lcd_start() {
	int lcd;                //Handle for LCD

	wiringPiSetup();
	//Initialise LCD(int rows, int cols, int bits, int rs, 
	//int enable, int d0, int d1, int d2, int d3, int d4, int d5, int d6, int d7)
	if (
			lcd =
			lcdInit (2, 16,4, LCD_RS, LCD_E ,LCD_D4 , 
				LCD_D5, LCD_D6,LCD_D7,0,0,0,0)
	   ){
		printf ("lcd init failed! \n");
		return -1 ;
	}
	lcdPosition(lcd,0,0);  //Position cursor on the first line in the first column
	lcdPuts(lcd, "*^^* HELLO THIS IS JOSS TAB CTRL");  
	/*
	char s[100];
	int i;
	   for(i=0; i<4; i++) {
	   int ret = get_relay_value(i);
	   printf("ret:%d\n",ret);
	   sprintf(s,"[%d]tab status :%d\n",i,ret);
	   lcdPosition(lcd,0,0); 
	   lcdPuts(lcd,s);
	   delay(2000);
	   }
	 */
	return lcd;
}
예제 #11
0
int main(){
if (wiringPiSetup() < 0)
{
    fprintf (stderr, "Unable to open serial device: %s\n", strerror (errno)) ;
    return 1 ;
}

int lcdFD;
lcdFD = lcdInit(2, 16, 4, RS, EN, D0, D1, D2, D3, D0, D1, D2, D3);
lcdPosition(lcdFD, 0,0);
lcdPrintf(lcdFD,"Waveshare");

lcdPosition(lcdFD, 0,1);
lcdPrintf(lcdFD, "Pi");

}
예제 #12
0
/*
*	Function: ioBoardLcdTest
* Description: be used to test Lcd interface on the board
*/
void ioBoardLcdTest(int bits, int rows, int cols)
{
    int lcdHandle;
    lcdHandle = lcdInit (rows, cols, 8, 21, 23, 0, 1, 2, 3, 4, 5, 6, 7) ;
    if(lcdHandle < 0)
    {
        printf("Lcd init failed!\n");
        return;
    }

    printf("LCD: the LCD will display character, please view!\n");

    lcdPosition (lcdHandle, 0, 0) ;
    lcdPuts (lcdHandle, "Lcd Test OK") ;
    lcdPosition (lcdHandle, 0, 1) ;
    lcdPuts (lcdHandle, "www.lemaker.org") ;
}
예제 #13
0
파일: lcd_senso.c 프로젝트: udo-hase/senso
int lcd_init(){
  wiringPiSetupSys () ;
  mcp23017Setup (AF_BASE, 0x20) ;

  adafruitLCDSetup (105) ; //setze Farbe

  lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Warmwasserproben") ;
  lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, " Daten Aufnahme ");
  sleep (2);
  lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Start --->      ") ;
  lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "Press Select... ");
  waitForEnter () ;
  lcdClear (lcdHandle) ;
  adafruitLCDSetup (103) ; //setze Farbe
  
  return(0);
}
예제 #14
0
파일: lcd_senso.c 프로젝트: udo-hase/senso
int lcd_print(int x,int y,int col,char *str){
		//wiringPiSetupSys () ;
		//mcp23017Setup (AF_BASE, 0x20) ;
		setBacklightColour (col);
		//str[16]=0x00; //ende des Strings bei Pos. 16 :)
		printf("x=%d;y=%d;str='%s'\n",x,y,str);
		lcdPosition (lcdHandle, x, y) ; lcdPuts (lcdHandle, str) ;
		return(0);
}
예제 #15
0
int main(void)
{
	int fd;
	int i;
	if (wiringPiSetup() == -1){
		exit(1);
	}

	fd = lcdInit(2,16,4, 2,3, 6,5,4,1,0,0,0,0); //see /usr/local/include/lcd.h
	printf("%d", fd);
	if (fd == -1){
		printf("lcdInit 1 failed\n") ;
		return 1;
	}
	sleep(1);

	lcdClear(fd);
	lcdPosition(fd, 0, 0); 
	lcdPuts(fd, "Welcom To--->");

	lcdPosition(fd, 0, 1); 
	lcdPuts(fd, "  sunfounder.com");

	sleep(1);
	lcdClear(fd);

	while(1){
		for(i=0;i<sizeof(Buf)-1;i++){
			lcdPosition(fd, i, 1);
			lcdPutchar(fd, *(Buf+i));
			delay(200);
		}
		lcdPosition(fd, 0, 1); 
		lcdClear(fd);
		sleep(0.5);
		for(i=0; i<16; i++){
			lcdPosition(fd, i, 0);
			lcdPutchar(fd, *(myBuf+i));
			delay(100);
		}
	}

	return 0;
}
int lcdPutBigSpecialChar(int col, int row, char charToPrint)
{
    int font[][9] = {
        //' '
        {
            254,
            254,
            254,
        },
        //':'
        {
            3,
            254,
            2,
        },
    };

    int index = -1;

    switch(charToPrint)
    {
    case ' ':
        index = 0;
        break;
    case ':':
        index = 1;
        break;
    }

    if(index >= 0)
    {
        // the number to screen at the position specified.
        lcdPosition(lcdHandle, col, row);  // LINE 1
        lcdPutchar (lcdHandle, font[index][0]);

        lcdPosition(lcdHandle, col, row + 1);   //LINE 2
        lcdPutchar (lcdHandle, font[index][1]);

        lcdPosition(lcdHandle, col, row + 2);   //LINE 3
        lcdPutchar (lcdHandle, font[index][2]);
    }

    return 0;
}
예제 #17
0
파일: lcd_ip2.c 프로젝트: tkrmnz/PiLCD
//-----------------------------------------------
void scrollMessage(int lcd, int line, int width)
{
  char buf[32];
  static int position = 0;
  strncpy (buf, &message[position], width);
  buf[width]=0;
  lcdPosition(lcd, 0,line);
  lcdPuts(lcd, buf);
  if(++position == (strlen(message)-width))
    position = 0;
}
예제 #18
0
int show_temp(fd){
	lcdPosition (fd, 0, 0); lcdPuts (fd, "Temperature:");
	int fdata = -1, ret;
	char *tmp1, tmp2[10], ch='t';
	char dev_name[100] = "/sys/devices/w1_bus_master1/28-000005e38995/w1_slave";
	long value;
	int integer, decimal;
	char buffer[100];
	int i,j;
	float temp;
	
	if ((fdata = open(dev_name, O_RDONLY)) < 0)
	{
		//perror("open error");
		lcdPosition (fd, 0, 1); lcdPrintf (fd, "open error");
		return 0;
	}

	ret = read(fdata, buffer, sizeof(buffer));
	if (ret < 0)
	{
		//perror("read error");
		lcdPosition (fd, 0, 1); lcdPrintf (fd, "read error");
		exit(1);
	}	


	tmp1 = strchr(buffer, ch);		
	sscanf(tmp1, "t=%s", tmp2);
	
	value = atoi(tmp2);	
	integer = value / 1000;
	decimal = value % 1000;
	
	//printf("temperature is %d.%d\n", integer, decimal);
	sprintf(buffer, "%d.%d", integer, decimal);
	temp = atof(buffer);
	lcdPosition (fd, 0, 1); lcdPrintf (fd, "%.1fC", temp);
	close(fdata);
	return 0;
}
예제 #19
0
int show_client_count(int fd)
{
	FILE *fp;
	fp = popen("hostapd_cli all_sta", "r");

	char mid;
	int i = 0;
	
	lcdPosition (fd, 0, 0); lcdPuts (fd, "Client Info:");

	while(!feof(fp))
	{
		mid = fgetc(fp);//从txt文本中读取一个字符赋值给mid
		if(mid == '\n')  //如果这个字符为换行符
			i++;                        
	}
	//printf("\n行數:\n",i);  
	lcdPosition (fd, 0, 1);lcdPrintf (fd, "Count: %d", (i-1)/8) ;	
	fclose(fp);

	return 0;
}
예제 #20
0
int show_date (int fd)
{
	struct tm *newtime;  
	char tmpbuf[128];  
	time_t timestamp; 
	int start,now;

	time(&timestamp);  
	newtime=localtime(&timestamp); 
	start = timestamp;

	strftime(tmpbuf, 128, "%Y-%m-%d %a", newtime); 
	lcdPosition (fd, 0, 0);lcdPrintf (fd, tmpbuf);
	while(now - start < 5){
		time(&timestamp);  
		newtime=localtime(&timestamp);
		now = timestamp;
		strftime(tmpbuf, 128, "%H:%M:%S", newtime); 
		lcdPosition (fd, 0, 1);lcdPrintf (fd, tmpbuf);
		sleep(1);
	}
}
예제 #21
0
파일: wpi.c 프로젝트: alepharchives/wpi
static ERL_NIF_TERM
lcd_position_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int handle, x, y;
    if (!enif_get_int(env, argv[0], &handle) ||
        !enif_get_int(env, argv[1], &x)      ||
        !enif_get_int(env, argv[2], &y))
    {
        return enif_make_badarg(env);
    }
    lcdPosition(handle, x, y);
    return atom_ok;
}
예제 #22
0
int show_client_info(int fd)
{
	FILE *fp;
	fp = fopen("/var/lib/misc/dnsmasq.leases","r");

	char buf[200];
	int i = 0;
	char * buf2;

	while(fgets(buf,sizeof(buf),fp) != NULL){
		//printf("%s\n", buf);
		cls(fd);

		buf2 = strtok(buf, " ");
		while(buf2 != NULL) 
		{
			//printf("%s\n", buf2);
			i++;
			if(i == 4)
			{
				lcdPosition (fd, 0, 0);lcdPrintf (fd, "%.16s", buf2);
				//printf("%s\n", s);
			}
			if(i == 3)
			{
				lcdPosition (fd, 0, 1);lcdPrintf (fd, "%.16s", buf2);
				//printf("%s\n", s);
			}
			buf2 = strtok(NULL, " ");
			//sleep(1);
		}
		i = 0;
		sleep(3);
	}
	fclose(fp);

	return 0;
}
예제 #23
0
int show_run_time (int fd)
{
	lcdPosition (fd, 0, 0); lcdPuts (fd, "Already Run:");
	FILE *fp;
	char buf[50];
	char *buf2;
	int timestamp;
	
	fp=fopen("/proc/uptime","r"); //读取内存信息
	
	fgets(buf,sizeof(buf)-1,fp);
	
	buf2 = strtok(buf, " ");
	timestamp = atoi(buf2);
	
	int day = timestamp / 86400;
	int hour = (timestamp % 86400) / 3600;
	int minute = (timestamp % 3600) / 60;
	int second = timestamp % 60;
	
	lcdPosition (fd, 0, 1); lcdPrintf (fd, "%dD %dh %dm %ds", day, hour, minute, second);
	fclose(fp);
	return timestamp;
}
예제 #24
0
파일: ifs.c 프로젝트: elseym/kitpi
int main(void) {
	char buf[1024];
	int i;

	int sck = socket(AF_INET, SOCK_DGRAM, 0);
	if(sck < 0) {
		perror("socket");
		return 1;
	}

	struct ifconf ifc;
	ifc.ifc_len = sizeof(buf);
	ifc.ifc_buf = buf;
	if(ioctl(sck, SIOCGIFCONF, &ifc) < 0) {
		perror("ioctl(SIOCGIFCONF)");
		return 1;
	}

	if (wiringPiSetup() == -1) {
		printf("wiringPiSetup failed!\nexiting.\n");
		return 1;
	}

	int lcd = lcdInit(2, 16, 4, 15, 16, 7, 0, 2, 3, 0, 0, 0, 0);
	delay(5);
	if (lcd == -1) {
		printf("lcdinit failed!\nexiting.\n");
		return 2;
	}

	lcdClear(lcd);
	delay(2);

	struct ifreq *ifr = ifc.ifc_req;
	int nInterfaces = ifc.ifc_len / sizeof(struct ifreq), y = 0;
	for(i = 0; i < nInterfaces; i++) {
		struct ifreq *item = &ifr[i];
		if (strcmp(item->ifr_name, "lo") == 0) continue;
		lcdPosition(lcd, 0, y++);
		delay(2);
		lcdPrintf(lcd, "%s: %s", item->ifr_name, inet_ntoa(((struct sockaddr_in *)&item->ifr_addr)->sin_addr));
		delay(5);
	}

  return 0;
}
예제 #25
0
void scrollMessage (int line, int width)
{
  char buf [32] ;
  static int position = 0 ;
  static int timer = 0 ;

  if (millis () < timer)
    return ;

  timer = millis () + 200 ;

  strncpy (buf, &message [position], width) ;
  buf [width] = 0 ;
  lcdPosition (lcdHandle, 0, line) ;
  lcdPuts     (lcdHandle, buf) ;

  if (++position == (strlen (message) - width))
    position = 0 ;
}
예제 #26
0
void scrollMessage(int row, int width, const char* message) {
  char buf[32] = {0};
  memset(buf, 0, sizeof(buf));

  static int position = 0;
  static int timer = 0;

  if(millis() < timer) {
    return;
  }

  timer = millis() + 200;

  strncpy(buf, &message[position], width);
  buf[width] = 0;

  lcdPosition(lcdHandle, 0, row);
  lcdPuts(lcdHandle, buf);

  if (++position == (strlen(message) - width)) {
    position = 0;
  }
}
예제 #27
0
int main (void) {
  FILE  *fp;
  int    fd;

  struct sysinfo sys_info;

  char uptimeInfo[15];
  char tempInfo[10];
  char cpuUsageInfo[10];
  char freeRamInfo[10];

  char  buf[10];
  int   buf_size = 10;
  float shiftfloat = (float)(1<<SI_LOAD_SHIFT);

  if (wiringPiSetupGpio() == -1)
    return 1 ;

  fd=lcdInit(2,16,4,RS,EN,DB4,DB5,DB6,DB7,0,0,0,0);
  
  pinMode(FAN, OUTPUT) ;
  
  while (1) {
    lcdClear(fd);

    if(sysinfo(&sys_info) != 0)
      printf("sysinfo Error\n");

    unsigned int days  = sys_info.uptime / 86400;
    unsigned int hours = (sys_info.uptime / 3600) - (days * 24);
    unsigned int mins  = (sys_info.uptime / 60) - (days * 1440) - (hours * 60);
    sprintf(uptimeInfo, "Run %dD%dH%dM", days, hours, mins);

    if (fp = fopen( "/sys/class/thermal/thermal_zone0/temp", "r")) {
      fgets(buf, buf_size, fp);
      fclose(fp);
    }
    else printf("fopen Error\n");

    unsigned int temperature = atoi(buf)/1000;
    sprintf(tempInfo, "%d'C",temperature);

    float cpuUsage = (((float)sys_info.loads[0]) / shiftfloat);
    sprintf(cpuUsageInfo, "Load%.2f", cpuUsage);

    unsigned long freeRam = sys_info.freeram / 1024 / 1024;
    sprintf(freeRamInfo, "RAM%ldMB", freeRam);

    lcdPosition(fd, 0,0); lcdPuts(fd,uptimeInfo);
    lcdPosition(fd,12,0); lcdPuts(fd,tempInfo);
    lcdPosition(fd, 0,1); lcdPuts(fd,cpuUsageInfo);
    lcdPosition(fd, 8,1); lcdPuts(fd,freeRamInfo);

    if(temperature > 50)
         digitalWrite(FAN, 1);
    else
         digitalWrite(FAN, 0);
         
    delay(1000);
  }
  return 0 ;
}
예제 #28
0
int main() {
	int n;
	int c=0;
	int lcd;
	char ch[128];
	int fd_port;				
        int p;					
	int spo2;			
	char read_buf[20];			

	fd_port = open_serial();		// 장치 초기화 및 열기
	
	if(wiringPiSetup()==-1)
	return 1;
	
	pinMode(LED1, OUTPUT);
	pinMode(LED2, OUTPUT);
	pinMode(LED3, OUTPUT);	

	lcd= lcdInit(2,16,4,6,5,4,0,2,3,0,0,0,0);
	sleep(1);
	
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"WElCOME!!");
		delay(1000);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"Your Finger Test");
		delay(1500);
		lcdClear(lcd);
		
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading   ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.. ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading... ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading..  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading... ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading.  ");
		delay(900);
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Loading..  ");
		delay(900);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"S");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"ST");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"STA");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"STAR");
		delay(700);
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"START");
		delay(1200);

	while (1)
	{
	 	n=read(fd_port,ch, sizeof(ch));
		p=atoi(ch);
		printf("문자->%s 변환->%d", ch,p);
		
		lcdClear(lcd);				
		lcdPosition(lcd,0,0);
		lcdPrintf(lcd,"Handle Test!");
		lcdPosition(lcd,0,1);
		lcdPrintf(lcd,"Pitch>%d",p);
		if(p<70) {
			digitalWrite(LED3,1);
			digitalWrite(LED2,0);
			digitalWrite(LED1,0);
		}
		else if(p<88){
			digitalWrite(LED3,0);
			digitalWrite(LED2,1);
			digitalWrite(LED1,0);		
		}
		else {
			c++;
			digitalWrite(LED3,0);
			digitalWrite(LED2,0);
			digitalWrite(LED1,1);
			if(c>5){
			lcdClear(lcd);
			lcdPosition(lcd,0,0);
			lcdPrintf(lcd,"Congratulation");
			lcdPosition(lcd,0,1);
			lcdPrintf(lcd,"Pitch>%d  Cure!!",p);
			break;
			}			
		}
//		delay(1);
	}


        close(fd_port);				// 장치 닫기

	return 0;
}
예제 #29
0
int main (int argc, char *argv[])
{
  int i ;
  int lcd ;
  int bits, rows, cols ;

  struct tm *t ;
  time_t tim ;

  char buf [32] ;

  if (argc != 4)
    return usage (argv [0]) ;

  printf ("Raspberry Pi LCD test\n") ;
  printf ("=====================\n") ;

  bits = atoi (argv [1]) ;
  cols = atoi (argv [2]) ;
  rows = atoi (argv [3]) ;

  if (!((rows == 1) || (rows == 2) || (rows == 4)))
  {
    fprintf (stderr, "%s: rows must be 1, 2 or 4\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  if (!((cols == 16) || (cols == 20)))
  {
    fprintf (stderr, "%s: cols must be 16 or 20\n", argv [0]) ;
    return EXIT_FAILURE ;
  }

  wiringPiSetup () ;

  if (bits == 4)
    lcdHandle = lcdInit (rows, cols, 4, 11,10, 4,5,6,7,0,0,0,0) ;
  else
    lcdHandle = lcdInit (rows, cols, 8, 11, 10, 0,1,2,3,4,5,6,7) ;

  if (lcdHandle < 0)
  {
    fprintf (stderr, "%s: lcdInit failed\n", argv [0]) ;
    return -1 ;
  }

  lcdPosition (lcdHandle, 0, 0) ; lcdPuts (lcdHandle, "Gordon Henderson") ;
  lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

  waitForEnter () ;

  if (rows > 1)
  {
    lcdPosition (lcdHandle, 0, 1) ; lcdPuts (lcdHandle, "  wiringpi.com  ") ;

    if (rows == 4)
    {
      lcdPosition (lcdHandle, 0, 2) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "=-") ;
      lcdPuts (lcdHandle, "=3") ;

      lcdPosition (lcdHandle, 0, 3) ;
      for (i = 0 ; i < ((cols - 1) / 2) ; ++i)
        lcdPuts (lcdHandle, "-=") ;
      lcdPuts (lcdHandle, "-4") ;
    }
  }

  waitForEnter () ;

  lcdCharDef  (lcdHandle, 2, newChar) ;

  lcdClear    (lcdHandle) ;
  lcdPosition (lcdHandle, 0, 0) ;
  lcdPuts     (lcdHandle, "User Char: ") ;
  lcdPutchar  (lcdHandle, 2) ;

  lcdCursor      (lcdHandle, TRUE) ;
  lcdCursorBlink (lcdHandle, TRUE) ;

  waitForEnter () ;

  lcdCursor      (lcdHandle, FALSE) ;
  lcdCursorBlink (lcdHandle, FALSE) ;
  lcdClear       (lcdHandle) ;

  for (;;)
  {
    scrollMessage (0, cols) ;
    
    if (rows == 1)
      continue ;

    tim = time (NULL) ;
    t = localtime (&tim) ;

    sprintf (buf, "%02d:%02d:%02d", t->tm_hour, t->tm_min, t->tm_sec) ;

    lcdPosition (lcdHandle, (cols - 8) / 2, 1) ;
    lcdPuts     (lcdHandle, buf) ;

    if (rows == 2)
      continue ;

    sprintf (buf, "%02d/%02d/%04d", t->tm_mday, t->tm_mon + 1, t->tm_year+1900) ;

    lcdPosition (lcdHandle, (cols - 10) / 2, 2) ;
    lcdPuts     (lcdHandle, buf) ;

    pingPong (lcd, cols) ;
  }

  return 0 ;
}
예제 #30
0
void throbberHandler(void) {
  char throb = (throbberEnabled == true)  ?  throbber[throbberIndex]  :  '?';
  throbberIndex = (throbberIndex + 1) % (sizeof(throbber) - 1);
  lcdPosition(0, 19);
  lcdWrite(throb, true);
}