Exemple #1
0
static void timer_callback(void *parameter)
{
	int i;
	key_t key;

	rt_ubase_t level;
	
	struct dev_key *dev_key = (struct dev_key *)parameter;
	RT_ASSERT(dev_key != RT_NULL);
	
	for (i = 0; i < KEY_NUM; i++)
	{
		key = key_check(i);
		if (KEY_VALUE(key) != KEY_NONE)
		{
			dev_key->key_buffer[dev_key->save_index] = key;

			level = rt_hw_interrupt_disable();
			dev_key->save_index++;
			if (dev_key->save_index >= KEY_QUEUE_LEN)
				dev_key->save_index = 0;
			rt_hw_interrupt_enable(level);

			/* invoke callback */
			if(dev_key->parent.rx_indicate != RT_NULL)
			{
				rt_size_t length;
				if (dev_key->read_index > dev_key->save_index)
					length = KEY_QUEUE_LEN - dev_key->read_index + dev_key->save_index;
				else
					length = dev_key->save_index - dev_key->read_index;

				dev_key->parent.rx_indicate(&dev_key->parent, length);
			}
		}
	}
}
Cyg_ErrNo gx3113_panel_read(cyg_io_handle_t handle,
                         void *buffer, cyg_uint32 *len)
{
#define KEY_VALUE(value)    ((value&0xff00)<<16 | (value&0xff)<<8)
#define INTERVAL   (3)

	static uint32_t interval = 0;

	// slow down the key press
	interval++;
	if (interval != INTERVAL)
	{
		*(uint32_t*)buffer = KEY_VALUE(0x0);
		return ENOERR;
	}
	else
	{
		interval = 0;
	}
//	bsp_printf("gx3113_panel_read s_panel_key %x\n",s_panel_key);
	switch (s_panel_key)
	{
		case PANEL_KEY_EXIT:
//			s_panel_key = 0;
			*(uint32_t*)buffer = PANEL_KEY_EXIT;
			break;
		case PANEL_KEY_UP:
//			s_panel_key = 0;
			*(uint32_t*)buffer = PANEL_KEY_UP;
			break;
		case PANEL_KEY_DOWN:
//			s_panel_key = 0;
			*(uint32_t*)buffer =PANEL_KEY_DOWN;
			break;
		case PANEL_KEY_RIGHT:
//			s_panel_key = 0;
			*(uint32_t*)buffer = PANEL_KEY_RIGHT;
			break;
		case PANEL_KEY_MENU:
//			s_panel_key = 0;
			*(uint32_t*)buffer = PANEL_KEY_MENU;
			break;
		case PANEL_KEY_OK:
			s_panel_key = 0;
			*(uint32_t*)buffer = PANEL_KEY_OK;
			break;
		case PANEL_KEY_LEFT:
//			s_panel_key = 0;
			*(uint32_t*)buffer = PANEL_KEY_LEFT;
			break;
		case PANEL_KEY_POWER:
//			s_panel_key = 0;
			*(uint32_t*)buffer = PANEL_KEY_POWER;
			break;
		default:
			*(uint32_t*)buffer = KEY_VALUE(0x0);
			break;
	}

	s_panel_key = 0;
	
	return ENOERR;
}
static void key_handler(void *msg)
{
	key_t key_msg = (key_t)(uint32_t)msg;
	uint8_t key = KEY_VALUE(key_msg);
	
	if (KEY_TYPE(key_msg) == MASK_KEY_RELEASE)
	{
		return;
	}

	if (KEY_TYPE(key_msg) != MASK_KEY_PRESS && (key == KEY_OK || key == KEY_CANCEL))
	{
		return;
	}
	
	beeper_beep(BEEPER_VOL_LOW, 50, 50, 1);

	if (key == KEY_LEFT || key == KEY_UP)
	{
		if (s_edit_item == DIVIDE_MODE_NONE)
		{
			s_unfocus_fun_arr[s_focus_item]();
			
			s_focus_item += DIVIDE_MODE_COUNT - 1;
			s_focus_item %= DIVIDE_MODE_COUNT;
			
			s_focus_fun_arr[s_focus_item]();
		}
		else
		{
			s_edit_fun_arr[s_edit_item](key);
		}
		
		lcd_validate_cmd();
	}
	else if (key == KEY_RIGHT || key == KEY_DOWN)
	{
		if (s_edit_item == DIVIDE_MODE_NONE)
		{
			s_unfocus_fun_arr[s_focus_item]();
			
			s_focus_item++;
			s_focus_item %= DIVIDE_MODE_COUNT;
			
			s_focus_fun_arr[s_focus_item]();
		}
		else
		{
			s_edit_fun_arr[s_edit_item](key);
		}

		lcd_validate_cmd();
	}
	else if (key == KEY_OK)
	{
		if (s_edit_item == DIVIDE_MODE_NONE)
		{
			s_enter_edit_fun_arr[s_focus_item]();
		}
		else
		{
			s_confirm_edit_fun_arr[s_focus_item]();
			
			s_edit_item = DIVIDE_MODE_NONE;
		}
		
		lcd_validate_cmd();
	}
	else if (key == KEY_CANCEL)
	{
		if (s_edit_item == DIVIDE_MODE_NONE)
		{
			/* save */
			set_dp_dn_divide_mode_setting(&s_divide_mode_setting);
			
			switch_to_menu(MENU_ID_EMPTY_LOAD_SETTING);
		}
		else
		{
			s_focus_fun_arr[s_focus_item]();
			
			lcd_validate_cmd();
			
			s_edit_item = DIVIDE_MODE_NONE;
		}
	}
}
Exemple #4
0
static void key_handler(void *msg)
{
	key_t key_msg = (key_t)(uint32_t)msg;
	uint8_t key = KEY_VALUE(key_msg);

	if (KEY_TYPE(key_msg) != MASK_KEY_PRESS && (key == KEY_OK || key == KEY_CANCEL))
	{
		return;
	}
	
	if (KEY_TYPE(key_msg) != MASK_KEY_RELEASE)
	{
		beeper_beep(BEEPER_VOL_LOW, 50, 50, 1);
		
		if (key == KEY_UP)
		{
			if (s_cr_mode == CR_EDIT_MODE)
			{
				s_cur_resist += BIG_RESIST_STEP;
				if (s_cur_resist > MAX_RESIST)
				{
					s_cur_resist = MAX_RESIST;
				}	
				draw_edit_resist_val(s_cur_resist);
			
				lcd_validate_cmd();
			}
		}
		else if (key == KEY_DOWN)
		{
			if (s_cr_mode == CR_EDIT_MODE)
			{
				if (s_cur_resist > BIG_RESIST_STEP)
				{
					s_cur_resist -= BIG_RESIST_STEP;
				}
				else
				{
					s_cur_resist = SMALL_RESIST_STEP;
				}
				draw_edit_resist_val(s_cur_resist);
			
				lcd_validate_cmd();
			}
		}
		else if (key == KEY_LEFT)
		{
			if (s_cr_mode == CR_EDIT_MODE)
			{
				if (s_cur_resist > SMALL_RESIST_STEP)
				{
					s_cur_resist -= SMALL_RESIST_STEP;
				}
				draw_edit_resist_val(s_cur_resist);
			
				lcd_validate_cmd();
			}
		}
		else if (key == KEY_RIGHT)
		{
			if (s_cr_mode == CR_EDIT_MODE)
			{	
				s_cur_resist += SMALL_RESIST_STEP;
				if (s_cur_resist > MAX_RESIST)
				{
					s_cur_resist = MAX_RESIST;
				}
				draw_edit_resist_val(s_cur_resist);
			
				lcd_validate_cmd();
			}
		}
		else if (key == KEY_OK)
		{
			if (KEY_TYPE(key_msg) == MASK_KEY_PRESS)
			{
				TEST_CMD test_cmd;
				
				if (s_cr_mode == CR_FOCUS_MODE)
				{	
					s_cur_resist = s_cr_mode_resist_set;
					draw_edit_resist_val(s_cur_resist);
				
					lcd_validate_cmd();
				
					s_cr_mode = CR_EDIT_MODE;		
					
					/* notify to start test */
					test_cmd.channel   = SLAVE_PORT_0;
					test_cmd.test_type = TEST_TYPE_CR_MODE;
					test_cmd.test_config.cr_mode_config.resist_val = s_cur_resist;
					test_cmd_notify(&test_cmd);

					TRACE("start testing\n");

					all_pass_led_on();
				}
				else
				{
					s_cr_mode_resist_set = s_cur_resist;
					draw_focus_resist_val(s_cr_mode_resist_set);
				
					lcd_validate_cmd();

					save_parameter(STRUCT_OFFSET(PARAMETER, cr_mode_resist_set), &s_cr_mode_resist_set, sizeof(s_cr_mode_resist_set));
					
					s_cr_mode = CR_FOCUS_MODE;
					
					/* notify to stop test */
					test_cmd.channel   = SLAVE_PORT_0;
					test_cmd.test_type = TEST_TYPE_NONE;
					test_cmd_notify(&test_cmd);		

					TRACE("stop testing\n");

					all_pass_led_off();
				}
			}
		}
		else if (key == KEY_CANCEL)
		{
			if (s_cr_mode == CR_FOCUS_MODE)
			{
				switch_to_menu(MENU_ID_MAIN);
			}
			else
			{
				TEST_CMD test_cmd;
				
				draw_focus_resist_val(s_cr_mode_resist_set);
				
				lcd_validate_cmd();
				
				s_cr_mode = CR_FOCUS_MODE;

				/* notify to stop test */
				test_cmd.channel   = SLAVE_PORT_0;
				test_cmd.test_type = TEST_TYPE_NONE;
				test_cmd_notify(&test_cmd);	

				TRACE("stop testing\n");

				all_pass_led_off();	
			}
		}
	}
	else
	{
		/* release */
		if (key == KEY_UP || key == KEY_DOWN
			|| key == KEY_LEFT || key == KEY_RIGHT)
		{
			if (s_cr_mode == CR_EDIT_MODE)
			{
				TEST_CMD test_cmd;
					
				/* notify */
				test_cmd.channel   = SLAVE_PORT_0;
				test_cmd.test_type = TEST_TYPE_CR_MODE;
				test_cmd.test_config.cr_mode_config.resist_val = s_cur_resist;
				test_cmd_notify(&test_cmd);

				TRACE("start testing\n");
			}
		}
	}
}