123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- /********************************************************************************
- * File Name: Radio.c
- * Function Describe: select button
- * Relate Module: lcd.c,lcd.h,Key.c,Key.h,Radio.h
- * Explain:
- * Writer: LiuYanZhi
- * Date: 2003-12-14
- * Rewriter:
- * Date:
- *******************************************************************************/
- #include <string.h>
- #include "lcd.h"
- #include "KeyLed.h"
- #include "Radio.h"
- void RadioShowItem(struct SUT_RADIO *p,unsigned char handle);
- void RadioShowBlock(struct SUT_RADIO *p,unsigned char handle);
- /********************************************************************************
- * Function:RadioInit
- * initialize Radio struct
- *******************************************************************************/
- void RadioInit
- (
- struct SUT_RADIO *p,
- unsigned short x,
- unsigned char y,
- char **item,
- unsigned char rows
- )
- {
- unsigned char i,j;
- p->x = x;
- p->y = y;
- p->item = item;
- p->rows = rows;
- i = 0; //get width and itemnum
- p->width = 0;
- for(;;)
- {
- j = strlen(p->item[i]);
- if(j == 0)break;
- if(j > p->width)p->width = j;
- i ++;
- }
- p->itemnum = i;
- p->width += 4;
- if(p->handle >= p->itemnum)
- p->handle = 0;
- }
- /********************************************************************************
- * Function:RadioShow
- * display Radio
- *******************************************************************************/
- void RadioShow(struct SUT_RADIO *p)
- {
- unsigned char i;
- for(i = 0 ; i < p->itemnum ; i ++)
- {
- RadioShowItem(p,i);
- if(i == p->handle)RadioShowBlock(p,i);
- }
- }
- /********************************************************************************
- * Function:RadioShowItem
- * display Radio item
- *******************************************************************************/
- void RadioShowItem(struct SUT_RADIO *p,unsigned char handle)
- {
- unsigned short x;
- unsigned char y;
- x = handle / p->rows;
- x *= p->width * 8;
- x += ((p->x) >> 3) * 8;
- y = handle % p->rows;
- y *= 24;
- y += p->y;
- LcdShowRect(x,y+1,x+12,y+13,0x01);
- LcdShowStr(x+24,y,p->item[handle],0x01);
- }
- /********************************************************************************
- * Function:RadioShowBlock
- * display Radio item select flag
- *******************************************************************************/
- void RadioShowBlock(struct SUT_RADIO *p,unsigned char handle)
- {
- unsigned short x;
- unsigned char y;
- unsigned char i;
- x = handle / p->rows;
- x *= p->width * 8;
- x += ((p->x) >> 3) * 8 + 2;
- y = handle % p->rows;
- y *= 24;
- y += p->y + 3;
- for(i = 0 ; i < 9 ; i ++)
- {
- LcdShowRect(x,y+i,x+8,y+i,0x01);
- }
- }
- /********************************************************************************
- * Function:RadioGetHandle
- *******************************************************************************/
- unsigned char RadioGetHandle(struct SUT_RADIO *p)
- {
- return p->handle;
- }
- /********************************************************************************
- * Function:RadioResponse
- *******************************************************************************/
- unsigned char RadioResponse(struct SUT_RADIO *p)
- {
- switch(g_ucKeyValue)
- {
- case KEY_UP:
- RadioShowBlock(p,p->handle);
- if(p->handle <= 0)p->handle = p->itemnum - 1;
- else p->handle --;
- RadioShowBlock(p,p->handle);
- break;
- case KEY_DOWN:
- RadioShowBlock(p,p->handle);
- p->handle ++;
- if(p->handle >= p-> itemnum)p->handle = 0;
- RadioShowBlock(p,p->handle);
- break;
- case KEY_LEFT:
- if(p->handle < p->rows)break;
- RadioShowBlock(p,p->handle);
- p->handle -= p->rows;
- RadioShowBlock(p,p->handle);
- break;
- case KEY_RIGHT:
- if((p->handle + p->rows) >= p->itemnum)break;
- RadioShowBlock(p,p->handle);
- p->handle += p->rows;
- RadioShowBlock(p,p->handle);
- break;
- case KEY_BACK:
- return 1;
- case KEY_ENTER:
- return 2;
- default:
- break;
- }
- return 0;
- }
- /********************************************************************************
- * End of Module
- *******************************************************************************/
|