示例#1
0
文件: lcd.c 项目: alivehex/gpior
// test only
void LCD_test() {
	int i;
	
	TRACE_DEBUG("LCD example");
	LCD_init();
	LCD_draw_string("!\"#$%&'()*+,-./");
	LCD_draw_string("0123456789:;<=>?@");
	for(i = 0; i < 22; i ++) {
		LCD_draw_symble(i);
	}
	LCD_clear();
	LCD_draw_string("ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`");
	LCD_draw_string("abcdefghijklmnopqrstuvwxyz{|}~");
	LCD_clear();
	for(i = 0; i < 27; i ++) {
		LCD_draw_icon(i);
	}
}
int main (void)
{
int loop=0, werbung=0, tnet=-1,blit=0,cnum=-1,tv,wflag=1,runtime=0, mut=0, vol=0, tmin=15;
char tstr[40],zapchan[40],msgchan[40];
FILE *fh1;
time_t t1,t2,t3,t4;

	printf("Blockad Version %s\n",P_VERSION);

	if (!ReadConf())
	{
		printf("Blockad <Configuration failed>\n");
	}
	else
	{
		if((fh1=fopen(FLG_FILE,"r"))!=NULL)
		{
			if(fgets(zapchan, sizeof(zapchan), fh1))
			{
				Trim_String(zapchan);
				if(fgets(tstr, sizeof(tstr), fh1))
				{
					sscanf(tstr,"%d",&cnum);
					if(fgets(tstr, sizeof(tstr), fh1))
					{
						sscanf(tstr,"%d",&rezap);
						if(fgets(msgchan, sizeof(msgchan), fh1))
						{
							Trim_String(msgchan);
						}
						else
						{
							sprintf(msgchan,"Unbekannt");
						}
						if(fgets(tstr, sizeof(tstr), fh1))
						{
							if(sscanf(tstr,"%d",&vol)==1)
							{
								if(volume)
								{
									if(fgets(tstr, sizeof(tstr), fh1))
									{
										if(sscanf(tstr,"%d",&mut)!=1)
										{
											mut=0;
										}
									}
								}
							}
						}
						if(fgets(tstr, sizeof(tstr), fh1))
						{
							if(sscanf(tstr,"%d",&tmin)!=1)
							{
								tmin=15;
							}
						}
					}
				}
				else
				{
					rezap=420;
				}	
				loop=1;
				if(cnum<0)
				{
					inet=-1;
				}
			}
			fclose(fh1);
		}
		time(&t1);
		t4=t3=t1;
#ifdef HAVE_DBOX_HARDWARE
		LCD_Init();
#endif
		if(inet>=0)
		{
			if(Open_Socket()==-1)
			{
				inet=-1;
			}
		}
		while(loop)
		{
			time(&t2);
			if(inet>=0)
			{
				tnet=-1;
				if(inet>=0)
				{
					tv=Check_Socket(cnum,&werbung);
					if(!werbung)
					{
						if((t2-t4)>tmin)
						{
							Do_Rezap(zapchan,vol,mut);
							loop=0;
						}
					}
					else
					{
						t4=t2;
					}
					if(tv>=0)
					{
						tnet=inet;
					}
				}
				inet=tnet;
			}
			if(loop)
			{
				if((fh1=fopen(FLG_FILE,"r"))!=NULL)
				{
					fclose(fh1);
					if(inet>=0)
					{
						if(wflag)
						{
							fh1=fopen(STS_FILE,"w");
							fprintf(fh1,"%s\n",msgchan);
							fprintf(fh1,"Auto\n");
							fclose(fh1);
							wflag=0;
						}
						if(t3!=t2)
						{
							sprintf(tstr,"%s",(blit^=1)?"   ":" WZ");
#ifdef HAVE_DBOX_HARDWARE
							LCD_Read();
							LCD_draw_string(97, 13, tstr);
							LCD_update();
#endif
							t3=t2;
						}
						sleep(1);
					}
					else
					{
						runtime=t2-t1;
						if(runtime>rezap)
						{
							Do_Rezap(zapchan,vol,mut);
							loop=0;
						}
						else
						{
							if(t3!=t2)
							{
								runtime=rezap-runtime;
								sprintf(tstr,"%2d:%02d",runtime/60,runtime%60);
								fh1=fopen(STS_FILE,"w");
								fprintf(fh1,"%s\n",msgchan);
								fprintf(fh1,"%s\n",tstr);
								fclose(fh1);
#ifdef HAVE_DBOX_HARDWARE
								LCD_Read();
								LCD_draw_string(81, 13, tstr);
								LCD_update();
#endif
								sleep(1);
								t3=t2;
							}
						}
					}
				}
				else
				{
					loop=0;
				}
			}
		}
	}
#ifdef HAVE_DBOX_HARDWARE
	LCD_Close();
#endif
	if(inet>=0)
	{
		Close_Socket();
	}
	sprintf(tstr,"cd /tmp\nrm blockads.*");
	system(tstr);

	return 0;
}