Ejemplo n.º 1
0
/**
 @brief main() Initialize user task
 @return void
*/
MEMSPACE 
void user_init(void)
{
	int i;
	os_event_t *handlerQueue;
    char time[20];
	int ret;
	uint16_t *ptr;
	uint32_t time1,time2;
	uint32_t ID;
	extern uint16_t tft_ID;
	double ang;

	os_delay_us(200000L);	// Power Up dalay - lets power supplies and devices settle

	// Configure the UART
	uart_init(BIT_RATE_115200,BIT_RATE_115200);

	DEBUG_PRINTF("\n");
	DEBUG_PRINTF("System init...\n");

	DEBUG_PRINTF("HSPI init...\n");
	hspi_init(1,0);

	DEBUG_PRINTF("Timers init...\n");
	init_timers();

	DEBUG_PRINTF("SD Card init...\n");
	mmc_init(1);

// CPU
// 160MHZ
//  REG_SET_BIT(0x3ff00014, BIT(0));
// 80MHZ
//   REG_CLR_BIT(0x3ff00014, BIT(0));


	DEBUG_PRINTF("Display Init\n");
	// Initialize TFT
	master = tft_init();
	ID = tft_ID;
	// Set master rotation
	tft_setRotation(1);

	/* Setup main status window */
	tft_window_init(winstats,0,0, master->w * 7 / 10, master->h/2);

	tft_setpos(winstats, 0,0);
	tft_set_font(winstats,5);
	tft_font_var(winstats);
	tft_setTextColor(winstats, ILI9341_RED,0);
	tft_printf(winstats, "DISP ID: %04lx\n", ID);
	ip_xpos = winstats->x;
	ip_ypos = winstats->y;
	tft_printf(winstats, "\n");
	tft_setTextColor(winstats, ILI9341_WHITE,0);
#if ILI9341_DEBUG & 1
	DEBUG_PRINTF("\nDisplay ID=%08lx\n",ID);
#endif
	tft_font_fixed(winstats);

	// Save last display offset of the status update line - used in the demo task
	xpos = winstats->x;
	ypos = winstats->y;

	/* Setup cube/wireframe demo window */
	tft_window_init(windemo,winstats->w,0, master->w - winstats->w, master->h/2);

// Cube points were defined with sides of 1.0 
// We want a scale of +/- w/2
	if(windemo->w < windemo->h) 
		dscale_max = windemo->w/2;
	else
		dscale_max = windemo->h/2;

	dscale = dscale_max;
	dscale_inc = dscale_max / 100;

/* Setup second window for window testing*/
	tft_window_init(wintest,0,master->h/2, master->w/2, master->h/2);
	tft_setTextColor(wintest, ILI9341_WHITE,ILI9341_NAVY);
    tft_fillWin(wintest, wintest->bg);
	tft_set_font(wintest,3);
	//tft_font_var(wintest);

	// write some text
	tft_setpos(wintest, 0,0);
	tft_printf(wintest, "Test1\nTest2\nTest3");

	/* Test demo area window */
	tft_window_init(wintestdemo,master->w/2,master->h/2,master->w/2, master->h/2);
	tft_setTextColor(wintestdemo, ILI9341_WHITE,0);
    tft_fillWin(wintestdemo, wintestdemo->bg);
	tft_set_font(wintestdemo,3);
	tft_font_var(wintestdemo);

#if ILI9341_DEBUG & 1
	DEBUG_PRINTF("Test Display Read\n");
	read_tests(wintest);
#endif

/* Draw cube in the second window as a test */
#if defined(WIRECUBE) && !defined(EARTH)
	DEBUG_PRINTF("Draw Cube\n");
// Cube points were defined with sides of 1.0 
// We want a scale of +/- w/2
	double tscale_max;
	if(wintestdemo->w < wintestdemo->h) 
		tscale_max = wintestdemo->w/2;
	else
		tscale_max = wintestdemo->h/2;
	ang = 45.0;
	V.x = ang;
	V.y = ang;
	V.z = ang;
	wire_draw(wintestdemo, cube_points, cube_edges, &V, wintestdemo->w/2, wintestdemo->h/2, tscale_max, ILI9341_RED);
#endif

#ifdef EARTH
	DEBUG_PRINTF("Draw Earth\n");
// Earth points were defined with radius of 0.5, diameter of 1.0
// We want a scale of +/- w/2
	double tscale_max;
	if(wintestdemo->w < wintestdemo->h) 
		tscale_max = wintestdemo->w;
	else
		tscale_max = wintestdemo->h;
	V.x = -90;
	V.y = -90;
	V.z = -90;
	// draw earth
	//time1 = system_get_time();
// Earth points were defined over with a scale of -0.5/+0.5 scale - so scale must be 1 or less
	wire_draw(wintestdemo, earth_data, NULL, &V, wintestdemo->w/2, wintestdemo->h/2, tscale_max, wintestdemo->fg);
	//time2 = system_get_time();
#endif

	wdt_reset();

	DEBUG_PRINTF("User Task\n");
	// Set up a timer to send the message to User Task
	os_timer_disarm(&UserTimerHandler);
	os_timer_setfn(&UserTimerHandler,(os_timer_func_t *)sendMsgToUserTask,(void *)0);
	os_timer_arm(&UserTimerHandler, USER_TASK_DELAY_TIMER, 1);
	// Setup the user task
	system_os_task(UserTask, UserTaskPrio, UserTaskQueue, UserTaskQueueLen);

#ifdef TELNET_SERIAL
	DEBUG_PRINTF("Setup Network Serial Bridge\n");
	bridge_task_init(23);
#endif

#ifdef NETWORK_TEST
	DEBUG_PRINTF("Setup Network TFT DIsplay Client\n");
	setup_networking(TCP_PORT);
#endif

#if 0
	// Misc Task init - testing only
	system_os_task(HighTask, HighTaskPrio, HighTaskQueue, HighTaskQueueLen);
	system_os_task(NormalTask, NormalTaskPrio, NormalTaskQueue, NormalTaskQueueLen);
	system_os_task(IdleTask, IdleTaskPrio, IdleTaskQueue, IdleTaskQueueLen);
	system_os_post(IdleTaskPrio, 0, 0);
#endif
	DEBUG_PRINTF("Done Setup\n");
    DEBUG_PRINTF("Heap Size(%d) bytes\n" , system_get_free_heap_size());

	// disable os_printf at this time
	system_set_os_print(0);

    system_init_done_cb(init_done_cb);
}
Ejemplo n.º 2
0
setup_windows(int rotation, int debug)
{
	int16_t x,y,w,h;
	uint32_t ID;
	extern uint16_t tft_ID;
	ID = tft_ID;

	// Set master rotation
	tft_setRotation(rotation);
	tft_setTextColor(master, ILI9341_WHITE,ILI9341_BLUE);
	tft_fillWin(master, master->bg);

#if ILI9341_DEBUG & 1
		if(debug)
			printf("\nDisplay ID=%08lx\n",ID);
#endif

	// Message window setup
#ifdef EARTH
		w = master->w * 7 / 10;
#else
		w = master->w;
#endif
		// TOP
#ifdef DEBUG_STATS
		tft_window_init(wintop,0,0, w, font_H(0)*4);
		tft_setTextColor(wintop, ILI9341_WHITE, ILI9341_NAVY);
#else
		tft_window_init(wintop,0,0, w, font_H(2)*2);
		tft_setTextColor(wintop, ILI9341_WHITE, tft_RGBto565(0,64,255));
#endif
	tft_set_font(wintop,0);
	tft_font_var(wintop);
	tft_fillWin(wintop, wintop->bg);
	tft_set_textpos(wintop, 0,0);

#ifdef EARTH
		tft_window_init(winearth,w,0, master->w - w + 1, wintop->h);
		tft_setTextColor(winearth, ILI9341_WHITE, ILI9341_NAVY);
		tft_fillWin(winearth, winearth->bg);
#endif

	// BOTOM
	// TIME,DATE
	tft_window_init(winbottom, 0, master->h - 1 - font_H(2)*2, 
		master->w, font_H(2)*2);
	if(master->rotation & 1)
		tft_set_font(winbottom,2);
	else
		tft_set_font(winbottom,1);
	tft_font_var(winbottom);
	tft_setTextColor(winbottom, 0, tft_RGBto565(0,255,0));
	tft_fillWin(winbottom, winbottom->bg);
	tft_set_textpos(winbottom, 0,0);

	// Message window setup
#ifdef WIRECUBE
		w = master->w * 7 / 10;
#else
		w = master->w;
#endif

	// MSG
	tft_window_init(winmsg,0,wintop->h,
			w, master->h - (wintop->h + winbottom->h));

	tft_setTextColor(winmsg, ILI9341_WHITE,ILI9341_BLUE);
	tft_fillWin(winmsg, winmsg->bg);
	// write some text
	tft_set_font(winmsg,0);
	tft_font_var(winmsg);
	tft_set_textpos(winmsg, 0,0);

	// CUBE setup
#ifdef WIRECUBE
		/* Setup cube/wireframe demo window */
		/* This is to the right of the winmsg window and the same height */
		tft_window_init(wincube, winmsg->w, wintop->h, master->w - winmsg->w, winmsg->h);
		tft_setTextColor(wincube, ILI9341_WHITE,ILI9341_BLUE);
		tft_fillWin(wincube, wincube->bg);
#endif

#ifdef DEBUG_STATS
	if(debug)
	{
		// Display ID
		tft_setTextColor(winmsg, ILI9341_RED,winmsg->bg);
		tft_printf(winmsg, "DISP ID: %04lx\n", ID);
		tft_setTextColor(winmsg, ILI9341_WHITE,winmsg->bg);
#ifdef XPT2046
			if(!tft_is_calibrated)
			{
				tft_set_font(winmsg,0);
				tft_printf(winmsg,"Please Calibrate Display\n");
				tft_printf(winmsg,"serial command: calibrate N\n");
				tft_printf(winmsg,"N is rotation, 0..3\n");
				tft_printf(winmsg,"%d is current\n",master->rotation);
			}
#endif
	}
#endif


	// Cube points were defined with sides of 1.0 
	// We want a scale of +/- w/2
#ifdef WIRECUBE
		if(wincube->w < wincube->h) 
			dscale_max = wincube->w/2;
		else
			dscale_max = wincube->h/2;

		dscale = dscale_max;
		dscale_inc = dscale_max / 100;
#endif

#if ILI9341_DEBUG & 1
	if(debug)
	{
		printf("Test Display Read\n");
		read_tests(winmsg);
	}
#endif

	// Draw Wireframe earth in message area
#ifdef EARTH
	// Earth points were defined with radius of 0.5, diameter of 1.0
	// We want a scale of +/- w/2
		double tscale_max;
		if(winearth->w < winearth->h) 
			tscale_max = winearth->w;
		else
			tscale_max = winearth->h;
		V.x = -90;
		V.y = -90;
		V.z = -90;
		// draw earth
	// Earth points were defined over with a scale of -0.5/+0.5 scale - so scale must be 1 or less
		wire_draw(winearth, earth_data, NULL, &V, winearth->w/2, winearth->h/2, tscale_max, winearth->fg);
#endif

}
Ejemplo n.º 3
0
/**
 @brief test task
  Runs corrected cube demo from Sem
  Optionally wireframe Earh viewer
 @return void
*/
LOCAL void user_task(void)
{
	uint32_t time1,time2;
	uint8_t red, blue,green;
	long timer = 0;
	uint16 system_adc_read(void);
	extern uint8_t ip_msg[];
	time_t sec;
	char buffer[256];


	

#ifdef WIRECUBE
	V.x = degree;
	V.y = degree;
	V.z = degree;
// Cube points were defined with sides of 1.0 
// We want a scale of +/- w/2
	wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, 0);
	//wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, 0);
