Esempio n. 1
0
void calibration_entry(void* parameter)
{
    rt_mq_t mq;
    rtgui_win_t* win;
    struct rtgui_rect rect;

    mq = rt_mq_create("cali", 40, 8, RT_IPC_FLAG_FIFO);
    if (mq == RT_NULL) return;

    rtgui_thread_register(rt_thread_self(), mq);

    rtgui_graphic_driver_get_default_rect(&rect);

    /* set screen rect */
    calibration_ptr->width = rect.x2;
    calibration_ptr->height = rect.y2;

    /* create calibration window */
    win = rtgui_win_create(RT_NULL,
                           "calibration", &rect, RTGUI_WIN_STYLE_NO_TITLE | RTGUI_WIN_STYLE_NO_BORDER);
    rtgui_widget_set_event_handler(RTGUI_WIDGET(win), calibration_event_handler);
    if (win != RT_NULL)
    {
        rtgui_win_show(win, RT_FALSE);
        // rtgui_widget_update(RTGUI_WIDGET(win));
        rtgui_win_event_loop(win);
    }

    rtgui_thread_deregister(rt_thread_self());
    rt_mq_delete(mq);

    /* set calibration data */
    rt_device_control(calibration_ptr->device, RT_TOUCH_CALIBRATION_DATA, &calibration_ptr->data);

    /* recover to normal */
    rt_device_control(calibration_ptr->device, RT_TOUCH_NORMAL, RT_NULL);

    /* release memory */
    rt_free(calibration_ptr);
    calibration_ptr = RT_NULL;
}
Esempio n. 2
0
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
    if (event->type == RTGUI_EVENT_PAINT)
    {
        struct rtgui_dc* dc;
        struct rtgui_rect rect;
        rtgui_image_t *background;

		/* draw child */
		rtgui_view_event_handler(widget, event);

        dc = rtgui_dc_begin_drawing(widget);
        if (dc == RT_NULL) return RT_FALSE;
        rtgui_widget_get_rect(widget, &rect);

        /* draw background */
        background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE);
        if (background != RT_NULL)
        {
            rtgui_image_blit(background, dc, &rect);
            rtgui_image_destroy(background);
        }
        else
        {
            rtgui_dc_fill_rect(dc, &rect);
        }

        /* draw playing information */
		player_update_tag_info();

        rtgui_dc_end_drawing(dc);

        return RT_FALSE;
    }
    else if (event->type == RTGUI_EVENT_KBD)
    {
        struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
        if (ekbd->type == RTGUI_KEYDOWN)
        {
        	if ((ekbd->key == RTGUIK_LEFT) || (ekbd->key == RTGUIK_RIGHT))
        	{
        		if (player_mode == PLAYER_STOP)
        		{
                    rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
        		}
        		else
        		{
        			rt_device_t dev = rt_device_find("snd");
        			if (ekbd->key == RTGUIK_LEFT && radio_setup.default_volume > 0)
        			{
        				radio_setup.default_volume--;
        				rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume);
        			}
        			else if (ekbd->key == RTGUIK_RIGHT && radio_setup.default_volume < CODEC_VOLUME_MAX)
        			{
        				radio_setup.default_volume++;
        				rt_device_control(dev, CODEC_CMD_VOLUME, &radio_setup.default_volume);
        			}
        		}
        	}
			else
			{
				return RTGUI_WIDGET(music_listbox)->event_handler(RTGUI_WIDGET(music_listbox), event);
			}
        }
        return RT_FALSE;
    }
	else if (event->type == RTGUI_EVENT_MOUSE_BUTTON)
	{
		struct rtgui_event_mouse* emouse;

		emouse = (struct rtgui_event_mouse*)event;
		if (emouse->button & RTGUI_MOUSE_BUTTON_UP)
		{
			if (rtgui_rect_contains_point(&next_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(NEXT_BUTTON);
			else if (rtgui_rect_contains_point(&prev_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(PREV_BUTTON);
			else if (rtgui_rect_contains_point(&playing_btn_rect, emouse->x, emouse->y) == RT_EOK)
				player_onbutton(PLAYING_BUTTON);
		}
	}
    else if (event->type == RTGUI_EVENT_COMMAND)
    {
        struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;

        switch (ecmd->command_id)
        {
        case PLAYER_REQUEST_PLAY_SINGLE_FILE:
        case PLAYER_REQUEST_PLAY_LIST:
            rtgui_timer_start(info_timer);
			return RT_TRUE;

        case PLAYER_REQUEST_STOP:
        {
			struct play_item *item = RT_NULL;

			/* if it's radio mode, set next mode to stop */
			if (player_mode == PLAYER_PLAY_RADIO)
				next_step = PLAYER_STEP_STOP;

			/* set player mode */
			player_mode = PLAYER_STOP;

			switch (next_step)
			{
			case PLAYER_STEP_NEXT:
				/* play next */
				item = play_list_next(play_list_get_mode());
				break;
			case PLAYER_STEP_PREV:
				/* play prev */
				item = play_list_prev(play_list_get_mode());
				break;
			case PLAYER_STEP_SEEK:
				/* play current item */
				item = play_list_current();
			}

			if (item != RT_NULL)
				player_play_item(item);
			else
			{
				player_mode = PLAYER_STOP;
				rtgui_timer_stop(info_timer);
			}

			/* update tag information */
			player_update_tag_info();
        }
		return RT_TRUE;

        case PLAYER_REQUEST_FREEZE:
        {
            /* stop play */
            if (player_is_playing() == RT_TRUE)
            {
                player_stop();
            }

            /* delay some tick */
            rt_thread_delay(50);

            /* show a modal view */
            {
                rtgui_view_t *view;
                rtgui_label_t *label;
                rtgui_rect_t rect = {0, 0, 150, 150}, container_rect;

                rtgui_graphic_driver_get_default_rect(&container_rect);
                /* set centre */
                rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
                view = rtgui_view_create("USB");
                rtgui_workbench_add_view(workbench, view);

                /* set container to window rect */
                container_rect = rect;

                rect.x1 = 0;
                rect.y1 = 0;
                rect.x2 = 120;
                rect.y2 = 20;
                label = rtgui_label_create("USB 联机中...");
                rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
                rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
                rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));

                rtgui_view_show(view, RT_TRUE);
                /* never reach hear */
            }
        }

		case PLAYER_REQUEST_UPDATE_INFO:
			/* update status information */
			player_update_tag_info();
			return RT_TRUE;

        default:
            break;
        }

        return RT_FALSE;
    }

    return rtgui_view_event_handler(widget, event);
}