Ejemplo n.º 1
0
void checksignal(){
	tft_clear();
	if (read_GPIO_switch(GPIOA,GPIO_Pin_9)){
		tft_prints(2,2,"Pin 9 receive signal");
		tft_update();
		LED_ON(GPIOB,LED_L);		
	}
	if (read_GPIO_switch(GPIOA,GPIO_Pin_10)){
		tft_prints(2,2,"Pin 10 receive signal");
		tft_update();
		LED_ON(GPIOB,LED_M);		
	}
	if (read_GPIO_switch(GPIOA,GPIO_Pin_11)){
		tft_prints(2,2,"Pin 11 receive signal");
		tft_update();
		LED_ON(GPIOA,LED_R);		
	}
	if (read_GPIO_switch(GPIOA,GPIO_Pin_12)){
		tft_prints(2,2,"Pin 12 receive signal");
		tft_update();
	}
	if (!read_GPIO_switch(GPIOA,GPIO_Pin_12) && !read_GPIO_switch(GPIOA,GPIO_Pin_11) && !read_GPIO_switch(GPIOA,GPIO_Pin_11) && !read_GPIO_switch(GPIOA,GPIO_Pin_12)){
		tft_prints(2,2,"no signal received");
		tft_update();
	}
	
}
void listener(const uint8_t byte) {
    switch(byte) {
    case 'w':
        tft_prints(1,1,"Yay Forward LA");
        tft_update();
        motor_control(1,1,100);
        motor_control(2,1,100);
        _delay_ms(delay_time);
        motor_control(1, 1, 0);
        motor_control(2, 1, 0);
        break;

    case 'a':
        tft_prints(1,1,"Yay Left LA");
        tft_update();
        motor_control(1, 1, 0);
        motor_control(2, 1, 100);
        _delay_ms(delay_time);
        motor_control(1, 1, 0);
        motor_control(2, 1, 0);
        break;

    case 'd':
        tft_prints(1, 1, "Yay Right LA");
        tft_update();
        motor_control(1,1,100);
        motor_control(2,1,0);
        _delay_ms(delay_time);
        motor_control(1, 1, 0);
        motor_control(2, 1, 0);
        break;

    case 's':
        tft_prints(1, 1, "Yay Stop La");
        tft_update();
        motor_control(1, 1, 0);
        motor_control(2, 1, 0);
        //stop_while = 0;
        break;

    case 'b':
        stop_while = 1;
        break;

    default:
        tft_prints(1, 1, "default la");
        break;

    }
}
Ejemplo n.º 3
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();
		
	}
void main()
{
    system_init();
    EnableInterrupts();

    while( 1 )
    {
        if( update_flag )
            tft_update();
    }
}
void turnn(int x){
    if (x>0 && x<20){
        motor_control(1, 0, 0);  //left motor
        motor_control(2, 0, 100); //right motor
        tft_prints(5,5,"Turn left");
        tft_update();
    }else if(x>20 && x<40){
        motor_control(1, 0, 0);
        motor_control(2, 0, 75);
        tft_prints(5,5,"Turn left");
        tft_update();
    }else if(x>40 && x<54){
        motor_control(1, 0, 0);
        motor_control(2, 0, 70);
        tft_prints(5,5,"Turn left");
        tft_update();
    }
    if(x>74 && x<100){
        motor_control(1, 0, 100);   //left motor
        motor_control(2, 0, 0);
        tft_prints(5,5,"Turn right");
        tft_update();
    }else if(x<100 && x>120){
        motor_control(1,0, 75);
        motor_control(2,0, 0);
        tft_prints(5,5,"Turn right");
        tft_update();
    }else if (x>120){
        motor_control(1,0,70);
        motor_control(2,0, 0);
        tft_prints(5,5,"Turn right");
        tft_update();
    }
}
/*int main()
{
	LED_INIT();
	uart_init(COM3, 115200);
	//uart_interrupt_init(COM3, &listener);
	tft_init(0, WHITE, BLACK, GREEN);
	button_init();
	ticks_init();
	motor_init();
	pneumatic_init();
	int count = 0;
	tft_init(0, WHITE, BLACK, GREEN);
	linear_ccd_init();
	adc_init();
	while(true) {
		if(count != get_ms_ticks()){
			count = get_ms_ticks();
			if(count % 40 == 0){
				linear_ccd_clear();
				linear_ccd_read();
				linear_ccd_prints();
				if(find_white_line() != 0) {
					tft_prints(2, 1, "%3d", find_white_line());
					tft_update();
				}

				if(find_white_line() < 50) {
					motor_control(1,0,100);

				}
				else {
					motor_control(1,0,0);

				}
				//tft_update();
			}
		}
	}
	return 0;
}*/
int main() {
    tft_init(0,WHITE,BLACK,RED);
    linear_ccd_init();
    ticks_init();
    GPIO_switch_init();
    pneumatic_init();
    button_init();
    LED_INIT();
    motor_init();
    uart_init(COM3, 115200);
    uart_interrupt_init(COM3,&listener);

    while(true) {
//listener(const uint8_t byte);
        tft_clear();
        tft_prints(2,4,"okay la") ;
        tft_update();

        while(!read_button(1))
        {   LED_ON(GPIOB, LED_M);
            motor_control(1,1,100);
        }
        /*if(read_GPIO_switch(GPIOA,GPIO_Pin_9)==1&&!read_button(1))
        { tft_clear();
        tft_prints(2,4,"grip");
        tft_update();*/
        /*pneumatic_control(GPIOB,GPIO_Pin_13,1);}
         else
        { tft_clear();
        	tft_prints(2,4,"let it go~");
        	tft_update();
        pneumatic_control(GPIOB,GPIO_Pin_13,0);}*/

        int time = get_ms_ticks();
        if(time%40==0)
        {
            linear_ccd_clear();
            linear_ccd_read();
            linear_ccd_prints();

        }
        //turnn(find_white_line());

    }
}
Ejemplo n.º 7
0
/**
	* @brief Display the menu (to be called directly, while-loop in side)
	* @param default_id: Default selected / entered menu ID
  * @param pre_enter: True for enterring the selected menu item
  * @retval None
	*/
