Esempio n. 1
0
void ui_process(uint16_t framenumber)
{
	bool b_btn_state;
	static bool btn_left_last_state = HID_MOUSE_BTN_UP;
	static bool btn_right_last_state = HID_MOUSE_BTN_UP;
	static bool btn_middle_last_state = HID_MOUSE_BTN_UP;
	static uint8_t cpt_sof = 0;

	if ((framenumber % 1000) == 0) {
		LED_On(LED1_GPIO);
	}
	if ((framenumber % 1000) == 500) {
		LED_Off(LED1_GPIO);
	}
	// Scan process running each 2ms
	cpt_sof++;
	if (2 > cpt_sof) {
		return;
	}
	cpt_sof = 0;

	// Scan buttons on switch 7 (left), 6 (middle), 4 (right)
	b_btn_state = (gpio_pin_is_low(GPIO_PUSH_BUTTON_7)) ? HID_MOUSE_BTN_DOWN
			: HID_MOUSE_BTN_UP;
	if (b_btn_state != btn_left_last_state) {
		udi_hid_mouse_btnleft(b_btn_state);
		btn_left_last_state = b_btn_state;
	}
	b_btn_state = (gpio_pin_is_low(GPIO_PUSH_BUTTON_6)) ? HID_MOUSE_BTN_DOWN
			: HID_MOUSE_BTN_UP;
	if (b_btn_state != btn_middle_last_state) {
		udi_hid_mouse_btnmiddle(b_btn_state);
		btn_middle_last_state = b_btn_state;
	}
	b_btn_state = (gpio_pin_is_low(GPIO_PUSH_BUTTON_4)) ? HID_MOUSE_BTN_DOWN
			: HID_MOUSE_BTN_UP;
	if (b_btn_state != btn_right_last_state) {
		udi_hid_mouse_btnright(b_btn_state);
		btn_right_last_state = b_btn_state;
	}
	// Scan move on switch 0 (right), 1 (left), 2 (down), 3 (up)
	if (gpio_pin_is_low(GPIO_PUSH_BUTTON_0))
		udi_hid_mouse_moveX(MOUSE_MOVE_RANGE);
	if (gpio_pin_is_low(GPIO_PUSH_BUTTON_1))
		udi_hid_mouse_moveX(-MOUSE_MOVE_RANGE);
	if (gpio_pin_is_low(GPIO_PUSH_BUTTON_2))
		udi_hid_mouse_moveY(MOUSE_MOVE_RANGE);
	if (gpio_pin_is_low(GPIO_PUSH_BUTTON_3))
		udi_hid_mouse_moveY(-MOUSE_MOVE_RANGE);
}
Esempio n. 2
0
void ui_process(uint16_t framenumber)
{
	bool b_btn_state;
	static bool btn_left = false, btn_right = false;
	static uint16_t cpt_sof = 0;

	if ((framenumber % 1000) == 0) {
		LED_On(LED1);
	}
	if ((framenumber % 1000) == 500) {
		LED_Off(LED1);
	}
	/* Scan process running each 2ms */
	cpt_sof++;
	if (cpt_sof < 2) {
		return;
	}
	cpt_sof = 0;

	/* Uses buttons to move mouse */
	if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_3)) {
		udi_hid_mouse_moveY(-MOUSE_MOVE_RANGE);
	}
	if (!ioport_get_pin_level(GPIO_PUSH_BUTTON_4)) {
		udi_hid_mouse_moveY( MOUSE_MOVE_RANGE);
	}
	/* Check button click */
	b_btn_state = !ioport_get_pin_level(GPIO_PUSH_BUTTON_2);
	if (b_btn_state != btn_left) {
		btn_left = b_btn_state;
		udi_hid_mouse_btnleft(btn_left);
	}
	b_btn_state = !ioport_get_pin_level(GPIO_PUSH_BUTTON_1);
	if (b_btn_state != btn_right) {
		btn_right = b_btn_state;
		udi_hid_mouse_btnright(btn_right);
	}
}
Esempio n. 3
0
/**
 * @brief Notify the application when ZID report data is received from the paired device.
 *  
 * @param PairingRef Pairing reference.
 * @param num_report_records number of Report records.
 * @param *zid_report_data_record_ptr pointer to the report data received.
 * @param  RxLinkQuality    LQI value of the report data frame.
 * @param  RxFlags          Receive flags.
 */
