示例#1
0
void linear_ccd_read(){
	SI(0);
	CLK(0);
	_delay_us(1);
	SI(1);
	for(u8 n=0;n<128;n++)
	{
		_delay_us(1);
		CLK(1);		
		SI(0);
		_delay_us(1);
		linear_ccd_buffer1[n]=AO1();
		//linear_ccd_buffer2[n]=AO2();
		CLK(0);
	}
	
	
	

	for(u8 y=0;y<128;y++)
	{
		linear_ccd_buffer1[y] = (linear_ccd_buffer1[y])*160 / 4095;
	 if(linear_ccd_buffer1[y] >= 160){
		linear_ccd_buffer1[y] = 159;
	}
}
	 moving_adverage();
	//putting pixel on the monitor
	for(u8 y=0;y<128;y +=1)
	{
	
	 
		tft_put_pixel(y,linear_ccd_buffer1[y],GREEN);//put linear ccd1 pixels
		//tft_put_pixel(y,(linear_ccd_buffer2[y]*80 / 4095)+80,GREEN);//put linear ccd2 pixels
	
	}
		for(u8 y=0;y<128;y+=1 )
	{
	
	
		tft_put_pixel(y,linear_ccd_buffer1[y],BLACK);//clear linear ccd1 pixels
		//tft_put_pixel(y,(linear_ccd_buffer2[y]*80 / 4095)+80,BLACK);//clear linear ccd2 pixels
	
	
	}

	
	
	
}
示例#2
0
void linear_ccd_prints()
	{ int y ;
		int x ;
		for(x=0;x<=127;x++)
		{y= linear_ccd_buffer1[x];
		tft_put_pixel(x,y, BLACK);}
		tft_prints(2,4,"%d",find_white_line());
		tft_update();
		
	}
示例#3
0
void linear_ccd_clear()
  {   int y ;
		int x ;
		
		for(x=0;x<=127;x++)
		{y= linear_ccd_buffer1[x];
		tft_put_pixel(x,y, WHITE);}
		tft_clear();
		
		
}	
void print_ccd()
	{
    int y;
    int x;
    int avex;
    int sum;
    int max=0;
    int min=159;
    int mmin;
    int mmax;
    int count;

    for(int i=0; i<128; ++i){
        tft_put_pixel(i, linear_ccd_buffer1[i], BLACK);
        x=i;
        y=linear_ccd_buffer1[i];
        max= (y>max)? y: max;
        min = (y<min)? y :min;

        /*if(whiteexists(max,min)){
            sum+=i;
            count=count+1;
            tft_prints(1,1,"whiteline=1");
            tft_update();
        }else{
            tft_prints(1,1,"whiteline=0");
            tft_update();
            //checkendstage(max,min);
        }
        //checkendstage(max,min);
    }
    tft_prints(2,2,"max=%d",max);
    tft_update();
    tft_prints(2,3,"min=%d",min);
    tft_update();
    avex=sum/count;
    tft_prints(7,7,"avex=%d",avex);
    tft_update();
    //turnn(avex);*/
}
}
示例#5
0
/**
	* @brief System start interface display (to be called directly, delay exists)
	* @param duration: the delay time (in ms) of this function
	* @retval None
	*/