#endif

#ifdef CIRCLE
	rad = dscale; // +/- 90
    tft_drawCircle(windemo, windemo->w/2, windemo->h/2, rad ,0);
	Display bounding circle that changes color around the cube
	if(dscale_inc < 0.0)
	{
		red = 255;
		blue = 0;
		green = 0;
	}
	else
	{
		red = 0;
		blue = 255;
		green = 0;
	}
	// RGB - YELLOW
    tft_drawCircle(windemo, windemo->w/2, windemo->h/2, dscale, tft_color565(red,green,blue));
#endif

    degree += deg_inc;
    dscale += dscale_inc;

	if(degree <= -360)
		deg_inc = 4;
	if(degree >= 360)
		deg_inc = -4;

    if(dscale < dscale_max/2)
	{
	   dscale_inc = -dscale_inc;
	}
    if(dscale > dscale_max)
	{
	   dscale_inc = -dscale_inc;
	}


#ifdef WIRECUBE
	V.x = degree;
	V.y = degree;
	V.z = degree;
	//time1 = system_get_time();
	wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, ILI9341_WHITE);
	//wire_draw(windemo, cube_points, cube_edges, &V, windemo->w/2, windemo->h/2, dscale, ILI9341_WHITE);
	//time2 = system_get_time();
#endif