static void zid_report_data_indication(uint8_t PairingRef, uint8_t num_report_records,
                                                zid_report_data_record_t *zid_report_data_record_ptr, uint8_t RxLinkQuality, uint8_t RxFlags)
{          
   
                  
                  
     for(uint8_t i=0;i<num_report_records;i++)
     {  
    
         switch(zid_report_data_record_ptr->report_desc_identifier)
         {
         case MOUSE:
         {
            
             mouse_desc_t *mouse_desc;
             mouse_desc = (mouse_desc_t *)zid_report_data_record_ptr->report_data;
			 
				udi_hid_mouse_btnleft(mouse_desc->button0); 
				udi_hid_mouse_btnright(mouse_desc->button1);
			   
				if((0x80==(mouse_desc->button2)))
				{   
					udi_hid_mouse_moveScroll((mouse_desc->y_coordinate));
					mouse_desc->y_coordinate = 0;
				}
				else if(0x01==(mouse_desc->button2))
				{ 
					udi_hid_mouse_btnmiddle(0x01);
				}
				udi_hid_mouse_moveX((mouse_desc->x_coordinate));
				udi_hid_mouse_moveY((mouse_desc->y_coordinate));
			 
          
             break;
         }
         case KEYBOARD:
         {
             if(zid_report_data_record_ptr->report_type == INPUT)
             {
                 
                 keyboard_input_desc_t *keyboard_input_desc;
                 keyboard_input_desc = (keyboard_input_desc_t *)zid_report_data_record_ptr->report_data;
                    if(main_b_kbd_enable)
                    {   
						if(keyboard_input_desc->modifier_keys)
						{
							udi_hid_kbd_modifier_down(keyboard_input_desc->modifier_keys);
							udi_hid_kbd_modifier_up(keyboard_input_desc->modifier_keys);
						}
					                    
						for(uint8_t j=0;j<4;j++)
						{  
							if(keyboard_input_desc->key_code[j])
							{    
								udi_hid_kbd_down(keyboard_input_desc->key_code[j]);
								udi_hid_kbd_up(keyboard_input_desc->key_code[j]);
							}   
                   
						}
						uint16_t u_value;
						u_value= convert_byte_array_to_16_bit(&(keyboard_input_desc->key_code[4]));
						if(u_value)
						{   
							udi_hid_mkbd_modifier_down(u_value);
							udi_hid_mkbd_modifier_up(u_value);
						}
					}
              
             }
             else
             {
                /* Application can implement for other report types.*/
             }
             break;
         }
         default:
		 break;
         }
         zid_report_data_record_ptr++;
     }

    RxLinkQuality = RxLinkQuality;
    RxFlags = RxFlags;

}
Esempio n. 4
0
File: ui.c Progetto: kerichsen/asf
/**
 * \brief Process the user interface
 *
 * This function processes user touch events and updates the display.
 *
 * The first registered touch is used to control the cursor. Its presence is
 * indicated with a red frame around the display. When the cursor touch moves,
 * its movement is visualized with a trace on the display.
 *
 * The second registered touch is used to control mouse buttons, and is
 * indicated with an inner frame of which the color depends on which side the
 * touch is for: blue for left and green for right button click. The frame is
 * shown until the touch is released.
 * To detect which side click it is, the position relative to the cursor touch
 * is used, i.e., a touch to the left of the first touch will cause a left
 * mouse click.
 *
 * \param framenumber Current USB frame number
 *
 * \note This function should be called every millisecond, e.g., for each USB
 * frame.
 */
void ui_process(uint16_t framenumber)
{
	static bool process_traces = false;
	static bool register_trace = false;
	static bool left_press = true;
	static gfx_coord_t old_x;
	static gfx_coord_t old_y;
	uint16_t blink_frame;
	uint8_t new_x_pos;
	uint8_t new_y_pos;

	/* Blink LED1 at 1 Hz (toggle every 500 frames) */
	blink_frame = framenumber % 1000;
	if (blink_frame == 0) {
		LED_On(LED1_GPIO);
	} else if (blink_frame == 500) {
		LED_Off(LED1_GPIO);
	}

	/* Interleave processing of traces and touch events so they are each
	 * handled every 2 milliseconds.
	 */
	if (process_traces) {
		process_traces = false;

		/* Is there a new trace to register? */
		if (register_trace) {
			handle_trace(old_x, old_y);
		/* No new trace, clear an old one */
		} else {
			handle_trace(0, 0);
		}

		/* Return now, don't process touches */
		return;
	}

	/* Process traces in next iteration */
	process_traces = true;
	register_trace = false;

	/* Process new touch, if it was flagged */
	if (ui_new_touch_event) {
		ui_new_touch_event = false;

		/* Is event for first finger on display? */
		if (ui_touch_event.id == 0) {
			/* Upon new press, draw red frame */
			if (ui_touch_event.status & MXT_PRESS_EVENT) {
				old_x = ui_touch_event.x;
				old_y = ui_touch_event.y;
				draw_frame(0, 2, GFX_COLOR_RED);

			/* Upon release, erase red frame */
			} else if (ui_touch_event.status & MXT_RELEASE_EVENT) {
				draw_frame(0, 2, COLOR_BACKGROUND);

			/* Upon move, update mouse position and display trace */
			} else if (ui_touch_event.status & MXT_DETECT_EVENT) {
				/* Scale the relative position down to get a
				 * sensible cursor speed.
				 */
				new_x_pos = (ui_touch_event.x - old_x) >> 2;
				new_y_pos = (ui_touch_event.y - old_y) >> 2;

				udi_hid_mouse_moveX(new_x_pos);
				udi_hid_mouse_moveY(new_y_pos);

				old_x = ui_touch_event.x;
				old_y = ui_touch_event.y;

				register_trace = true;
			}
		}

		/* Is event for second finger on display? */
		if (ui_touch_event.id == 1) {
			/* For new press, signal a left or right mouse button
			 * press depending on which side of the cursor it's on
			 */
			if (ui_touch_event.status & MXT_PRESS_EVENT) {
				/* Left click? */
				if (ui_touch_event.x <= old_x) {
					left_press = true;
					udi_hid_mouse_btnleft(HID_MOUSE_BTN_DOWN);

					/* Draw a blue inner-frame */
					draw_frame(2, 2, GFX_COLOR_BLUE);

				/* Must otherwise be a right click. */
				} else {
					left_press = false;
					udi_hid_mouse_btnright(HID_MOUSE_BTN_DOWN);

					/* Draw a green inner-frame */
					draw_frame(2, 2, GFX_COLOR_GREEN);
				}
			}

			/* For release, signal release of the mouse button */
			if (ui_touch_event.status & MXT_RELEASE_EVENT) {
				if (left_press) {
					udi_hid_mouse_btnleft(HID_MOUSE_BTN_UP);
				} else {
					udi_hid_mouse_btnright(HID_MOUSE_BTN_UP);
				}

				/* Erase blue/green inner-frame */
				draw_frame(2, 2, COLOR_BACKGROUND);
			}
		}
	}