コード例 #1
0
ファイル: cap_read.c プロジェクト: michael00133/ECE4760
//======================= Blink ========================= //
// Blinks a circle on the screen at a rate of 1 blink per second
static PT_THREAD (protothread_blink(struct pt *pt))
{
    PT_BEGIN(pt);
    while(1) {
	
	PT_YIELD_TIME_msec(1000);
    tft_drawCircle(10, 10, 10, ILI9340_WHITE);

	PT_YIELD_TIME_msec(1000);
	tft_drawCircle(10, 10, 10, ILI9340_BLACK); 
   }
    PT_END(pt);
} // blink
コード例 #2
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);
			}
		}
	}
}
コード例 #3
0
ファイル: user_main.c プロジェクト: magore/esp8266_ili9341
// 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

}