123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- /********************************************************************************
- * File Name: Spin.c
- * Function Describe:
- * Relate Module: lcd.c,lcd.h,Key.c,Key.h
- * Explain:
- * Writer: LiuYanZhi
- * Date: 2003-11-7
- * Rewriter:
- * Date:
- *******************************************************************************/
- #include <string.h>
- #include <stdio.h>
- #include "lcd.h"
- #include "KeyLed.h"
- #include "Spin.h"
- /********************************************************************************
- * Function:SpinInit
- * initialize spin struct
- *******************************************************************************/
- void SpinInit
- (
- struct SUT_SPIN *p,
- unsigned short x,
- unsigned char y,
- char **item
- )
- {
- unsigned char i;
- p->x = x;
- p->y = y;
- p->item = item;
- p->itemnum = 0;
- i = 0;
- p->width = 0;
- for(;;)
- {
- if(strlen(p->item[i]) == 0)break;
- if(strlen(p->item[i]) > p->width)
- p->width = strlen(p->item[i]);
- i++;
- p->itemnum ++;
- }
- p->top = 0;
- p->bottom = p->itemnum - 1;
- if(p->handle < p->top)p->handle = p->top;
- if(p->handle > p->bottom)p->handle = p->bottom;
- p->focus = 0;
- p->disable = 0;
- p->keyflag = 0;
- p->type = 0;
- p->step = 1;
- }
- /********************************************************************************
- * Function:SpinInitData
- * initialize spin struct to data mode
- *******************************************************************************/
- void SpinInitData
- (
- struct SUT_SPIN *p,
- unsigned short x,
- unsigned char y,
- unsigned char width,
- short min,
- short max,
- short step,
- char *unit
- )
- {
- p->x = x;
- p->y = y;
- p->width = width;
- p->top = min;
- p->bottom = max;
- p->unit = unit;
- p->step = step;
- if(p->handle < p->top || p->handle > p->bottom)
- p->handle = p->top;
- p->focus = 0;
- p->disable = 0;
- p->keyflag = 0;
- p->type = 1;
- }
- /********************************************************************************
- * Function:SpinSetPage
- *******************************************************************************/
- void SpinSetRange(struct SUT_SPIN *p,short top,short bottom)
- {
- p->top = top;
- p->bottom = bottom;
- if(p->type == 0)
- {
- if(p->top >= p->itemnum)p->top = p->itemnum - 1;
- if(p->bottom >= p->itemnum)p->bottom = p->itemnum - 1;
- if(p->bottom < p->top)p->bottom = p->top;
- }
- if(p->handle < p->top)p->handle = p->top;
- if(p->handle > p->bottom)p->handle = p->bottom;
- }
- /********************************************************************************
- * Function:SpinSetFocus
- *******************************************************************************/
- void SpinSetFocus(struct SUT_SPIN *p)
- {
- if(p->disable)return;
- if(p->focus)return;
- p->focus = 1;
- LcdReverseBar(p->x,p->y-1,p->x+(p->width-1)*8,p->y+16);
- }
- /********************************************************************************
- * Function:SpinLoseFocus
- *******************************************************************************/
- void SpinLoseFocus(struct SUT_SPIN *p)
- {
- if(p->disable)return;
- if(!p->focus)return;
- p->focus = 0;
- LcdReverseBar(p->x,p->y-1,p->x+(p->width-1)*8,p->y+16);
- }
- /********************************************************************************
- * Function:SpinShow
- * show spin
- *******************************************************************************/
- void SpinShow(struct SUT_SPIN *p)
- {
- unsigned char x;
- char buffer[20];
- LcdClearArea(p->x,p->y,p->x+(p->width-1)*8,p->y+16);
- if(p->type == 0)
- {
- if(p->disable)LcdShowStr(p->x,p->y,p->item[p->handle],0x03);
- else LcdShowStr(p->x,p->y,p->item[p->handle],0x01);
- if(p->disable)return;
- }
- else
- {
- sprintf(buffer,"%d",p->handle);
- strcat(buffer,p->unit);
- x = strlen(buffer);
- if(x > p->width)
- {
- x = p->width;
- buffer[x] = 0;
- }
- x = (p->width - x) / 2;
- LcdShowStr(p->x+x*8,p->y,buffer,0x00);
- }
- if(p->focus)LcdReverseBar(p->x,p->y-1,p->x+(p->width-1)*8,p->y+16);
- }
- /********************************************************************************
- * Function:SpinShowBorder
- *******************************************************************************/
- void SpinShowBorder(struct SUT_SPIN *p)
- {
- unsigned short x;
- unsigned char width;
- x = (p->x >> 3) * 8;
- width = p->width * 8;
- LcdShowRect(x-1,p->y-2,x+width,p->y+17,0x01);
- }
- /********************************************************************************
- * Function:SpinGetHandle
- * get spin's handle
- *******************************************************************************/
- short SpinGetHandle(struct SUT_SPIN *p)
- {
- return p->handle;
- }
- /********************************************************************************
- * Function:SpinResponse
- * spin response
- *******************************************************************************/
- unsigned char SpinResponse(struct SUT_SPIN *p)
- {
- unsigned char task;
- if(p->disable)return 0;
- if(!p->focus)return 0;
- task = 0xFF;
- switch(g_ucKeyValue)
- {
- case KEY_UP:
- if(p->keyflag)task = 2;
- else task = 0;
- break;
- case KEY_DOWN:
- if(p->keyflag)task = 3;
- else task = 1;
- break;
- case KEY_LEFT:
- if(p->keyflag)task = 0;
- else task = 2;
- break;
- case KEY_RIGHT:
- if(p->keyflag)task = 1;
- else task = 3;
- break;
- case KEY_BACK:
- return 1;
- case KEY_ENTER:
- return 2;
- default:
- break;
- }
- switch(task)
- {
- case 0:
- LcdReverseBar(p->x,p->y-1,p->x+(p->width-1)*8,p->y+16);
- if((p->handle - p->step) < p->top)p->handle = p->bottom;
- else p->handle -= p->step;
- SpinShow(p);
- break;
- case 1:
- LcdReverseBar(p->x,p->y-1,p->x+(p->width-1)*8,p->y+16);
- if((p->handle + p->step) > p->bottom)p->handle = p->top;
- else p->handle += p->step;
- SpinShow(p);
- break;
- case 2:
- return 3;
- // break;
- case 3:
- return 4;
- //break;
- }
- return 0;
- }
- void SpinSetNext(struct SUT_SPIN *p)
- {
- LcdReverseBar(p->x,p->y-1,p->x+(p->width-1)*8,p->y+16);
- if(p->handle >= p->bottom)p->handle = p->top;
- else p->handle += p->step;
- SpinShow(p);
- }
- /********************************************************************************
- * End of focus
- *******************************************************************************/
|