⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 menu.c

📁 D:My DocumentszqARM压缩包OpenSource_49.rar
💻 C
📖 第 1 页 / 共 2 页
字号:
}
//*******************************************************************************************
//
// Function : display_menu
// Description : display LCD user interface menu on LCD
//
//*******************************************************************************************
void display_menu(void)
{
	BYTE generic_buf[64];

	if( menu_index == 0)
		return;

	// display menu title on lcd first line
	lcd_putc( '\f' );
	lcd_print ( (BYTE *)menu_list[ menu_index - 1 ] );
	
	// display menu detail on lcd second line
	lcd_putc( '\n' );
	if( menu_index == 1 )//MENU_MAIN)
	{
		lcd_print( (BYTE *)menu_list[ submenu_index ] );
	}
	// setup avr ip address
	else if( menu_index == 2 )
	{
		print_ip ( generic_buf, (BYTE*)&avr_ip, setting_cursor+1 );
		lcd_print ( generic_buf );
	}
	// setup server ip address
	else if(menu_index == 3 )
	{
		print_ip ( generic_buf, (BYTE*)&server_ip, setting_cursor+1 );
		lcd_print ( generic_buf );
	}
	// setup countdown timer for send temparature
	else if ( menu_index == 4 )
	{
		print_time ( generic_buf, count_time, setting_cursor+1 );
		lcd_print ( generic_buf );
	}
	// ping server
	else if ( menu_index == 5 )
	{
		print_ip ( generic_buf, (BYTE*)&server_ip, 1 );
		lcd_print ( generic_buf );
	}
	// send temparature now
	//else if ( menu_index == 6 )
	//{
	//	lcd_put ( ASCII_CURSOR );
	//	lcd_print_p ( PSTR ( "OK" ) );
	//}
}
//*******************************************************************************************
//
// Function : key_up_process
// Description : 
//
//*******************************************************************************************
void key_up_process ( void )
{
	BYTE temp;
	
	// standby display, display board status
	if(menu_index == 0)
	{
		if ( ++ standby_cursor == ((sizeof(standby_list)/2)+1) )
			standby_cursor = 1;
		flag1.bits.update_display = 1;
	}
	// main menu
	else if(menu_index == 1)
	{
		if( ++submenu_index == (sizeof(menu_list)/2) )
		{
			submenu_index = 1;
		}
	}
	// setup avr ip
	else if( menu_index == 2 )
	{
		avr_ip.byte [ setting_cursor ]++;
		eeprom_write_block ( &avr_ip, ee_avr_ip, 4 );
	}
	// setup server ip
	else if( menu_index == 3 )
	{
		server_ip.byte [ setting_cursor ]++;
		eeprom_write_block ( &server_ip, ee_server_ip, 4 );
	}
	// setup countdown timer
	else if( menu_index == 4 )
	{
		temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) );
		if ( ++count_time [ setting_cursor ] == temp )
			count_time [ setting_cursor ] = 0;
		eeprom_write_block ( count_time, ee_count_time, 4 );
	}
}
//*******************************************************************************************
//
// Function : key_dw_process
// Description : 
//
//*******************************************************************************************
void key_dw_process ( void )
{
	BYTE temp;
	
	// standby display, display board status
	if(menu_index == 0)
	{
		if ( -- standby_cursor == 0 )
			standby_cursor = sizeof(standby_list)/2;
		flag1.bits.update_display = 1;
	}
	// main menu
	else if(menu_index == 1)
	{
		if( --submenu_index == 0 )
		{
			submenu_index = (sizeof(menu_list)/2)-1;
		}
	}
	// setup avr ip
	else if( menu_index == 2 )
	{
		avr_ip.byte [ setting_cursor ]--;
		eeprom_write_block ( &avr_ip, ee_avr_ip, 4 );
	}
	// setup server ip
	else if( menu_index == 3 )
	{
		server_ip.byte [ setting_cursor ]--;
		eeprom_write_block ( &server_ip, ee_server_ip, 4 );
	}
	// setup countdown timer
	else if( menu_index == 4 )
	{
		temp = pgm_read_byte ( (PGM_P)(count_time_max + setting_cursor) );
		if ( --count_time [ setting_cursor ] == 0xff )
			count_time [ setting_cursor ] = temp;
		eeprom_write_block ( count_time, ee_count_time, 4 );
	}
}
//*******************************************************************************************
//
// Function : key_process
// Description : Process all key code from get_key_code function
//
//*******************************************************************************************
void menu_process ( void )
{
	static BYTE key_hold_count=0, key_hold_step_delay=0;
	BYTE rxtx_buffer[MAX_RXTX_BUFFER];
	BYTE key_code, temp;
	static BYTE backlight_sec=31, backlight_seccount=250;
	
	// get switch value from port
	key_code = SW_PIN & ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) );
	
	// Check key press?
	if ( key_code  == ( _BV( SW_DW ) | _BV( SW_UP ) | _BV( SW_EXIT ) | _BV( SW_MENU ) ) )
	{
		flag1.bits.key_is_executed = 0;
		flag2.bits.key_hold = 0;
		key_hold_count = 0;
		key_hold_step_delay = 0;

		// lcd backlight control
		// lcd backlight off after key is unpress ( 30 seconds)
		if ( backlight_sec )
		{
			if ( --backlight_seccount > 250 )
			{
				backlight_seccount = 250;
				if ( --backlight_sec == 1 )
				{
					backlight_sec = 0;
					// lcd backlight off
					LCD_BL_PORT &= ~_BV( LCD_BL_PIN );
				}
			}
		}
		return;
	}
	
	// lcd backlight on
	// and hold-on 30 seconds
	backlight_sec = 31;
	LCD_BL_PORT |= _BV( LCD_BL_PIN );

	// check hold key
	if ( ++key_hold_count == 200 )
	{
		key_hold_count = 0;
		flag2.bits.key_hold = 1;		
	}
	
	if ( flag2.bits.key_hold )
	{
		if ( ++key_hold_step_delay == 30 )
		{
			key_hold_step_delay = 0;
			if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) )
			{
				key_up_process ();
			}
			// if down key is pressed
			else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) )
			{
				key_dw_process ();
			}
			display_menu();
		}
	}
	// key code already executed
	if ( flag1.bits.key_is_executed )
		return;
	// check key code, what is key pressed?
	// if menu key is pressed
	if ( key_code == ((~_BV ( SW_MENU ) ) & 0xf0) )
	{
		// enter to main menu
		if( menu_index == 0 )
		{
			setting_cursor = 0;
			menu_index = 1;
			submenu_index = 1;
		}
		// enter to submenu
		else if( menu_index == 1 )
		{
			menu_stack = menu_index;
			submenu_stack = submenu_index;
			menu_index = submenu_index + menu_index;
			submenu_index = 1;
		}
		// ping server
		else if ( menu_index == 5 )
		{
			// Show on lcd first line
			lcd_putc( '\f' );
			lcd_print ( (BYTE *)menu_list[ 4 ] );
			lcd_putc( '\n' );
			if ( icmp_ping ( (BYTE*)rxtx_buffer, (BYTE*)&server_mac, (BYTE*)&server_ip ) )
			{
				lcd_print_p ( PSTR ( "Ping OK." ) );
			}
			else
			{
				lcd_print_p ( PSTR ( "Not found." ) );
			}
			flag1.bits.lcd_busy = 1;
			menu_index = 0;
			submenu_index = 0;
			flag1.bits.key_is_executed = 1;
			return;
		}
		// change cursor setting on each menu
		else
		{
			temp = pgm_read_byte ( (PGM_P)(setting_cursor_max + menu_index - 2) );

			if ( ++setting_cursor == temp )
				setting_cursor = 0;
		}
	}
	// if exit key is pressed
	else if ( key_code == ((~_BV ( SW_EXIT ) ) & 0xf0) )
	{
		setting_cursor = 0;
		if(menu_index > 1)
		{
			menu_index = menu_stack;
			submenu_index = submenu_stack;
		}
		else
		{
			menu_index = 0;
			submenu_index = 0;
			
		}
	}
	// if up key is pressed
	else if ( key_code == ((~_BV ( SW_UP ) ) & 0xf0) )
	{
		key_up_process ();
	}
	// if down key is pressed
	else if ( key_code == ((~_BV ( SW_DW ) ) & 0xf0) )
	{
		key_dw_process ();
	}
	// display menu information on LCD
	display_menu();
	flag1.bits.key_is_executed = 1;
	flag1.bits.lcd_busy = 0;
}
//*******************************************************************************************
//
// Function : menu_init
// Description : initial I/O direction for all key,
// initial timer1 for countdown timer
//
//*******************************************************************************************
void menu_init ( void )
{	
	// setup countdown initial value
	sec_count = 0;
	eeprom_read_block ( count_time, ee_count_time, 3 );
	count_time[3] = 0;

	// setup menu and standby display
	flag1.byte = 0;
	flag2.byte = 0;
	menu_index = 0;
	submenu_index = 0;
	menu_stack = 0;
	submenu_stack = 0;
	setting_cursor = 0;
	standby_cursor = 1;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -