Ejemplo n.º 1
0
/**
 * \brief Main application function
 *
 * This function calls all the necessary initialization functions before
 * launching the calculator widget and entering the main work loop.
 *
 * The main work loop is responsible for handling the low level user input, so
 * it reads touch data from the mXT143E Xplained, translates and passes it on to
 * the window system's event queue.
 *
 * All the processing for the calculator is done by the calculator widget's
 * event handler function \ref app_calc_handler(). This function is called by
 * the window system when it maps a user input event to an interaction with the
 * calculator, i.e., a button press.
 */
int main(void)
{
	static struct mxt_device device;

	board_init();
	sysclk_init();
	membag_init();

	gfx_init();
	mxt_init(&device);
	win_init();

	setup_gui_root_window();
	win_reset_root_geometry();
	if (app_widget_launch() == false) {
		show_out_of_memory_error();
		for (;;);
	}

	while (true) {
		struct win_pointer_event win_touch_event;

		/* Queue touch events from the touchscreen if any are available */
		while (read_touch_event(&device, &win_touch_event)) {
			win_queue_pointer_event(&win_touch_event);
		}

		/* Process queued events in the windowing system */
		win_process_events();
	}
}
Ejemplo n.º 2
0
/**
 * \brief Main application function
 *
 * This function executes the necessary initialization calls and displays the
 * demo widgets before entering the main work loop of the application.
 *
 * The main work loop reads out the touch events from the mXT143E Xplained and
 * enqueues the corresponding touch events in the window system, before
 * processing the window system's event queue.
 */
int main(void)
{
	static struct mxt_device device;

	board_init();
	sysclk_init();
	membag_init();
	gfx_init();
	mxt_init(&device);
	win_init();

	setup_root_window();
	app_widget_launch();

	while (true) {
		/* Process received messages from the maXTouch device */
		while (mxt_is_message_pending(&device)) {
			struct mxt_touch_event touch_event;
			struct win_pointer_event win_touch_event;

			/* Get the first touch event in queue */
			if (mxt_read_touch_event(&device,
					&touch_event) != STATUS_OK) {
				continue;
			}

			/* Translate touch event type into a WTK event type */
			if (touch_event.status & MXT_PRESS_EVENT) {
				win_touch_event.type = WIN_POINTER_PRESS;
			} else if (touch_event.status & MXT_MOVE_EVENT) {
				win_touch_event.type = WIN_POINTER_MOVE;
			} else if (touch_event.status & MXT_RELEASE_EVENT) {
				win_touch_event.type = WIN_POINTER_RELEASE;
			} else {
				continue;
			}

			/* Indicate the touch event is a non-relative movement
			 * with the virtual touch button pressed
			 */
			win_touch_event.is_relative = false;
			win_touch_event.buttons = WIN_TOUCH_BUTTON;

			/* Translate the touch X and Y position into a screen
			 * coordinate
			 */
			win_touch_event.pos.x =
					((uint32_t)(4096 - touch_event.x) * gfx_get_width()) / 4096;
			win_touch_event.pos.y =
					((uint32_t)(4096 - touch_event.y) * gfx_get_height()) / 4096;
			win_queue_pointer_event(&win_touch_event);
		}

		/* Process queued events in the windowing system */
		win_process_events();
	}
}
Ejemplo n.º 3
0
/*
 * \brief Callback called when the pen is pressed on the touchscreen.
 *
 * \param event Pointer to the touch event.
 */
static void event_handler(rtouch_event_t const *event)
{
	struct win_pointer_event win_touch_event;

	switch (event->type) {
	case RTOUCH_MOVE:
		win_touch_event.type = WIN_POINTER_MOVE;
		break;

	case RTOUCH_PRESS:
		win_touch_event.type = WIN_POINTER_PRESS;
		break;

	case RTOUCH_RELEASE:
		win_touch_event.type = WIN_POINTER_RELEASE;

		/* If in PPT mode, clear the PPT mode and set the
		  * touch_event_on_ppt flag to exist ppt mode in win task.*/
		if (demo_get_special_mode_status(DEMO_PPT_MODE)) {
			demo_set_special_mode_status(DEMO_PPT_MODE, 0);
			demo_start_adc(false);
			touch_event_on_ppt = 1;
			return;
		}

		/* If in FFT mode, clear the FFT mode flag to back to main. */
		if (demo_get_special_mode_status(DEMO_FFT_MODE)) {
			demo_set_special_mode_status(DEMO_FFT_MODE, 0);

			/* Return directly */
			return;
		}

		break;

	default:
		/* None pointer event received, exist evnet handler. */
		return;
	}

	/* Queue the touch move, press or release event to wtk service. */
	win_touch_event.is_relative = false;
	win_touch_event.buttons = WIN_TOUCH_BUTTON;

	/* Translate the touch X and Y position into a screen coordinate */
	win_touch_event.pos.x
		= (uint32_t)event->panel.x;
	win_touch_event.pos.y
		= (uint32_t)event->panel.y;
	win_queue_pointer_event(&win_touch_event);
}