Exemple #1
0
int zaDir10::dirlist()
{
	this->m_0.LoadImg("app/native/res/battery_empty.png",512,512);
	this->m_0.setposition(380,980-90);
	this->m_1.LoadImg("app/native/res/battery_1.png",512,512);
	this->m_1.setposition(380,980-90);
	this->m_2.LoadImg("app/native/res/battery_2.png",512,512);
	this->m_2.setposition(380,980-90);
	this->m_3.LoadImg("app/native/res/battery_3.png",512,512);
	this->m_3.setposition(380,980-90);
	this->m_4.LoadImg("app/native/res/battery_4.png",512,512);
	this->m_4.setposition(380,980-90);
	this->m_5.LoadImg("app/native/res/battery_5.png",512,512);
	this->m_5.setposition(380,980-90);
	this->m_6.LoadImg("app/native/res/battery_6.png",512,512);
	this->m_6.setposition(380,980-90);
	this->m_7.LoadImg("app/native/res/battery_7.png",512,512);
	this->m_7.setposition(380,980-90);
	this->m_8.LoadImg("app/native/res/battery_full.png",512,512);
	this->m_8.setposition(380,980-90);
	this->m_9.LoadImg("app/native/res/battery_power.png",512,512);
	this->m_9.setposition(380,980-90);

	m_bar1.LoadImg("app/native/res/bar.png",768,100);
	m_bar1.setposition(384,1230);

	m_bar2.LoadImg("app/native/res/bar.png",768,150);
	m_bar2.setposition(384,550);

	m_bar3.LoadImg("app/native/res/bar.png",768,100);
	m_bar3.setposition(384,410);

	m_font.init("/usr/fonts/font_repository/monotype/SlatePro.ttf",20);
	m_fonts.init("/usr/fonts/font_repository/monotype/SlatePro.ttf",10);
	ppopen();

	return 0;
}
Exemple #2
0
int zaDir10::render()
{
//	if (!m_dirty)
//		return 0;

	m_dirty = false;

	if (!m_font.font)
	{
		fprintf(stderr,"font err");
		return EXIT_FAILURE;
	}

	static int rep = 0;
	static int a =0;

	char *p;
	int mount = 0;

	p = this->getValue("\"StateOfCharge\":");
	if (p == NULL)
	{
		mount = 0;
	}
	else
	    mount = atoi(p);

	a ++ ;
	if ( a >  mount/12.f)
		a = 0;

    bool l_charge = true;
    p = this->getValue("\"ChargerName\":\"");
	if (p != NULL)
	{
		if (strstr(p,"NONE")!=NULL
		   || strstr(p,"PLUGGED")!=NULL)
		{
			l_charge = false;
			a = mount/12.5f;
		}
	}

	if (a == 0)  this->m_0.RunImg();
	if (a == 1)  this->m_1.RunImg();
	if (a == 2)  this->m_2.RunImg();
	if (a == 3)  this->m_3.RunImg();
	if (a == 4)  this->m_4.RunImg();
	if (a == 5)  this->m_5.RunImg();
	if (a == 6)  this->m_6.RunImg();
	if (a == 7)  this->m_7.RunImg();
	if (a == 8)  this->m_8.RunImg();
	if (a >= 9)  this->m_9.RunImg();
//	m_bar1.RunImg();
//	m_bar2.RunImg();
//	m_bar3.RunImg();

	char info[100];
	memset(info,0,100);

	int l_y = 100;

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);



	p = this->getValue("\"StateOfCharge\":");
	if (p != NULL)
	{
		sprintf(info,"%s%%",p);
	}

	int l_rate = atoi(p);

	p = this->getValue("AvailableEnergy:n:");
	if (p != NULL)
	{
		sprintf(info,"%s    %s mWH",info,p);
	}

	bbutil_render_text(m_font.font,"", 100.0f, 620-l_y);
	bbutil_render_text(m_font.font,info, 100.0f, 620-l_y);


	p = this->getValue("\"AverageCurrent\":"); //ChargeCurrent
	if (p != NULL)
	{
			sprintf(info,"%s mA",p);
	}

	int l_timeMin = 0;
	int l_cur = 0;
	int l_tofull = 0;

	if (info[0] == '-')
	{
	  glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
	  l_cur = atoi(p+1);
	  l_timeMin = 1800*l_rate*60/100/l_cur;
	  l_tofull = 0;
	}
	else
	{
		glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
		l_cur = atoi(p);
		if (l_cur != 0)
			l_timeMin = 1800*(100-l_rate)*60/100/l_cur;
		else
			l_timeMin = 24*60;
		l_tofull = 1;
	}
	bbutil_render_text(m_font.font,"", 100.0f, 620-l_y);
	bbutil_render_text(m_font.font,info,380.0f, 620-l_y);

	// charge time
	int l_hour, l_min;
	l_min = l_timeMin%60;
	if (l_timeMin > 59)
	{
		l_hour = (l_timeMin-l_min)/60;
		if (l_min == 0)
			sprintf(info," %d hour",l_hour);
		else
			sprintf(info,"%d h %d m",l_hour,l_min);
	}
	else
	{
		sprintf(info,"  %d min",l_min);
	}

	if (!l_tofull)
		strcat(info," to empty");
	else
		strcat(info," to full");
	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

	if (l_timeMin != 0)
	{
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info,200.0f, 500-l_y);
	}

	if ( !l_charge || (l_charge && rep < 3))
	{
		glColor4f(0.3f, 1.0f, 0.3f, 1.0f);

		p = this->getValue("\"BatteryName\":\"");
		if (p != NULL)
		{
			sprintf(info,"Name: %s",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 440-50-l_y);

		p = this->getValue("\"StateOfBattery\":\"");
		if (p != NULL)
		{
			sprintf(info,"State of Battery: %s",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 380-50-l_y);

		p = this->getValue("\"StateOfHealth\":");
		if (p != NULL)
		{
			sprintf(info,"Battery Health: %s%%",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 320-50-l_y);

		p = this->getValue("\"BatteryAlert\":\"");
		if (p != NULL)
		{
			sprintf(info,"Battery Alert: %s",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 260-50-l_y);


		p = this->getValue("\"Temperature\":");
		if (p != NULL)
		{
			sprintf(info,"CPU Temperature: %d",atoi(p)/100);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 200-50-l_y);
	}

	if (l_charge && rep >= 3)
	{
		glColor4f(1.0f, 1.0f, 0.0f, 1.0f);

		p = this->getValue("\"ChargerName\":\"");
		if (p != NULL)
		{
			sprintf(info,"Charger: %s",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 440-50-l_y);

		p = this->getValue("\"ChargerParams\":[{\"ChargerStatus\":\"");
		if (p != NULL)
		{
			sprintf(info,"Charger State: %s",p);
		}
		bbutil_render_text(m_font.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 380-50-l_y);

		p = this->getValue("\"AverageCurrent\":"); //ChargeCurrent
		if (p != NULL)
		{
			sprintf(info,"Average Current: %s mA",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 320-50-l_y);

		p = this->getValue("\"BatteryVoltage\":");
		if (p != NULL)
		{
			sprintf(info,"Battery Voltage: %s mV",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 260-50-l_y);

		info[0] = 0;
		p = this->getValue("\"CycleCount\":");
		if (p != NULL)
		{
			sprintf(info,"Charge Count: %s",p);
		}
		bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
		bbutil_render_text(m_fonts.font,info, 80.0f, 200-50-l_y);

//		info[0] = 0;
//		p = this->getValue("\"TimeToFull\":");
//		if (p != NULL)
//		{
//			sprintf(info,"Time to Full: %s min",p);
//		}
//		bbutil_render_text(m_fonts.font,info, 80.0f, 200-50);
//
//		info[0] = 0;
//		p = this->getValue("\"Temperature\":");
//		if (p != NULL)
//		{
//			sprintf(info,"CPU Temperature: %s",p);
//		}
//		bbutil_render_text(m_fonts.font,info, 60.0f, 140);
	}

	if (l_charge)
	{
		rep ++ ;
		if( rep > 6)
			rep = 0;
	}
	else
		rep = 0;


	ppopen();

    struct   tm     *ptm;
    time_t ts;
    ts   =   time(NULL);
    ptm   =   localtime(&ts);
    char m_nowtime[40];
    sprintf(m_nowtime,"%04d/%02d/%02d %02d:%02d:%02d",
  		  ptm->tm_year+1900,
  		  ptm->tm_mon+1,
  		  ptm->tm_mday,
  		  ptm->tm_hour,
  		  ptm->tm_min,
  		  ptm->tm_sec );

	glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	bbutil_render_text(m_fonts.font,"", 100.0f, 620-l_y);
	bbutil_render_text(m_fonts.font, m_nowtime, 150.0f,1280-70.0f);
	usleep(1000000);
	return 0 ;
}
Exemple #3
0
void test_COM1(void)
{
	char pressKey, *dev = "/dev/ttyS0", *s=NULL, *st;
	char *lf = strcat(dirname(gppath(getpid())), "/ppp.log");
	int l, m, n=0;
	FILE *com, *gprs, *pl;
	pthread_t ti, to;
	pid_t gid = 0;

	va_list ap;

	while (1)
	{
		printf("Press 'o' try to open COM1\n");
		printf("Press 'c' try to close COM1\n");
		printf("Press 'e' exit COM1 test\n");

		pressKey=getchar();

		printf("\n");

		switch (pressKey)
		{
			case 'o':
				com = fopen_sp(dev, B115200, 8, 0, 1, TTYS_TEXT_MODE);
				if (com != NULL)
					printf("Open COM1 OK! Pointer of COM: %p(address: %p)\n", com, &com);
				else
				{
					printf("Open COM1 error!\n");
					break;					
				}

				ti=to=0;
				
				if (pthread_create(&ti, NULL, send_to_com, (void *)com) != 0)
				{
					printf("Create send thread fail!\n");
					break;
				}
				if (pthread_create(&to, NULL, read_from_com, (void *)com) != 0)
				{
					printf("Create read thread fail!\n");
					break;
				}
				pthread_join(ti, NULL);

				char *arg[]={
					"pppd",
					"/dev/ttyS0",			//Serial device is ttyS0(COM1)
					"115200",				//Buad in 115200
					"modem",				//Waitting for CD signal
					"nocrtscts",			//Disabled hardware RTS & CTS
					"nodetach",				//Disable detach from terminal.
					"usepeerdns",			//Ask the peers for up to 2 DNS
					"noipdefault",			//Local ip supply by peers
					"defaultroute",			//Using the peers as gateway
					"user", "\"cmnet\"",
					"0.0.0.0:0.0.0.0",		//local ip:remote ip
					"ipcp-accept-local",	//Accept peer supply local IP
					"noccp",				//Disable CCP(Compression Control Protocol)
					"persist",				//hold connection
					"lcp-echo-interval", "5",	//Send LCP echo frame every 30 seconds
					"lcp-echo-failure", "5",	//Retry times when LCP echo fail
					"chap-interval", "5",		//rechallenge the peer every 5 seconds
					NULL};

				gprs = ppopen(&gid, "pppd", arg, "rn");
				if (NULL == gprs)
				{
					printf("Call pppd fail!\n");
					break;
				}
				pl = fopen(lf, "a");
				if (NULL == pl)
				{
					printf("Open log file fail!\n");
					break;
				}

				l = 0;
				time_t t;
				for (;;)
				{
					while (getline(&s, &n, gprs)<=0);
				
					t = time(NULL);
					st = sctime(&t);

					fprintf(pl, "%s>%s", st, s);
					fflush(pl);
					printf("%s>%s", st, s);

					if ((strstr(s, "terminated") != NULL) || (strstr(s, "failed") != NULL))
					{
						l = -1;
						printf("PPPD fail!\n");
						fprintf(pl, "\n%s>---PPPD fail!---\n", st);
						break;
					}

									switch (l)
					{
						case 0:
							if (strstr(s, PPPD_LOCAL_IP_STR) != NULL)
							{
								l++;
								printf("%d>>Got local IP\n", l);
							}
							break;
						case 1:
							if (strstr(s, PPPD_REMOTE_IP_STR) != NULL)
							{
								l++;
								printf("%d>>Got remote IP\n", l);
							}
							break;
						case 2:
							if (strstr(s, PPPD_PRIMARY_DNS_STR) != NULL)
							{
								l++;
								printf("%d>>Got primary dns\n", l);
							}
							break;
						case 3:
							if (strstr(s, PPPD_SECONDARY_DNS_STR) != NULL)
							{
								l++;
								printf("%d>>Got secondary dns\n", l);
							}
							break;
					}
					if (l == 4) 
					{
						printf("Got all str!\n");
						// break;
					}
				}

				if (l == -1)
				{
					printf("Close pipe file!\n");
					fclose(gprs);
					printf("Kill pppd! PID: %d\n", gid);
					kill(gid, SIGKILL);
					waitpid(gid, NULL, 0);
				}
				break;
			case 'c':
				fclose_sp(com);
		}
		if (pressKey=='e')
		{
			if (NULL != gprs) fclose(gprs);
			if (0 != gid)
			{
				kill(gid, SIGKILL);
				waitpid(gid, NULL, 0);
			}
			break;
		}
	}
}