void system_start(u16 duration)
{
  const char* title = "Robocon 2015  Min System 1.2";
  
	//led_control((LED) (LED_D1 | LED_D2 | LED_D3), LED_ON);
	tft_clear();

	char tmp[CHAR_MAX_X-1] = "";
	tft_clear();
	tft_prints(1, 1, "[HKUST]");
	tft_prints(1, 2, "[Robotics Team]");
	
	strncpy(tmp, title, tft_get_max_x_char()-2);
	tft_prints(1, 4, "%s", tmp);
	if (strlen(title) >= tft_get_max_x_char()-2) {
		strncpy(tmp, &title[tft_get_max_x_char()-2], tft_get_max_x_char()-2);
		tft_prints(1, 5, "%s", tmp);
	}
	
	
	tft_update();
	
	buzzer_play_song(START_UP, 120, 0);
	
	// Start-up battery check
	//battery_adc_update();

	u16 prev_text_color = tft_get_text_color();	// Temp color change
	
 // tft_prints(0, 8, " Level: %d.%02dV", get_voltage() / 100, get_voltage() % 100);
  /*
	switch(battery_check()) {
		case BATTERY_USB:
		case BATTERY_OKAY:
			// DO NOTHING
			buzzer_play_song(START_UP, 120, 0);
			tft_set_text_color(DARK_GREEN);
			tft_prints(0, 7, " Battery OK");
		break;
		case BATTERY_LOW:
			buzzer_set_note_period(get_note_period(NOTE_E, 7));
			tft_set_text_color(ORANGE);
			buzzer_control(5, 100);
			tft_prints(0, 7, " LOW BATTERY!");
		break;
		case BATTERY_SUPER_LOW:
			buzzer_set_note_period(get_note_period(NOTE_C, 7));
			tft_set_text_color(RED);
			buzzer_control(10, 50);
			tft_prints(0, 7, " NO BATTERY!");
			tft_update();
			while(1) {
				delay_nms(200);
				//led_control((LED) (LED_D1 | LED_D2 | LED_D3), LED_OFF);
				tft_clear_line(7);
				tft_update();
				delay_nms(200);
				//led_control((LED) (LED_D1 | LED_D2 | LED_D3), LED_ON); 
				tft_prints(0, 7, " NO BATTERY!");
				tft_update();
			}
		
	}*/
	tft_update();
	// Reset bg and text color
	tft_set_text_color(prev_text_color);
	
/*
  
  for (u16 i = 0; i < duration / 4; ++i) {
    _delay_ms(4);
    button_update();
    if (button_pressed(BUTTON_JS2_CENTER) == 1) {
      break; 
    }
  }
  
	led_control((LED) (LED_D1 | LED_D2 | LED_D3), LED_OFF);
	
}

*/
/**
	* @brief Regular battery check (to be called every 10 seconds)
	* @param None
	* @retval None.
	* @warning Low battery will NOT go into while loop. 
	*/
/*
void battery_regular_check(void)
{
	switch(battery_check()) {
		case BATTERY_USB:
		case BATTERY_OKAY:
			// DO NOTHING
		break;
		case BATTERY_LOW:
			buzzer_set_note_period(get_note_period(NOTE_E, 7));
			buzzer_control(2, 100);
		break;
		case BATTERY_SUPER_LOW:
			buzzer_set_note_period(get_note_period(NOTE_E, 7));
			buzzer_control(6, 200);
		break;
	}
		
}
*/
/**
	* @brief Draw the battery icon on the top right corner of the TFT LCD monitor
	* @param batt: The battery level in voltage times 10 (122 for 12.2V)
	* @retval None
	*/
static void draw_battery_icon(u16 batt)
{
	u8 pos = (tft_get_orientation() % 2 ? MAX_HEIGHT : MAX_WIDTH);
	u16 batt_color = 0, batt_boundary = 0;
	u16 batt_w = 0;
	if (batt > BATTERY_USB_LEVEL / 10) {
		tft_prints(tft_get_max_x_char()-7, 0, "%2d.%d", batt/10, batt%10);
		batt_color = batt <= 114 ? RED : (batt <= 120 ? ORANGE : GREEN);
		batt_boundary = batt <= 114 ? RED : WHITE;
	} else {
		tft_prints(tft_get_max_x_char()-7, 0, " USB");
		batt_color = SKY_BLUE;
		batt_boundary = WHITE;
		batt = 126;
	}
	
	pos = (tft_get_orientation() % 2 ? MAX_HEIGHT : MAX_WIDTH);
	/* Convert battery level (110 to 126) to the pixel range (0 to 13) */ 
	batt_w = (batt > 126 ? 13 : batt < 110 ? 0 : (batt-110)*13/16);
	for (u8 i = 0; i < 13; i++) {
		for (u8 j = 0; j < 6; j++) {
			tft_put_pixel(pos-19+i, 5+j, i < batt_w ? batt_color : DARK_GREY);
		}
	}
	
	// Top and bottom line
	for (u8 i = 0; i < 17; i++) {
		tft_put_pixel(pos-21+i, 3, batt_boundary);
		tft_put_pixel(pos-21+i, 12, batt_boundary);
	}
	
	// Left and right line
	for (u8 i = 0; i < 8; i++) {
		tft_put_pixel(pos-21, 4+i, batt_boundary);
		tft_put_pixel(pos-5, 4+i, batt_boundary);
	}
	// The right extra lines
	for (u8 i = 0; i < 6; i++) {
		tft_put_pixel(pos-4, 5+i, batt_boundary);
		tft_put_pixel(pos-3, 5+i, batt_boundary);
	}
}