// Get system voltage 33 = 3.3 volts
	adc_sum += system_adc_read();
	//adc_sum += system_get_vdd33();

	// FIXME atomic access
	if(++adc_count == 10)
	{
		voltage = ((double) adc_sum / 100.0); 
		adc_count = 0;
		adc_sum = 0;
	}

	// DEBUG_PRINTF("Degree: %d \r\n",(int)degree);
	// cube redraw count
	count += 1;
	tft_set_font(winstats,0);
	tft_setpos(winstats,ip_xpos,ip_ypos);
	tft_printf(winstats,"%-26s\n", ip_msg);
	if(!signal_loop--)
	{
		signal_loop = 100;
		tft_printf(winstats,"CH:%02d, DB:-%02d\n", 
			wifi_get_channel(),
			wifi_station_get_rssi());
		signal_loop = 0;
	}
	tft_setpos(winstats,xpos,ypos);
	tft_printf(winstats,"Heap: %d\n", system_get_free_heap_size());
	tft_printf(winstats,"Iter:% 9ld, %+7.2f\n", count, degree);
	
	// NTP state machine
	ntp_setup();

	// get current time
	time(&sec);

	tft_printf(winstats,"Volt:%2.2f\n%s\n", (float)voltage, ctime(&sec));
	
#ifdef NETWORK_TEST
	poll_network_message(wintest);
