/******************************************************************************** * 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 #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 *******************************************************************************/