void menu(u8 default_id, bool pre_enter)
{
	menu_selected = default_id;
	while (1) {
		if (ticks_img != get_ticks()) {
			ticks_img = get_ticks();
			
			/*if (ticks_img % 200 == 1) {
				battery_adc_update();
				if (get_seconds() % 10 == 4 && ticks_img == 1) {
					battery_regular_check();
				}
			}*/

//			if (ticks_img % 50 == 2) {
//				// Check button input
//				//button_update();
//							
//				/** Menu item shift **/
//				if (button_pressed(BUTTON_JS2_DOWN) == 1 || button_hold(BUTTON_JS2_DOWN, 10, 1)) {
//					// Go down the list
//					if (menu_selected < menu_count - 1) {
//						++menu_selected; 
//					} else {
//						menu_selected = 0;
//					}
//				} else if (button_pressed(BUTTON_JS2_UP) == 1 || button_hold(BUTTON_JS2_UP, 10, 1)) {
//					if (menu_selected > 0) {
//						--menu_selected;
//					} else {
//						menu_selected = menu_count - 1;
//					}
//				}
//				
//				/** Enter menu **/
//				if (button_pressed(BUTTON_JS2_CENTER) == 1 || pre_enter) {
//					if (menu_list[menu_selected].fx == 0) {
//						// NULL FUNCTION
//						buzzer_play_song(FAIL_SOUND, 120, 100);
//					} else {
//						u16 prev_bg_color = tft_get_bg_color();
//						u16 prev_text_color = tft_get_text_color();
//						tft_clear();
//						CLICK_MUSIC;
//						menu_list[menu_selected].fx();
//						CLICK_MUSIC;
//						tft_clear();
//						tft_set_bg_color(prev_bg_color);
//						tft_set_text_color(prev_text_color);
//						pre_enter = false; 
//					}
//				}        
//				/** Change screen orientation **/
//				
//				if (button_pressed(BUTTON_1) == 1) {
//					tft_set_orientation((tft_get_orientation() + 1) % 4);
//					SUCCESSFUL_MUSIC;
//				}
//				if (button_pressed(BUTTON_2) == 1) {
//					tft_set_orientation((tft_get_orientation() + 3) % 4);
//					SUCCESSFUL_MUSIC;
//				}
//			}	
     
			if (ticks_img % 50 == 7) {
				u16 prev_bg_color = tft_get_bg_color();
				u16 prev_text_color = tft_get_text_color();
				
				tft_clear();
				
				draw_top_bar();
				
				// Menu list
				const u8 items_per_page = tft_get_max_y_char() - 2;
				u8 page_count = menu_count ? (menu_count - 1) / items_per_page : 0; // Start from 0
				u8 current_page = menu_selected / items_per_page;	// Start from 0
				
				for (u8 i = 0 + current_page * items_per_page, y = 0; i < menu_count && y < items_per_page; ++i, ++y) {
					if (i == menu_selected) {
						// Highlight the selected item
						tft_set_bg_color(ticks_img < 500 ? BLACK : DARK_GREY);
						tft_clear_line(y+1);
						tft_set_text_color(WHITE);
					} else {
						tft_set_bg_color(WHITE);
						tft_clear_line(y+1);
						tft_set_text_color(BLACK);
					}
					tft_prints(1, y+1, "%s", menu_list[i].title);
				}
				
				// Bottom bar - page number
				tft_set_text_color(WHITE);
				tft_set_bg_color(BLUE2);
				tft_clear_line(tft_get_max_y_char()-1);
				tft_prints(1, tft_get_max_y_char()-1, "%d/%d", current_page + 1, page_count + 1);
				
				// Reset bg and text color
				tft_set_bg_color(prev_bg_color);
				tft_set_text_color(prev_text_color);
				tft_update();
			}
		}
	}
}
Ejemplo n.º 8
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);
	}
}