#endif

// Buffered get line uses interrupts and queues
	if(uart0_gets(buffer,255))
	{
		DEBUG_PRINTF("Command:%s\n",buffer);
		if(!fatfs_tests(buffer))
		{
			if(!user_tests(buffer))
			{
				DEBUG_PRINTF("unknow command: %s\n", buffer);
			}
		}
	}
}
Ejemplo n.º 4
0
// main task loop called by yield code
void user_loop(void)
{
	extern int connections;
	uint32_t time1,time2;
	long t;
#ifdef DISPLAY
	char time_tmp[32];
	uint8_t red, blue,green;
	int touched;
	uint16_t X,Y;
#endif

	// getinfo.ip.addr, getinfo.gw.addr, getinfo.netmask.addr
	struct ip_info getinfo;
	char *ptr;

	// ========================================================
	// Run all remaining tasks once every 1mS
	t = ms_read();
	if((t - last_time10) < 1U)
		return;
	last_time10 = t;
	// ========================================================
// Tasks that must run very fast , once every millisecond should be at the top

#ifdef ADF4351
	ADF4351_task();
#endif
#ifdef XPT2046
	XPT2046_task();
#endif

	// ========================================================
	// Only run every 50mS
	t = ms_read();
	if((t - last_time50) < 50U)
		return;
	last_time50 = t;
	// ========================================================

	user_tasks();

	// NTP state machine
	ntp_setup();


#ifdef DISPLAY
	#ifdef XPT2046
		if(tft_is_calibrated)
		{
			touched = tft_touch_key(master,(uint16_t *)&X, (uint16_t *)&Y);
			#if XPT2046_DEBUG
				if(touched)
					tft_printf(winmsg,"X:%d,Y:%d\n",(int)X,(int)Y);
			#endif
		}
	#endif

	#ifdef NETWORK_TEST
		servertest_message(winmsg);
	#endif

	#ifdef DEBUG_STATS
		#ifdef VOLTAGE_TEST
			#ifdef DEBUG_STATS
				// Do NOT run adc_read() every millisecond as system_adc_read() blocks WIFI 
				tft_set_textpos(wintop, 0,2);
				tft_printf(wintop,"Volt:%2.2f\n", (float)adc_read());
			#endif
		#endif // VOLTAGE_TEST

		count += 1;
		tft_set_textpos(wintop, 0,0);
		tft_set_font(wintop,0);
		tft_font_fixed(wintop);
		tft_printf(wintop,"Iter:% 10ld, %+7.2f\n", count, degree);
	#endif

	#ifdef CIRCLE
		rad = dscale; // +/- 90
		tft_drawCircle(wincube, wincube->w/2, wincube->h/2, rad ,wincube->bg);
		// RGB 
	#endif

	// reset cube to background
	#ifdef WIRECUBE
		V.x = degree;
		V.y = degree;
		V.z = degree;
		// Cube points were defined with sides of 1.0 
		// We want a scale of +/- w/2
		wire_draw(wincube, cube_points, cube_edges, &V, wincube->w/2, wincube->h/2, dscale, wincube->bg);
	#endif

	degree += deg_inc;
	dscale += dscale_inc;

	if(degree <= -360)
		deg_inc = 4;
	if(degree >= 360)
		deg_inc = -4;

	if(dscale < dscale_max/2)
	{
	   dscale_inc = -dscale_inc;
	}
	if(dscale > dscale_max)
	{
	   dscale_inc = -dscale_inc;
	}

	#ifdef WIRECUBE
		V.x = degree;
		V.y = degree;
		V.z = degree;
		wire_draw(wincube, cube_points, cube_edges, &V, wincube->w/2, wincube->h/2, dscale, ILI9341_WHITE);
	#endif

	#ifdef CIRCLE
		// Display bounding circle that changes color around the cube
		if(dscale_inc < 0.0)
		{
			red = 255;
			blue = 0;
			green = 0;
		}
		else
		{
			red = 0;
			blue = 0;
			green = 255;
		}
		rad = dscale; // +/- 90
		tft_drawCircle(wincube, wincube->w/2, wincube->h/2, rad, tft_RGBto565(red,green,blue));
	#endif
#endif	// DISPLAY

	// ========================================================
	// Tasks run only once every second go after this
	time(&sec);
	if(sec == seconds)
		return;
	seconds=sec;
	// ========================================================

#ifdef DISPLAY
	// ========================================================
	// TIME
	tft_set_textpos(winbottom, 0,0);
	//Tue May 17 18:56:01 2016
	strncpy(time_tmp,ctime(&sec),31);
	time_tmp[19] = 0;
	tft_printf(winbottom," %s", time_tmp);
	tft_cleareol(winbottom);
	tft_set_textpos(winbottom, 0,1);

	// ========================================================
	// CONNECTION status
	//tft_printf(winbottom," %s", ip_msg);
	// IP and disconnected connection state only
	if(wifi_get_ip_info(0, &getinfo))
		tft_printf(winbottom," %s", ipv4_2str(getinfo.ip.addr));
	else
		tft_printf(winbottom," Disconnected");
	tft_cleareol(winbottom);

	#ifdef DEBUG_STATS
		// ========================================================
		// HEAP size
		tft_set_textpos(wintop, 0,1);
		tft_printf(wintop,"Heap: %d, Conn:%d\n", 
		system_get_free_heap_size(), connections);
		
		// ========================================================
		// WIFI status
		tft_set_textpos(wintop, 0,3);
		tft_printf(wintop,"CH:%02d, DB:%+02d\n", 
		wifi_get_channel(),
		wifi_station_get_rssi());
	#endif	// DEBUG_STATS
#endif	//DISPLAY

}