现在的位置: 首页 > 综合 > 正文

MStar Clock

2013年08月17日 ⁄ 综合 ⁄ 共 1873字 ⁄ 字号 评论关闭

需要计算每个刻度的坐标

但是MStar不支持三角函数

所以首先用VC的库,可以使用三角函数,计算出每个点的坐标,打印出来,保存到数组中

#include <math.h>
#include <stdio.h>

#define PI 3.1415926

void main()
{
	int n = 0;
	
	int radius = 120;
	int centre[2] = {160, 240};
	int point[2] = {0};
	
	int hour[2] = {0};
	int minute[2] = {0};
	int second[2] = {0};
	
	for (n = 0; n < 15; n++)
	{
		point[0] = centre[0] + radius * sin((PI / 30) * n);
		point[1] = centre[1] - radius * cos((PI / 30) * n);
		printf("{%d, %d}, ", point[0], point[1]);
	}
	for (n = 0; n < 15; n++)
	{
		point[0] = centre[0] + radius * cos((PI / 30) * n);
		point[1] = centre[1] + radius * sin((PI / 30) * n);
		printf("{%d, %d}, ", point[0], point[1]);
	}
	for (n = 0; n < 15; n++)
	{
		point[0] = centre[0] - radius * sin((PI / 30) * n);
		point[1] = centre[1] + radius * cos((PI / 30) * n);
		printf("{%d, %d}, ", point[0], point[1]);
	}
	for (n = 0; n < 15; n++)
	{
		point[0] = centre[0] - radius * cos((PI / 30) * n);
		point[1] = centre[1] - radius * sin((PI / 30) * n);
		printf("{%d, %d}, ", point[0], point[1]);
	}
}

得到这样一个数组

int clock_dot[60][2] = {
	{160, 120}, {172, 120}, {184, 122}, {197, 125}, {208, 130}, {219, 136}, {230, 142}, {240, 150}, {249, 159}, {257, 169},
	{263, 179}, {269, 191}, {274, 202}, {277, 215}, {279, 227}, {280, 240}, {279, 252}, {277, 264}, {274, 277}, {269, 288},
	{263, 299}, {257, 310}, {249, 320}, {240, 329}, {230, 337}, {220, 343}, {208, 349}, {197, 354}, {184, 357}, {172, 359},
	{160, 360}, {147, 359}, {135, 357}, {122, 354}, {111, 349}, {100, 343}, {89, 337}, {79, 329}, {70, 320}, {62, 310},
	{56, 300}, {50, 288}, {45, 277}, {42, 264}, {40, 252}, {40, 240}, {40, 227}, {42, 215}, {45, 202}, {50, 191},
	{56, 180}, {62, 169}, {70, 159}, {79, 150}, {89, 142}, {99, 136}, {111, 130}, {122, 125}, {135, 122}, {147, 120}
};

再使用画点函数画出点

for (n = 0; n < 60; n++)
{
	ven_graphics_drawPoint(g_HelloWorldCanvas, clock_dot[n][0], clock_dot[n][1]);
}

获取系统时间函数ven_time_ret_t *ven_time_getLocalTime(ven_time_format_t pLocalTime)

返回值:VEN_TIME_RET_FAILED 失败,VEN_TIME_RET_SUCCESS
成功,VEN_TIME_RET_BAD_PARAM 入参无效

 

定时器:

u16 ven_os_createTimer(ven_os_timeout_callback timeout); 

//成功返回TimerID,失败返回0

s32 ven_os_startTimer(u16 TimerId, bool bCyclic, u32 nHandle, u32 time_ms);

//成功返回1,失败返回-1

//bCyclic值为1时,该函数可写在回调函数外,自动循环调用回调函数,为0时,需要写在回调函数中,通过回调函数本身调用

 

抱歉!评论已关闭.