Example #1
0
/*--------------------------------------------------------------------------------------------------
  Name         :  LCD_drawBorder
  Description  :  Draws rectangle border on the display
  Argument(s)  :  None
  Return value :  None
--------------------------------------------------------------------------------------------------*/
void LCD_drawBorder (void )
{
	unsigned char i, j;  
	    
	for(i=0; i<7; i++)
	{
		LCD_gotoXY (0,i);
			
		for(j=0; j<84; j++)
		{
			if(j == 0 || j == 83) {
				lcd_buffer[cursor_row][cursor_col + j] |= 0xff;
			} else if(i == 0) {
				lcd_buffer[cursor_row][cursor_col + j] |= 0x08;
				//LCD_writeData (0x08);		// row 0 is having only 5 bits (not 8)
			} else if(i == 6) {
				lcd_buffer[cursor_row][cursor_col + j] |= 0x04;
				//LCD_writeData (0x04);		// row 6 is having only 3 bits (not 8)
			} else {
				lcd_buffer[cursor_row][cursor_col + j] |= 0x00;
				//LCD_writeData (0x00);
			}
		}
	}

	LCD_update();
}	
/*********************************************************************
 * @fn      Board_writeString
 *
 * @brief   Write a string on the LCD display.
 *
 * @param   str - string to print
 * @param   line - line (page) to write (0-7)
 *
 * @return  void
 */
void Board_writeString(char *str, uint8_t line)
{
  if (lcdHandle != NULL)
  {
    LCD_bufferClearPage(lcdHandle, 0, (LCD_Page)line);
    LCD_bufferPrintString(lcdHandle, 0, str, 0, (LCD_Page)line);
    LCD_update(lcdHandle, 0);
  }
}
int show_progress( void *clientp, double dltotal, double dlnow, double ultotal, double ulnow )
{
#if 0
	char prstr[50];
	
	if(dltotal<spdsize[speed])
	{
		return 0;
	}
	
	LCD_draw_rectangle (7,7,111,17, LCD_PIXEL_ON,LCD_PIXEL_OFF);
	LCD_draw_fill_rect (7,7,(int)((dlnow/dltotal)*111.0),17,LCD_PIXEL_ON);
	sprintf(prstr,"%d%%",(int)(dlnow*100.0/dltotal));
	LCD_draw_Istring(45, 9, prstr);
	LCD_update();
#endif
	return 0;
}
/*********************************************************************
 * @fn      Board_openLCD
 *
 * @brief   Open LCD peripheral on SRF06EB.
 *
 * @param   none
 *
 * @return  void
 */
