Radio.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /********************************************************************************
  2. * File Name: Radio.c
  3. * Function Describe: select button
  4. * Relate Module: lcd.c,lcd.h,Key.c,Key.h,Radio.h
  5. * Explain:
  6. * Writer: LiuYanZhi
  7. * Date: 2003-12-14
  8. * Rewriter:
  9. * Date:
  10. *******************************************************************************/
  11. #include <string.h>
  12. #include "lcd.h"
  13. #include "KeyLed.h"
  14. #include "Radio.h"
  15. void RadioShowItem(struct SUT_RADIO *p,unsigned char handle);
  16. void RadioShowBlock(struct SUT_RADIO *p,unsigned char handle);
  17. /********************************************************************************
  18. * Function:RadioInit
  19. * initialize Radio struct
  20. *******************************************************************************/
  21. void RadioInit
  22. (
  23. struct SUT_RADIO *p,
  24. unsigned short x,
  25. unsigned char y,
  26. char **item,
  27. unsigned char rows
  28. )
  29. {
  30. unsigned char i,j;
  31. p->x = x;
  32. p->y = y;
  33. p->item = item;
  34. p->rows = rows;
  35. i = 0; //get width and itemnum
  36. p->width = 0;
  37. for(;;)
  38. {
  39. j = strlen(p->item[i]);
  40. if(j == 0)break;
  41. if(j > p->width)p->width = j;
  42. i ++;
  43. }
  44. p->itemnum = i;
  45. p->width += 4;
  46. if(p->handle >= p->itemnum)
  47. p->handle = 0;
  48. }
  49. /********************************************************************************
  50. * Function:RadioShow
  51. * display Radio
  52. *******************************************************************************/
  53. void RadioShow(struct SUT_RADIO *p)
  54. {
  55. unsigned char i;
  56. for(i = 0 ; i < p->itemnum ; i ++)
  57. {
  58. RadioShowItem(p,i);
  59. if(i == p->handle)RadioShowBlock(p,i);
  60. }
  61. }
  62. /********************************************************************************
  63. * Function:RadioShowItem
  64. * display Radio item
  65. *******************************************************************************/
  66. void RadioShowItem(struct SUT_RADIO *p,unsigned char handle)
  67. {
  68. unsigned short x;
  69. unsigned char y;
  70. x = handle / p->rows;
  71. x *= p->width * 8;
  72. x += ((p->x) >> 3) * 8;
  73. y = handle % p->rows;
  74. y *= 24;
  75. y += p->y;
  76. LcdShowRect(x,y+1,x+12,y+13,0x01);
  77. LcdShowStr(x+24,y,p->item[handle],0x01);
  78. }
  79. /********************************************************************************
  80. * Function:RadioShowBlock
  81. * display Radio item select flag
  82. *******************************************************************************/
  83. void RadioShowBlock(struct SUT_RADIO *p,unsigned char handle)
  84. {
  85. unsigned short x;
  86. unsigned char y;
  87. unsigned char i;
  88. x = handle / p->rows;
  89. x *= p->width * 8;
  90. x += ((p->x) >> 3) * 8 + 2;
  91. y = handle % p->rows;
  92. y *= 24;
  93. y += p->y + 3;
  94. for(i = 0 ; i < 9 ; i ++)
  95. {
  96. LcdShowRect(x,y+i,x+8,y+i,0x01);
  97. }
  98. }
  99. /********************************************************************************
  100. * Function:RadioGetHandle
  101. *******************************************************************************/
  102. unsigned char RadioGetHandle(struct SUT_RADIO *p)
  103. {
  104. return p->handle;
  105. }
  106. /********************************************************************************
  107. * Function:RadioResponse
  108. *******************************************************************************/
  109. unsigned char RadioResponse(struct SUT_RADIO *p)
  110. {
  111. switch(g_ucKeyValue)
  112. {
  113. case KEY_UP:
  114. RadioShowBlock(p,p->handle);
  115. if(p->handle <= 0)p->handle = p->itemnum - 1;
  116. else p->handle --;
  117. RadioShowBlock(p,p->handle);
  118. break;
  119. case KEY_DOWN:
  120. RadioShowBlock(p,p->handle);
  121. p->handle ++;
  122. if(p->handle >= p-> itemnum)p->handle = 0;
  123. RadioShowBlock(p,p->handle);
  124. break;
  125. case KEY_LEFT:
  126. if(p->handle < p->rows)break;
  127. RadioShowBlock(p,p->handle);
  128. p->handle -= p->rows;
  129. RadioShowBlock(p,p->handle);
  130. break;
  131. case KEY_RIGHT:
  132. if((p->handle + p->rows) >= p->itemnum)break;
  133. RadioShowBlock(p,p->handle);
  134. p->handle += p->rows;
  135. RadioShowBlock(p,p->handle);
  136. break;
  137. case KEY_BACK:
  138. return 1;
  139. case KEY_ENTER:
  140. return 2;
  141. default:
  142. break;
  143. }
  144. return 0;
  145. }
  146. /********************************************************************************
  147. * End of Module
  148. *******************************************************************************/