Пример #1
0
/**
 * @brief  Main Function
 */
int main (void) {

  SystemInit();                            /* initialize system               */

  LED_init();

  idxCur = 0;                              /* current led position from 0..7  */
  idxOld = 0;                              /* old     led position from 0..7  */
  dir    = 1;                              /* direction for switching the LED */
  LED_On (idxCur);                         /* switch on  first LED            */

  BUTTON_init();

  while (1);
}
Пример #2
0
/*
	按照pButton描述的方式显示一个button
		在函数执行过程中,带入的按键的宽和高可能会被改变
			当文字要求的宽度或高度大于按钮提供的宽度或高度时,按钮的宽度或高度会增加到文字的宽度或高度
		在函数执行过程中,按键的xStart和yStart属性会被初始化
		如果函数成功的将按钮绘制到屏幕上,则同时将该按钮添加到按钮链表中
		函数可能会绘制按键失败:	按键的要求宽度或高度与其显示位置的综合使按钮显示在了屏幕之外.
*/
BUTTON* BUTTON_draw_button(U32 xStart, U32 yStart, BUTTON *pButton)
{
	U16 fontWidth = FONT_get_string_width(pButton->content, FontFormat.fontType);				//获得字符串的宽度
	U16 fontHigh  = FONT_get_lib_info(FontFormat.fontType)->fontHigh;                           //获得字体的高度
	
	U32 oldColor; 		//旧颜色
	U32 oldBackColor;   //新颜色

	pButton->xStart = xStart;
	pButton->yStart = yStart;
	//pButton->buttonWidth = fontWidth > pButton->buttonWidth ? fontWidth + 10: pButton->buttonWidth;
	//pButton->buttonHigh = fontHigh > pButton->buttonHigh ? fontHigh + 10:pButton-> buttonHigh;
	
	//如果指定的位置导致按钮会被显示在屏幕外面,则不显示,并返回0
	if(pButton->xStart+pButton->buttonWidth > SCREEN_SIZE_X || pButton->yStart + pButton->buttonHigh > SCREEN_SIZE_Y)
		return null;
	
	LCD_draw_rectangle(xStart, yStart, 
						pButton->buttonWidth, 
							pButton->buttonHigh, 
								pButton->buttonColor);
	
	oldColor = LCD_set_font_color(pButton->fontColor);  				//设置新颜色,保存旧颜色
	oldBackColor = LCD_set_font_backColor(pButton->buttonColor);		//设置新背景色,保存旧背景色
	
	xStart = xStart + (pButton->buttonWidth - fontWidth)/2;    			//获得字体的x起始显示位置
	yStart = yStart + (pButton->buttonHigh - fontHigh)/2;				//获得字体的y起始显示位置
	
	LCD_printf(xStart, yStart, pButton->content);       //显示文字
	LCD_set_font_backColor(oldBackColor);								//恢复原来的字体背景色
	LCD_set_font_color(oldColor);                       //恢复原来的字体颜色

	//如果显示成功,则将该按键加入到按键链表中
	if(PButtonList == null)
		BUTTON_init();
	
	BTNLIST_insert_button(pButton, PButtonList);
	
	return pButton;										//返回这个按键
}