예제 #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();
	}
}
예제 #2
0
파일: main.c 프로젝트: Timvrakas/samd21_gcc
/**
 * \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();
	}
}
예제 #3
0
파일: demo.c 프로젝트: thegeek82000/asf
/**
 * \brief This task, when activated, send every ten seconds on debug UART the
 * whole report of free heap and total tasks status
 */
static void task_win(void *pvParameters)
{
	uint32_t hour, minute, second;
	uint32_t year, month, date,week;

	uint8_t uc_result;

	UNUSED(pvParameters);

	for (;;) {
		while (demo_get_special_mode_status(DEMO_LCD_CALIBRATE_MODE)) {
			app_widget_settings_on(false);
			uc_result = rtouch_calibrate();
			if (uc_result == 0) {
				demo_set_special_mode_status(
						DEMO_LCD_CALIBRATE_MODE, 0);
				app_widget_settings_on(true);
				puts("Calibration successful !\r");
				break;
			} else {
				puts("Calibration failed; error delta is too big ! Please retry calibration procedure...\r");
			}
		}

		if (demo_get_special_mode_status(DEMO_WAIT_MODE) ||
				demo_get_special_mode_status(DEMO_SLEEP_MODE)) {
			app_widget_lpm_on(true);
			demo_set_special_mode_status(DEMO_WAIT_MODE, 0);
			demo_set_special_mode_status(DEMO_SLEEP_MODE, 0);
		}

		/* Play PPT */
		if (demo_get_special_mode_status(DEMO_PPT_MODE)) {
			demo_start_adc(true);
			if (pontentiometer_value == ppt_delay_clapse_counter) {
				snprintf( ppt_slide_path,
						sizeof(ppt_slide_path),
						"%s%s%s%u%s",
						SCR_PPT_SLIDE_PATH,
						SCR_PPT_SLIDE_FOLDER,
						SCR_PPT_SLIDE_BASENAME,
						ppt_silder_index,
						SCR_PPT_SLIDE_EXT );

				demo_ppt.data.custom = ppt_slide_path;

				gfx_draw_bitmap(&demo_ppt, 0, 0);
				ppt_delay_clapse_counter = 0;
				ppt_silder_index++;

				if (ppt_silder_index >= SCR_PPT_SLIDE_MAX) {
					ppt_silder_index = 0;
				}
			}

			ppt_delay_clapse_counter++;

			continue;
		}

		if (touch_event_on_ppt == 1) {
			app_widget_main_on(true);
			touch_event_on_ppt = 0;
		}

		demo_qtouch_event_handler();
		/* Process queued events in the windowing system */
		win_process_events();

		if (demo_get_special_mode_status(DEMO_MAIN_MODE)) {
			/* Retrieve date and time */
			rtc_get_time( RTC, &hour, &minute, &second );
			snprintf( demo_cur_time, sizeof(demo_cur_time),
					"%02u:%02u:%02u",
					hour, minute, second );
			/* Draw the time text */
			gfx_draw_string(demo_cur_time, 15, 300,
					&sysfont, COLOR_WHITE, COLOR_WHITE);
			gfx_draw_string(demo_cur_time, 15, 300,
					&sysfont, GFX_COLOR_TRANSPARENT,
					COLOR_BLUE);

			/* Retrieve date and time */
			rtc_get_date( RTC, &year, &month, &date, &week );
			snprintf( demo_cur_date, sizeof(demo_cur_date),
					"%04u/%02u/%02u",
					year, month, date );
			/* Draw the help text */
			gfx_draw_string(demo_cur_date, 135, 300,
					&sysfont, COLOR_WHITE, COLOR_WHITE);
			gfx_draw_string(demo_cur_date, 135, 300,
					&sysfont, GFX_COLOR_TRANSPARENT,
					COLOR_BLUE);
		}

		vTaskDelay(100);
	}
}