void Board_openLCD(void)
{
#ifdef TI_DRIVERS_LCD_INCLUDED
  //Enable the 3V3 domain for the LCD
  hLCDPins = PIN_open(&LCDPinState, LCDPinTable);
    
  LCD_Params lcdParams;
  
  LCD_Params_init(&lcdParams);
  
  // Open LCD peripheral
  lcdHandle = LCD_open(&lcdBuffers[0], 1, &lcdParams);
  
  if ( lcdHandle )
  {
    LCD_bufferClear(lcdHandle, 0);
    LCD_update(lcdHandle, 0);
  }
#endif
}
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;
}
Example #6
0
int main(void) {
_delay_ms(100);
	// IO port initialisation
	port_direction_init();
	
	centre.x = ((float)LCD_WIDTH-1.0)/(float)2.0;	//the X origin offset
	centre.y = ((float)LCD_HEIGHT-1.0)/(float)2.0;	//the Y origin offset
	
	//set up the compass serial port
	compass_init();
	LCD_init();
	SREG |= 0x80;	//Set the global interrupt enable bit in the Status Register SREG, see section 6.3.1 of the datasheet.
	LCD_clear();
	
	//north
	fixedPointLine northline1;
	northline1.start.x = fip(centre.x);
	northline1.start.y = fip(0);
	northline1.end.x = fip(37);
	northline1.end.y = fip(centre.y);
	fixedPointLine northline2;
	northline2.start.x = fip(centre.x);
	northline2.start.y = fip(0);
	northline2.end.x = fip(46);
	northline2.end.y = fip(centre.y);
	//north small
	fixedPointLine northsmallline1;
	northsmallline1.start.x = fip(41.5);
	northsmallline1.start.y = fip(15);
	northsmallline1.end.x = fip(46);
	northsmallline1.end.y = fip(23.5);
	fixedPointLine northsmallline2;
	northsmallline2.start.x = fip(41.5);
	northsmallline2.start.y = fip(15);
	northsmallline2.end.x = fip(37);
	northsmallline2.end.y = fip(23.5);
	//horizontal line
	fixedPointLine horizontalline;
	horizontalline.start.x = fip(30);//37;
	horizontalline.start.y = fip(centre.y);
	horizontalline.end.x = fip(53);//46;
	horizontalline.end.y = fip(centre.y);
	//south
	fixedPointLine southline1;
	southline1.start.x = fip(centre.x);
	southline1.start.y = fip(47);
	southline1.end.x = fip(46);
	southline1.end.y = fip(centre.y);
	fixedPointLine southline2;
	southline2.start.x = fip(centre.x);
	southline2.start.y = fip(47);
	southline2.end.x = fip(37);
	southline2.end.y = fip(centre.y);
	
	fixedPointPolygon northTriangle;
	northTriangle.num_vertices = 4;
	fixedPointCoord vertices[northTriangle.num_vertices];
	vertices[0].x = fip(centre.x); //point
	vertices[0].y = fip(0);
	vertices[1].x = fip(46); //bottom right
	vertices[1].y = fip(centre.y);
	vertices[2].x = fip(centre.x); //middle arrow
	vertices[2].y = fip(19);
	vertices[3].x = fip(37); //bottom left
	vertices[3].y = fip(centre.y);
	northTriangle.vertices = vertices; //vertices points to the start of the array
	
	fixedPointPolygon rotatedPoly;
	fixedPointEdgeTable globalEdgeTable;
	while (1) {
	//TODO: use a timed interrupt to send the LCD update
	//TODO: stop the LCD update during the compass update (MAYBE??)
	//TODO: name public and private headers
	//TODO: separate out LCD functions
		updated = 0;
		compass_transmit((char) 0x12);
		while (!updated) {
		}
		LCD_clear_buff();
		
		//north
		//draw_line_l(rotateLine(northline1, angle));
		//draw_line_l(rotateLine(northline2, angle));
		//north small
		/*draw_line_l(rotateLine(northsmallline1, angle));
		draw_line_l(rotateLine(northsmallline2, angle));*/
		//horizontal line
		//draw_line_l(rotateLine(horizontalline, angle));
		//south
		draw_line_l(rotateLine(southline1, angle));
		
		if (rotatePolygon(&northTriangle, angle, &rotatedPoly)) {
			if (initialise_global_edge_table(&rotatedPoly, &globalEdgeTable)) {
			//remember a logical check that after initialisation, there are at least 2 edges!
				draw_polygon(&globalEdgeTable);
				free(globalEdgeTable.edges);
				globalEdgeTable.edges = NULL;
				draw_line_l(rotateLine(southline2, angle));
			}
			free(rotatedPoly.vertices);
			rotatedPoly.vertices = NULL;
		}
		
		//steps:
		//rotate polygon - check
		//http://www.cs.rit.edu/~icss571/filling/how_to.html
		//initializing should return a bool for successful or not (cos of mallocing)
		//initialize edges
		//initializing global edge table (sorted) (size should be total number of edges)
		//initializing parity
		//initializing the scan-line
		//initializing active edge table (size should be number of edges)
		//fill polygon
		//aim for a draw_scene function (pass an array of polygons and an angle)
		//  if N is 2 for a polygon, cast its array to a line

		LCD_update();

 	}
}
Example #7
0
void LCD_clear() {
	LCD_clear_buff();
	LCD_update();
}
int HTTP_downloadFile(char *URL, char *downloadTarget, int showprogress, int tmo, int ctimo, int repeats)
{
	CURLcode res = -1;
	char *surl=URL;
	int i=strlen(URL),y;

	for(y=0; y<4; y++) // change HTTP to lower case
		URL[y]=tolower(URL[y]);

	while(i)
	{
		if(URL[i] <= ' ')
		{
			URL[i]=0;
		}
		--i;
	}

	FILE *tmpFile = fopen(downloadTarget, "wb");
	if (tmpFile) {
		CURL *curl = curl_easy_init();
		if(curl)
		{
			curl_easy_setopt(curl, CURLOPT_VERBOSE, 0L);
			curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 1L/*(showprogress)?0:1*/);
			curl_easy_setopt(curl, CURLOPT_NOSIGNAL, 1L);
			curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
			curl_easy_setopt(curl, CURLOPT_WRITEDATA, tmpFile);
			curl_easy_setopt(curl, CURLOPT_FAILONERROR, 1L);
			curl_easy_setopt(curl, CURLOPT_URL, surl);
			curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, (ctimo)?ctimo:(30+tmo*45));
			curl_easy_setopt(curl, CURLOPT_TIMEOUT, (tmo+1)*60);
			curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
			if(proxyadress && strstr(URL,"//127.0.0.1/")==NULL && strstr(URL,"//localhost/")==NULL)
			{
				curl_easy_setopt(curl, CURLOPT_PROXY, proxyadress);
				curl_easy_setopt(curl, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
			}
			else
			{
				curl_easy_setopt(curl, CURLOPT_PROXY, (char *)0);
			}
			if(proxyuserpwd && strstr(URL,"//127.0.0.1/")==NULL && strstr(URL,"//localhost/")==NULL)
			{
				curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, proxyuserpwd);
			}

			res = curl_easy_perform(curl);
			if (res != CURLE_OK){
				printf("[%s] curl_easy_perform() failed:%s\n",__func__, curl_easy_strerror(res));
			}
			curl_easy_cleanup(curl);
		}
		fclose(tmpFile);
	}

	if(res)
	{
		remove(downloadTarget);
	}

#if 0
	if(showprogress)
	{
		LCD_draw_fill_rect (6,6,112,18,LCD_PIXEL_OFF);
		LCD_update();
	}
#endif
	return res;
}