在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
芯片精品文章合集(500篇!) 创芯人才网--重磅上线啦!
查看: 3712|回复: 7

[讨论] stm32 红牛开发板 4.3触屏问题

[复制链接]
发表于 2012-9-27 16:21:49 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
跪求帮助!!!
本人在购买红牛开发板时,有一个UCGUI+UCOS+4.3触屏实验,下载实验时发现有触点乱飞现象!!!
希望各位大侠能够指点指点!!!
有相关资料跪求共享!!!
发表于 2012-9-28 23:33:24 | 显示全部楼层
无图无真相?
发表于 2013-8-17 18:08:40 | 显示全部楼层
红牛开发板?
发表于 2013-9-13 21:11:07 | 显示全部楼层
红牛开发板  多少米啊》???
发表于 2013-9-28 14:05:46 | 显示全部楼层
感觉触摸屏有问题哦
发表于 2013-10-12 19:21:04 | 显示全部楼层
没用过这个
发表于 2014-1-5 10:54:59 | 显示全部楼层






  1. #include "stdint.h"
  2. #include "stdbool.h"
  3. #include "time.h"
  4. #include "math.h"
  5. #include "string.h"
  6. #include "stdlib.h"

  7. #include "inc/hw_memmap.h"
  8. #include "inc/tm4c123gh6pm.h"
  9. #include "inc/hw_nvic.h"
  10. #include "inc/hw_sysctl.h"
  11. #include "inc/hw_types.h"
  12. #include "driverlib/fpu.h"
  13. #include "driverlib/gpio.h"
  14. #include "driverlib/flash.h"
  15. #include "driverlib/sysctl.h"
  16. #include "driverlib/systick.h"
  17. #include "driverlib/uart.h"
  18. #include "driverlib/udma.h"
  19. #include "driverlib/rom.h"
  20. #include "driverlib/interrupt.h" // INT_TIMER0A
  21. #include "driverlib/timer.h"     // timer functions
  22. #include "driverlib/adc.h"       // ADC functions

  23. #include "grlib/grlib.h"
  24. #include "grlib/widget.h"
  25. #include "grlib/canvas.h"
  26. #include "grlib/checkbox.h"
  27. #include "grlib/container.h"
  28. #include "grlib/pushbutton.h"
  29. #include "grlib/radiobutton.h"
  30. #include "grlib/slider.h"
  31. #include "utils/ustdlib.h"
  32. #include "Kentec320x240x16_ssd2119_8bit.h"
  33. #include "touch.h"
  34. #include "images.h"
  35. #include "stripchartwidget.h"


  36. //*****************************************************************************
  37. // The error routine that is called if the driver library encounters an error.
  38. //*****************************************************************************
  39. #ifdef DEBUG
  40. void    __error__(char *pcFilename, uint32_t ulLine)
  41. {
  42. }
  43. #endif

  44. //*****************************************************************************
  45. // The DMA control structure table.
  46. //*****************************************************************************
  47. #ifdef ewarm
  48.         #pragma data_alignment=1024
  49.         tDMAControlTable sDMAControlTable[64];
  50. #elif defined(ccs)
  51.         #pragma DATA_ALIGN(sDMAControlTable, 1024)
  52.         tDMAControlTable sDMAControlTable[64];
  53. #else
  54.         tDMAControlTable sDMAControlTable[64] __attribute__ ((aligned(1024)));
  55. #endif

  56. #if 1

  57. //*****************************************************************************
  58. //
  59. // Provide a definition for M_PI, if it was not provided by math.h.
  60. //
  61. //*****************************************************************************
  62. #ifndef M_PI
  63. #define M_PI                    3.14159265358979323846
  64. #endif

  65. //*****************************************************************************
  66. //
  67. // The number of SysTick ticks per second.
  68. //
  69. //*****************************************************************************
  70. #define TICKS_PER_SECOND        20
  71. #define FSECONDS_PER_TICK       (1.0 / (float)TICKS_PER_SECOND)

  72. //*****************************************************************************
  73. //
  74. // A counter for system clock ticks, used for tracking time.
  75. //
  76. //*****************************************************************************
  77. static volatile uint32_t g_ui32TickCount;

  78. //*****************************************************************************
  79. //
  80. // Define an off-screen buffer and display structure.  This is used by the
  81. // strip chart widget for drawing a scrolling display.
  82. //
  83. //*****************************************************************************
  84. #define SCOPE_SCREEN_WIDTH        (100)
  85. #define SCOPE_SCREEN_HIGHT        (80)
  86. #define OFFSCREEN_BUF_SIZE        GrOffScreen4BPPSize(SCOPE_SCREEN_WIDTH, SCOPE_SCREEN_HIGHT)

  87. uint8_t                           g_pui8OffscreenBuf[OFFSCREEN_BUF_SIZE];
  88. tDisplay                          g_sOffscreenDisplay;
  89. char                              strBuf[32];
  90. static  uint32_t ui32TempValueC;
  91. static  uint32_t ui32TempValueF;
  92. static  uint32_t ui32TempValueCMax = 0;
  93. static  uint32_t ui32TempValueFMax = 0;
  94. static  uint32_t ui32TempValueCMin = 300;
  95. static  uint32_t ui32TempValueFMin = 300;

  96. //*****************************************************************************
  97. //
  98. // Create a palette for the off-screen buffer that is used by the strip chart.
  99. //
  100. //*****************************************************************************
  101. uint32_t g_pui32Palette[] =
  102. {
  103.     ClrBlack,
  104.     ClrWhite,
  105.     ClrBlue,
  106.     ClrRed,
  107.     ClrDarkGreen,
  108. };
  109. #define NUM_PALETTE_ENTRIES     (sizeof(g_pui32Palette) / sizeof(uint32_t))

  110. //*****************************************************************************
  111. //
  112. // Define the series for the strip chart.  The SERIES_LENGTH is the maximum
  113. // number of points that will be shown on the chart.
  114. //
  115. //*****************************************************************************
  116. #define SERIES_LENGTH (SCOPE_SCREEN_HIGHT)

  117. static tStripChartSeries g_sSeries0 =
  118. {
  119.     0, "C", ClrRed, 1, 1, 0, 0
  120. };

  121. static tStripChartSeries g_sSeries1 =
  122. {
  123.     0, "F", ClrBlue, 1, 1, 0, 0
  124. };


  125. //*****************************************************************************
  126. //
  127. // Defines the X-axis for the strip chart
  128. //
  129. //*****************************************************************************
  130. static tStripChartAxis i16Axis16X =
  131. {
  132.     "TIME",                                 // title of axis
  133.     0,                                      // label for minimum of axis
  134.     0,                                      // label for maximum of axis
  135.     0,                                      // minimum value for the axis
  136.     SCOPE_SCREEN_WIDTH-1,                   // maximum value for the axis
  137.     TICKS_PER_SECOND                        // grid interval for the axis
  138. };

  139. //*****************************************************************************
  140. //
  141. // Defines the Y-axis for the strip chart.
  142. //
  143. //*****************************************************************************
  144. static tStripChartAxis i16Axis16Y =
  145. {
  146.     "T",                     // title of the axis
  147.     "0",                               // label for minimum of axis
  148.     "100",                                 // label for maximum of axis
  149.      0,                                  // minimum value for the axis
  150.     (SCOPE_SCREEN_HIGHT),                // maximum value for the axis
  151.     (SCOPE_SCREEN_HIGHT/4)               // grid interval for the axis
  152. };

  153. //*****************************************************************************
  154. //
  155. // Defines the strip chart widget.  This structure requires additional
  156. // run-time initialization.
  157. //
  158. //*****************************************************************************
  159. extern tCanvasWidget         g_sBackground;
  160. extern tPushButtonWidget     g_sPushBtn;
  161. void OnDisplayBoardPaint(tWidget *pWidget, tContext *pContext);
  162. void OnButtonPress(tWidget *psWidget);

  163. Canvas(g_sBackground, WIDGET_ROOT, 0, &g_sPushBtn,
  164.        &g_sKentec320x240x16_SSD2119, 10, 25, 300, (240 - 25 -10),
  165.        CANVAS_STYLE_FILL, ClrYellow, 0, 0, 0, 0, 0, 0);

  166. RectangularButton(g_sPushBtn, &g_sBackground, 0, 0,
  167.                   &g_sKentec320x240x16_SSD2119, 60, 60, 200, 40,
  168.                   (PB_STYLE_OUTLINE | PB_STYLE_TEXT_OPAQUE | PB_STYLE_TEXT |
  169.                    PB_STYLE_FILL | PB_STYLE_RELEASE_NOTIFY),
  170.                    ClrDarkBlue, ClrBlue, ClrWhite, ClrWhite,
  171.                    g_psFontCmss22b, strBuf, 0, 0, 0, 0, OnButtonPress);


  172. StripChart(g_sStripChart, WIDGET_ROOT, 0, 0, &g_sKentec320x240x16_SSD2119, 30, 120, SCOPE_SCREEN_WIDTH, SCOPE_SCREEN_HIGHT,
  173.            0, g_psFontFixed6x8, ClrBlack, ClrYellow, ClrWhite, ClrDarkGreen,
  174.            &i16Axis16X, &i16Axis16Y, &g_sOffscreenDisplay);



  175. //*****************************************************************************
  176. //
  177. // Creates a buffer for holding the values of the data series.  It must be
  178. // large enough to hold the maximum number of data points in the series that
  179. // will be shown on the strip chart.
  180. //
  181. //*****************************************************************************
  182. static int8_t g_i8SeriesData0[SERIES_LENGTH];
  183. static int8_t g_i8SeriesData1[SERIES_LENGTH];

  184. #endif


  185. #if 0
  186. //*****************************************************************************
  187. //
  188. // Forward declarations for the globals required to define the widgets at
  189. // compile-time.
  190. //
  191. //*****************************************************************************
  192. void OnPrevious(tWidget *pWidget);
  193. void OnNext(tWidget *pWidget);
  194. void OnIntroPaint(tWidget *pWidget, tContext *pContext);
  195. void OnPrimitivePaint(tWidget *pWidget, tContext *pContext);
  196. void OnCanvasPaint(tWidget *pWidget, tContext *pContext);
  197. void OnCheckChange(tWidget *pWidget, uint32_t bSelected);
  198. void OnButtonPress(tWidget *pWidget);
  199. void OnRadioChange(tWidget *pWidget, uint32_t bSelected);
  200. void OnSliderChange(tWidget *pWidget, int32_t lValue);
  201. extern tCanvasWidget g_psPanels[];

  202. //*****************************************************************************
  203. //
  204. // The first panel, which contains introductory text explaining the
  205. // application.
  206. //
  207. //*****************************************************************************
  208. Canvas(g_sIntroduction, g_psPanels, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 24,
  209.        320, 166, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0, OnIntroPaint);

  210. //*****************************************************************************
  211. //
  212. // The second panel, which demonstrates the graphics primitives.
  213. //
  214. //*****************************************************************************
  215. Canvas(g_sPrimitives, g_psPanels + 1, 0, 0, &g_sKentec320x240x16_SSD2119, 0,
  216.        24, 320, 166, CANVAS_STYLE_APP_DRAWN, 0, 0, 0, 0, 0, 0,
  217.        OnPrimitivePaint);

  218. //*****************************************************************************
  219. //
  220. // The third panel, which demonstrates the canvas widget.
  221. //
  222. //*****************************************************************************
  223. Canvas(g_sCanvas3, g_psPanels + 2, 0, 0, &g_sKentec320x240x16_SSD2119, 205,
  224.        27, 110, 158, CANVAS_STYLE_OUTLINE | CANVAS_STYLE_APP_DRAWN, 0, ClrGray,
  225.        0, 0, 0, 0, OnCanvasPaint);
  226. Canvas(g_sCanvas2, g_psPanels + 2, &g_sCanvas3, 0,
  227.        &g_sKentec320x240x16_SSD2119, 5, 109, 195, 76,
  228.        CANVAS_STYLE_OUTLINE | CANVAS_STYLE_IMG, 0, ClrGray, 0, 0, 0, g_pucLogo,
  229.        0);
  230. Canvas(g_sCanvas1, g_psPanels + 2, &g_sCanvas2, 0,
  231.        &g_sKentec320x240x16_SSD2119, 5, 27, 195, 76,
  232.        CANVAS_STYLE_FILL | CANVAS_STYLE_OUTLINE | CANVAS_STYLE_TEXT,
  233.        ClrMidnightBlue, ClrGray, ClrSilver, &g_sFontCm22, "Text", 0, 0);

  234. //*****************************************************************************
  235. //
  236. // The fourth panel, which demonstrates the checkbox widget.
  237. //
  238. //*****************************************************************************
  239. tCanvasWidget g_psCheckBoxIndicators[] =
  240. {
  241.     CanvasStruct(g_psPanels + 3, g_psCheckBoxIndicators + 1, 0,
  242.                  &g_sKentec320x240x16_SSD2119, 230, 30, 50, 42,
  243.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  244.     CanvasStruct(g_psPanels + 3, g_psCheckBoxIndicators + 2, 0,
  245.                  &g_sKentec320x240x16_SSD2119, 230, 82, 50, 48,
  246.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  247.     CanvasStruct(g_psPanels + 3, 0, 0,
  248.                  &g_sKentec320x240x16_SSD2119, 230, 134, 50, 42,
  249.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0)
  250. };
  251. tCheckBoxWidget g_psCheckBoxes[] =
  252. {
  253.     CheckBoxStruct(g_psPanels + 3, g_psCheckBoxes + 1, 0,
  254.                    &g_sKentec320x240x16_SSD2119, 40, 30, 185, 42,
  255.                    CB_STYLE_OUTLINE | CB_STYLE_FILL | CB_STYLE_TEXT, 16,
  256.                    ClrMidnightBlue, ClrGray, ClrSilver, &g_sFontCm22, "Select",
  257.                    0, OnCheckChange),
  258.     CheckBoxStruct(g_psPanels + 3, g_psCheckBoxes + 2, 0,
  259.                    &g_sKentec320x240x16_SSD2119, 40, 82, 185, 48,
  260.                    CB_STYLE_IMG, 16, 0, ClrGray, 0, 0, 0, g_pucLogo,
  261.                    OnCheckChange),
  262.     CheckBoxStruct(g_psPanels + 3, g_psCheckBoxIndicators, 0,
  263.                    &g_sKentec320x240x16_SSD2119, 40, 134, 189, 42,
  264.                    CB_STYLE_OUTLINE | CB_STYLE_TEXT, 16,
  265.                    0, ClrGray, ClrGreen, &g_sFontCm20, "Select",
  266.                    0, OnCheckChange),
  267. };
  268. #define NUM_CHECK_BOXES         (sizeof(g_psCheckBoxes) /   \
  269.                                  sizeof(g_psCheckBoxes[0]))

  270. //*****************************************************************************
  271. //
  272. // The fifth panel, which demonstrates the container widget.
  273. //
  274. //*****************************************************************************
  275. Container(g_sContainer3, g_psPanels + 4, 0, 0, &g_sKentec320x240x16_SSD2119,
  276.           210, 47, 105, 118, CTR_STYLE_OUTLINE | CTR_STYLE_FILL,
  277.           ClrMidnightBlue, ClrGray, 0, 0, 0);
  278. Container(g_sContainer2, g_psPanels + 4, &g_sContainer3, 0,
  279.           &g_sKentec320x240x16_SSD2119, 5, 109, 200, 76,
  280.           (CTR_STYLE_OUTLINE | CTR_STYLE_FILL | CTR_STYLE_TEXT |
  281.            CTR_STYLE_TEXT_CENTER), ClrMidnightBlue, ClrGray, ClrSilver,
  282.           &g_sFontCm22, "Group2");
  283. Container(g_sContainer1, g_psPanels + 4, &g_sContainer2, 0,
  284.           &g_sKentec320x240x16_SSD2119, 5, 27, 200, 76,
  285.           CTR_STYLE_OUTLINE | CTR_STYLE_FILL | CTR_STYLE_TEXT, ClrMidnightBlue,
  286.           ClrGray, ClrSilver, &g_sFontCm22, "Group1");

  287. //*****************************************************************************
  288. //
  289. // The sixth panel, which contains a selection of push buttons.
  290. //
  291. //*****************************************************************************
  292. tCanvasWidget g_psPushButtonIndicators[] =
  293. {
  294.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 1, 0,
  295.                  &g_sKentec320x240x16_SSD2119, 40, 85, 20, 20,
  296.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  297.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 2, 0,
  298.                  &g_sKentec320x240x16_SSD2119, 90, 85, 20, 20,
  299.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  300.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 3, 0,
  301.                  &g_sKentec320x240x16_SSD2119, 145, 85, 20, 20,
  302.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  303.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 4, 0,
  304.                  &g_sKentec320x240x16_SSD2119, 40, 165, 20, 20,
  305.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  306.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 5, 0,
  307.                  &g_sKentec320x240x16_SSD2119, 90, 165, 20, 20,
  308.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  309.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 6, 0,
  310.                  &g_sKentec320x240x16_SSD2119, 145, 165, 20, 20,
  311.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  312.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 7, 0,
  313.                  &g_sKentec320x240x16_SSD2119, 190, 35, 110, 24,
  314.                  CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "Non-auto",
  315.                  0, 0),
  316.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 8, 0,
  317.                  &g_sKentec320x240x16_SSD2119, 190, 55, 110, 24,
  318.                  CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "repeat",
  319.                  0, 0),
  320.     CanvasStruct(g_psPanels + 5, g_psPushButtonIndicators + 9, 0,
  321.                  &g_sKentec320x240x16_SSD2119, 190, 115, 110, 24,
  322.                  CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "Auto",
  323.                  0, 0),
  324.     CanvasStruct(g_psPanels + 5, 0, 0,
  325.                  &g_sKentec320x240x16_SSD2119, 190, 135, 110, 24,
  326.                  CANVAS_STYLE_TEXT, 0, 0, ClrSilver, &g_sFontCm20, "repeat",
  327.                  0, 0),
  328. };
  329. tPushButtonWidget g_psPushButtons[] =
  330. {
  331.     RectangularButtonStruct(g_psPanels + 5, g_psPushButtons + 1, 0,
  332.                             &g_sKentec320x240x16_SSD2119, 30, 35, 40, 40,
  333.                             PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT,
  334.                             ClrMidnightBlue, ClrBlack, ClrGray, ClrSilver,
  335.                             &g_sFontCm22, "1", 0, 0, 0, 0, OnButtonPress),
  336.     CircularButtonStruct(g_psPanels + 5, g_psPushButtons + 2, 0,
  337.                          &g_sKentec320x240x16_SSD2119, 100, 55, 20,
  338.                          PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT,
  339.                          ClrMidnightBlue, ClrBlack, ClrGray, ClrSilver,
  340.                          &g_sFontCm22, "3", 0, 0, 0, 0, OnButtonPress),
  341.     RectangularButtonStruct(g_psPanels + 5, g_psPushButtons + 3, 0,
  342.                             &g_sKentec320x240x16_SSD2119, 130, 30, 50, 50,
  343.                             PB_STYLE_IMG | PB_STYLE_TEXT, 0, 0, 0, ClrSilver,
  344.                             &g_sFontCm22, "5", g_pucBlue50x50,
  345.                             g_pucBlue50x50Press, 0, 0, OnButtonPress),
  346.     RectangularButtonStruct(g_psPanels + 5, g_psPushButtons + 4, 0,
  347.                             &g_sKentec320x240x16_SSD2119, 30, 115, 40, 40,
  348.                             (PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT |
  349.                              PB_STYLE_AUTO_REPEAT), ClrMidnightBlue, ClrBlack,
  350.                             ClrGray, ClrSilver, &g_sFontCm22, "2", 0, 0, 125,
  351.                             25, OnButtonPress),
  352.     CircularButtonStruct(g_psPanels + 5, g_psPushButtons + 5, 0,
  353.                          &g_sKentec320x240x16_SSD2119, 100, 135, 20,
  354.                          (PB_STYLE_FILL | PB_STYLE_OUTLINE | PB_STYLE_TEXT |
  355.                           PB_STYLE_AUTO_REPEAT), ClrMidnightBlue, ClrBlack,
  356.                          ClrGray, ClrSilver, &g_sFontCm22, "4", 0, 0, 125, 25,
  357.                          OnButtonPress),
  358.     RectangularButtonStruct(g_psPanels + 5, g_psPushButtonIndicators, 0,
  359.                             &g_sKentec320x240x16_SSD2119, 130, 110, 50, 50,
  360.                             (PB_STYLE_IMG | PB_STYLE_TEXT |
  361.                              PB_STYLE_AUTO_REPEAT), 0, 0, 0, ClrSilver,
  362.                             &g_sFontCm22, "6", g_pucBlue50x50,
  363.                             g_pucBlue50x50Press, 125, 25, OnButtonPress),
  364. };
  365. #define NUM_PUSH_BUTTONS        (sizeof(g_psPushButtons) /   \
  366.                                  sizeof(g_psPushButtons[0]))
  367. uint32_t g_ulButtonState;

  368. //*****************************************************************************
  369. //
  370. // The seventh panel, which contains a selection of radio buttons.
  371. //
  372. //*****************************************************************************
  373. tContainerWidget g_psRadioContainers[];
  374. tCanvasWidget g_psRadioButtonIndicators[] =
  375. {
  376.     CanvasStruct(g_psRadioContainers, g_psRadioButtonIndicators + 1, 0,
  377.                  &g_sKentec320x240x16_SSD2119, 95, 62, 20, 20,
  378.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  379.     CanvasStruct(g_psRadioContainers, g_psRadioButtonIndicators + 2, 0,
  380.                  &g_sKentec320x240x16_SSD2119, 95, 107, 20, 20,
  381.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  382.     CanvasStruct(g_psRadioContainers, 0, 0,
  383.                  &g_sKentec320x240x16_SSD2119, 95, 152, 20, 20,
  384.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  385.     CanvasStruct(g_psRadioContainers + 1, g_psRadioButtonIndicators + 4, 0,
  386.                  &g_sKentec320x240x16_SSD2119, 260, 62, 20, 20,
  387.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  388.     CanvasStruct(g_psRadioContainers + 1, g_psRadioButtonIndicators + 5, 0,
  389.                  &g_sKentec320x240x16_SSD2119, 260, 107, 20, 20,
  390.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  391.     CanvasStruct(g_psRadioContainers + 1, 0, 0,
  392.                  &g_sKentec320x240x16_SSD2119, 260, 152, 20, 20,
  393.                  CANVAS_STYLE_IMG, 0, 0, 0, 0, 0, g_pucLightOff, 0),
  394. };
  395. tRadioButtonWidget g_psRadioButtons1[] =
  396. {
  397.     RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 1, 0,
  398.                       &g_sKentec320x240x16_SSD2119, 10, 50, 80, 45,
  399.                       RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, &g_sFontCm20,
  400.                       "One", 0, OnRadioChange),
  401.     RadioButtonStruct(g_psRadioContainers, g_psRadioButtons1 + 2, 0,
  402.                       &g_sKentec320x240x16_SSD2119, 10, 95, 80, 45,
  403.                       RB_STYLE_TEXT, 16, 0, ClrSilver, ClrSilver, &g_sFontCm20,
  404.                       "Two", 0, OnRadioChange),
  405.     RadioButtonStruct(g_psRadioContainers, g_psRadioButtonIndicators, 0,
  406.                       &g_sKentec320x240x16_SSD2119, 10, 140, 80, 45,
  407.                       RB_STYLE_TEXT, 24, 0, ClrSilver, ClrSilver, &g_sFontCm20,
  408.                       "Three", 0, OnRadioChange)
  409. };
  410. #define NUM_RADIO1_BUTTONS      (sizeof(g_psRadioButtons1) /   \
  411.                                  sizeof(g_psRadioButtons1[0]))
  412. tRadioButtonWidget g_psRadioButtons2[] =
  413. {
  414.     RadioButtonStruct(g_psRadioContainers + 1, g_psRadioButtons2 + 1, 0,
  415.                       &g_sKentec320x240x16_SSD2119, 175, 50, 80, 45,
  416.                       RB_STYLE_IMG, 16, 0, ClrSilver, 0, 0, 0, g_pucLogo,
  417.                       OnRadioChange),
  418.     RadioButtonStruct(g_psRadioContainers + 1, g_psRadioButtons2 + 2, 0,
  419.                       &g_sKentec320x240x16_SSD2119, 175, 95, 80, 45,
  420.                       RB_STYLE_IMG, 24, 0, ClrSilver, 0, 0, 0, g_pucLogo,
  421.                       OnRadioChange),
  422.     RadioButtonStruct(g_psRadioContainers + 1, g_psRadioButtonIndicators + 3,
  423.                       0, &g_sKentec320x240x16_SSD2119, 175, 140, 80, 45,
  424.                       RB_STYLE_IMG, 24, 0, ClrSilver, 0, 0, 0, g_pucLogo,
  425.                       OnRadioChange)
  426. };
  427. #define NUM_RADIO2_BUTTONS      (sizeof(g_psRadioButtons2) /   \
  428.                                  sizeof(g_psRadioButtons2[0]))
  429. tContainerWidget g_psRadioContainers[] =
  430. {
  431.     ContainerStruct(g_psPanels + 6, g_psRadioContainers + 1, g_psRadioButtons1,
  432.                     &g_sKentec320x240x16_SSD2119, 5, 27, 148, 160,
  433.                     CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, ClrGray, ClrSilver,
  434.                     &g_sFontCm20, "Group One"),
  435.     ContainerStruct(g_psPanels + 6, 0, g_psRadioButtons2,
  436.                     &g_sKentec320x240x16_SSD2119, 167, 27, 148, 160,
  437.                     CTR_STYLE_OUTLINE | CTR_STYLE_TEXT, 0, ClrGray, ClrSilver,
  438.                     &g_sFontCm20, "Group Two")
  439. };

  440. //*****************************************************************************
  441. //
  442. // The eighth panel, which demonstrates the slider widget.
  443. //
  444. //*****************************************************************************
  445. Canvas(g_sSliderValueCanvas, g_psPanels + 7, 0, 0,
  446.        &g_sKentec320x240x16_SSD2119, 210, 30, 60, 40,
  447.        CANVAS_STYLE_TEXT | CANVAS_STYLE_TEXT_OPAQUE, ClrBlack, 0, ClrSilver,
  448.        &g_sFontCm24, "50%",
  449.        0, 0);

  450. tSliderWidget g_psSliders[] =
  451. {
  452.     SliderStruct(g_psPanels + 7, g_psSliders + 1, 0,
  453.                  &g_sKentec320x240x16_SSD2119, 5, 115, 220, 30, 0, 100, 25,
  454.                  (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
  455.                   SL_STYLE_TEXT | SL_STYLE_BACKG_TEXT),
  456.                  ClrGray, ClrBlack, ClrSilver, ClrWhite, ClrWhite,
  457.                  &g_sFontCm20, "25%", 0, 0, OnSliderChange),
  458.     SliderStruct(g_psPanels + 7, g_psSliders + 2, 0,
  459.                  &g_sKentec320x240x16_SSD2119, 5, 155, 220, 25, 0, 100, 25,
  460.                  (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_OUTLINE |
  461.                   SL_STYLE_TEXT),
  462.                  ClrWhite, ClrBlueViolet, ClrSilver, ClrBlack, 0,
  463.                  &g_sFontCm18, "Foreground Text Only", 0, 0, OnSliderChange),
  464.     SliderStruct(g_psPanels + 7, g_psSliders + 3, 0,
  465.                  &g_sKentec320x240x16_SSD2119, 240, 70, 26, 110, 0, 100, 50,
  466.                  (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_VERTICAL |
  467.                   SL_STYLE_OUTLINE | SL_STYLE_LOCKED), ClrDarkGreen,
  468.                   ClrDarkRed, ClrSilver, 0, 0, 0, 0, 0, 0, 0),
  469.     SliderStruct(g_psPanels + 7, g_psSliders + 4, 0,
  470.                  &g_sKentec320x240x16_SSD2119, 280, 30, 30, 150, 0, 100, 75,
  471.                  (SL_STYLE_IMG | SL_STYLE_BACKG_IMG | SL_STYLE_VERTICAL |
  472.                  SL_STYLE_OUTLINE), 0, ClrBlack, ClrSilver, 0, 0, 0,
  473.                  0, g_pucGettingHotter28x148, g_pucGettingHotter28x148Mono,
  474.                  OnSliderChange),
  475.     SliderStruct(g_psPanels + 7, g_psSliders + 5, 0,
  476.                  &g_sKentec320x240x16_SSD2119, 5, 30, 195, 37, 0, 100, 50,
  477.                  SL_STYLE_IMG | SL_STYLE_BACKG_IMG, 0, 0, 0, 0, 0, 0,
  478.                  0, g_pucGreenSlider195x37, g_pucRedSlider195x37,
  479.                  OnSliderChange),
  480.     SliderStruct(g_psPanels + 7, &g_sSliderValueCanvas, 0,
  481.                  &g_sKentec320x240x16_SSD2119, 5, 80, 220, 25, 0, 100, 50,
  482.                  (SL_STYLE_FILL | SL_STYLE_BACKG_FILL | SL_STYLE_TEXT |
  483.                   SL_STYLE_BACKG_TEXT | SL_STYLE_TEXT_OPAQUE |
  484.                   SL_STYLE_BACKG_TEXT_OPAQUE),
  485.                  ClrBlue, ClrYellow, ClrSilver, ClrYellow, ClrBlue,
  486.                  &g_sFontCm18, "Text in both areas", 0, 0,
  487.                  OnSliderChange),
  488. };

  489. #define SLIDER_TEXT_VAL_INDEX   0
  490. #define SLIDER_LOCKED_INDEX     2
  491. #define SLIDER_CANVAS_VAL_INDEX 4

  492. #define NUM_SLIDERS (sizeof(g_psSliders) / sizeof(g_psSliders[0]))

  493. //*****************************************************************************
  494. //
  495. // An array of canvas widgets, one per panel.  Each canvas is filled with
  496. // black, overwriting the contents of the previous panel.
  497. //
  498. //*****************************************************************************
  499. tCanvasWidget g_psPanels[] =
  500. {
  501.     CanvasStruct(0, 0, &g_sIntroduction, &g_sKentec320x240x16_SSD2119, 0, 24,
  502.                  320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  503.     CanvasStruct(0, 0, &g_sPrimitives, &g_sKentec320x240x16_SSD2119, 0, 24,
  504.                  320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  505.     CanvasStruct(0, 0, &g_sCanvas1, &g_sKentec320x240x16_SSD2119, 0, 24, 320,
  506.                  166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  507.     CanvasStruct(0, 0, g_psCheckBoxes, &g_sKentec320x240x16_SSD2119, 0, 24,
  508.                  320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  509.     CanvasStruct(0, 0, &g_sContainer1, &g_sKentec320x240x16_SSD2119, 0, 24,
  510.                  320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  511.     CanvasStruct(0, 0, g_psPushButtons, &g_sKentec320x240x16_SSD2119, 0, 24,
  512.                  320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  513.     CanvasStruct(0, 0, g_psRadioContainers, &g_sKentec320x240x16_SSD2119, 0,
  514.                  24, 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  515.     CanvasStruct(0, 0, g_psSliders, &g_sKentec320x240x16_SSD2119, 0,
  516.                  24, 320, 166, CANVAS_STYLE_FILL, ClrBlack, 0, 0, 0, 0, 0, 0),
  517. };

  518. //*****************************************************************************
  519. //
  520. // The number of panels.
  521. //
  522. //*****************************************************************************
  523. #define NUM_PANELS              (sizeof(g_psPanels) / sizeof(g_psPanels[0]))

  524. //*****************************************************************************
  525. //
  526. // The names for each of the panels, which is displayed at the bottom of the
  527. // screen.
  528. //
  529. //*****************************************************************************
  530. char *g_pcPanelNames[] =
  531. {
  532.     "     Introduction     ",
  533.     "     Primitives     ",
  534.     "     Canvas     ",
  535.     "     Checkbox     ",
  536.     "     Container     ",
  537.     "     Push Buttons     ",
  538.     "     Radio Buttons     ",
  539.     "     Sliders     ",
  540.     "     S/W Update    "
  541. };

  542. //*****************************************************************************
  543. //
  544. // The buttons and text across the bottom of the screen.
  545. //
  546. //*****************************************************************************
  547. RectangularButton(g_sPrevious, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 0, 190,
  548.                   50, 50, PB_STYLE_FILL, ClrBlack, ClrBlack, 0, ClrSilver,
  549.                   &g_sFontCm20, "-", g_pucBlue50x50, g_pucBlue50x50Press, 0, 0,
  550.                   OnPrevious);
  551.                   
  552. Canvas(g_sTitle, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 50, 190, 220, 50,
  553.        CANVAS_STYLE_TEXT | CANVAS_STYLE_TEXT_OPAQUE, 0, 0, ClrSilver,
  554.        &g_sFontCm20, 0, 0, 0);
  555.       
  556. RectangularButton(g_sNext, 0, 0, 0, &g_sKentec320x240x16_SSD2119, 270, 190,
  557.                   50, 50, PB_STYLE_IMG | PB_STYLE_TEXT, ClrBlack, ClrBlack, 0,
  558.                   ClrSilver, &g_sFontCm20, "+", g_pucBlue50x50,
  559.                   g_pucBlue50x50Press, 0, 0, OnNext);

  560. //*****************************************************************************
  561. //
  562. // The panel that is currently being displayed.
  563. //
  564. //*****************************************************************************
  565. uint32_t g_ulPanel;

  566. //*****************************************************************************
  567. //
  568. // Handles presses of the previous panel button.
  569. //
  570. //*****************************************************************************
  571. void
  572. OnPrevious(tWidget *pWidget)
  573. {
  574.     //
  575.     // There is nothing to be done if the first panel is already being
  576.     // displayed.
  577.     //
  578.     if(g_ulPanel == 0)
  579.     {
  580.         return;
  581.     }

  582.     //
  583.     // Remove the current panel.
  584.     //
  585.     WidgetRemove((tWidget *)(g_psPanels + g_ulPanel));

  586.     //
  587.     // Decrement the panel index.
  588.     //
  589.     g_ulPanel--;

  590.     //
  591.     // Add and draw the new panel.
  592.     //
  593.     WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ulPanel));
  594.     WidgetPaint((tWidget *)(g_psPanels + g_ulPanel));

  595.     //
  596.     // Set the title of this panel.
  597.     //
  598.     CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]);
  599.     WidgetPaint((tWidget *)&g_sTitle);

  600.     //
  601.     // See if this is the first panel.
  602.     //
  603.     if(g_ulPanel == 0)
  604.     {
  605.         //
  606.         // Clear the previous button from the display since the first panel is
  607.         // being displayed.
  608.         //
  609.         PushButtonImageOff(&g_sPrevious);
  610.         PushButtonTextOff(&g_sPrevious);
  611.         PushButtonFillOn(&g_sPrevious);
  612.         WidgetPaint((tWidget *)&g_sPrevious);
  613.     }

  614.     //
  615.     // See if the previous panel was the last panel.
  616.     //
  617.     if(g_ulPanel == (NUM_PANELS - 2))
  618.     {
  619.         //
  620.         // Display the next button.
  621.         //
  622.         PushButtonImageOn(&g_sNext);
  623.         PushButtonTextOn(&g_sNext);
  624.         PushButtonFillOff(&g_sNext);
  625.         WidgetPaint((tWidget *)&g_sNext);
  626.     }

  627. }

  628. //*****************************************************************************
  629. //
  630. // Handles presses of the next panel button.
  631. //
  632. //*****************************************************************************
  633. void
  634. OnNext(tWidget *pWidget)
  635. {
  636.     //
  637.     // There is nothing to be done if the last panel is already being
  638.     // displayed.
  639.     //
  640.     if(g_ulPanel == (NUM_PANELS - 1))
  641.     {
  642.         return;
  643.     }

  644.     //
  645.     // Remove the current panel.
  646.     //
  647.     WidgetRemove((tWidget *)(g_psPanels + g_ulPanel));

  648.     //
  649.     // Increment the panel index.
  650.     //
  651.     g_ulPanel++;

  652.     //
  653.     // Add and draw the new panel.
  654.     //
  655.     WidgetAdd(WIDGET_ROOT, (tWidget *)(g_psPanels + g_ulPanel));
  656.     WidgetPaint((tWidget *)(g_psPanels + g_ulPanel));

  657.     //
  658.     // Set the title of this panel.
  659.     //
  660.     CanvasTextSet(&g_sTitle, g_pcPanelNames[g_ulPanel]);
  661.     WidgetPaint((tWidget *)&g_sTitle);

  662.     //
  663.     // See if the previous panel was the first panel.
  664.     //
  665.     if(g_ulPanel == 1)
  666.     {
  667.         //
  668.         // Display the previous button.
  669.         //
  670.         PushButtonImageOn(&g_sPrevious);
  671.         PushButtonTextOn(&g_sPrevious);
  672.         PushButtonFillOff(&g_sPrevious);
  673.         WidgetPaint((tWidget *)&g_sPrevious);
  674.     }

  675.     //
  676.     // See if this is the last panel.
  677.     //
  678.     if(g_ulPanel == (NUM_PANELS - 1))
  679.     {
  680.         //
  681.         // Clear the next button from the display since the last panel is being
  682.         // displayed.
  683.         //
  684.         PushButtonImageOff(&g_sNext);
  685.         PushButtonTextOff(&g_sNext);
  686.         PushButtonFillOn(&g_sNext);
  687.         WidgetPaint((tWidget *)&g_sNext);
  688.     }

  689. }

  690. //*****************************************************************************
  691. //
  692. // Handles paint requests for the introduction canvas widget.
  693. //
  694. //*****************************************************************************
  695. void
  696. OnIntroPaint(tWidget *pWidget, tContext *pContext)
  697. {
  698.     //
  699.     // Display the introduction text in the canvas.
  700.     //
  701.     GrContextFontSet(pContext, &g_sFontCm18);
  702.     GrContextForegroundSet(pContext, ClrSilver);
  703.     GrStringDraw(pContext, "This application demonstrates the Stellaris", -1,
  704.                  0, 32, 0);
  705.     GrStringDraw(pContext, "Graphics Library.", -1, 0, 50, 0);
  706.     GrStringDraw(pContext, "Each panel shows a different feature of", -1, 0,
  707.                  74, 0);
  708.     GrStringDraw(pContext, "the graphics library. Widgets on the panels", -1, 0,
  709.                  92, 0);
  710.     GrStringDraw(pContext, "are fully operational; pressing them will", -1, 0,
  711.                  110, 0);
  712.     GrStringDraw(pContext, "result in visible feedback of some kind.", -1, 0,
  713.                  128, 0);
  714.     GrStringDraw(pContext, "Press the + and - buttons at the bottom", -1, 0,
  715.                  146, 0);
  716.     GrStringDraw(pContext, "of the screen to move between the panels.", -1, 0,
  717.                  164, 0);
  718. }

  719. //*****************************************************************************
  720. //
  721. // Handles paint requests for the primitives canvas widget.
  722. //
  723. //*****************************************************************************
  724. void
  725. OnPrimitivePaint(tWidget *pWidget, tContext *pContext)
  726. {
  727.     uint32_t ulIdx;
  728.     tRectangle sRect;

  729.     //
  730.     // Draw a vertical sweep of lines from red to green.
  731.     //
  732.     for(ulIdx = 0; ulIdx <= 8; ulIdx++)
  733.     {
  734.         GrContextForegroundSet(pContext,
  735.                                (((((10 - ulIdx) * 255) / 10) << ClrRedShift) |
  736.                                 (((ulIdx * 255) / 10) << ClrGreenShift)));
  737.         GrLineDraw(pContext, 115, 120, 5, 120 - (11 * ulIdx));
  738.     }

  739.     //
  740.     // Draw a horizontal sweep of lines from green to blue.
  741.     //
  742.     for(ulIdx = 1; ulIdx <= 10; ulIdx++)
  743.     {
  744.         GrContextForegroundSet(pContext,
  745.                                (((((10 - ulIdx) * 255) / 10) <<
  746.                                  ClrGreenShift) |
  747.                                 (((ulIdx * 255) / 10) << ClrBlueShift)));
  748.         GrLineDraw(pContext, 115, 120, 5 + (ulIdx * 11), 29);
  749.     }

  750.     //
  751.     // Draw a filled circle with an overlapping circle.
  752.     //
  753.     GrContextForegroundSet(pContext, ClrBrown);
  754.     GrCircleFill(pContext, 185, 69, 40);
  755.     GrContextForegroundSet(pContext, ClrSkyBlue);
  756.     GrCircleDraw(pContext, 205, 99, 30);

  757.     //
  758.     // Draw a filled rectangle with an overlapping rectangle.
  759.     //
  760.     GrContextForegroundSet(pContext, ClrSlateGray);
  761.     sRect.i16XMin = 20;
  762.     sRect.i16YMin = 100;
  763.     sRect.i16XMax = 75;
  764.     sRect.i16YMax = 160;
  765.     GrRectFill(pContext, &sRect);
  766.     GrContextForegroundSet(pContext, ClrSlateBlue);
  767.     sRect.i16XMin += 40;
  768.     sRect.i16YMin += 40;
  769.     sRect.i16XMax += 30;
  770.     sRect.i16YMax += 28;
  771.     GrRectDraw(pContext, &sRect);

  772.     //
  773.     // Draw a piece of text in fonts of increasing size.
  774.     //
  775.     GrContextForegroundSet(pContext, ClrSilver);
  776.     GrContextFontSet(pContext, &g_sFontCm14);
  777.     GrStringDraw(pContext, "Strings", -1, 125, 110, 0);
  778.     GrContextFontSet(pContext, &g_sFontCm18);
  779.     GrStringDraw(pContext, "Strings", -1, 145, 124, 0);
  780.     GrContextFontSet(pContext, &g_sFontCm22);
  781.     GrStringDraw(pContext, "Strings", -1, 165, 142, 0);
  782.     GrContextFontSet(pContext, &g_sFontCm24);
  783.     GrStringDraw(pContext, "Strings", -1, 185, 162, 0);

  784.     //
  785.     // Draw an image.
  786.     //
  787.     GrImageDraw(pContext, g_pucLogo, 270, 80);
  788. }

  789. //*****************************************************************************
  790. //
  791. // Handles paint requests for the canvas demonstration widget.
  792. //
  793. //*****************************************************************************
  794. void
  795. OnCanvasPaint(tWidget *pWidget, tContext *pContext)
  796. {
  797.     uint32_t ulIdx;

  798.     //
  799.     // Draw a set of radiating lines.
  800.     //
  801.     GrContextForegroundSet(pContext, ClrGoldenrod);
  802.     for(ulIdx = 50; ulIdx <= 180; ulIdx += 10)
  803.     {
  804.         GrLineDraw(pContext, 210, ulIdx, 310, 230 - ulIdx);
  805.     }

  806.     //
  807.     // Indicate that the contents of this canvas were drawn by the application.
  808.     //
  809.     GrContextFontSet(pContext, &g_sFontCm12);
  810.     GrStringDrawCentered(pContext, "App Drawn", -1, 260, 50, 1);
  811. }

  812. //*****************************************************************************
  813. //
  814. // Handles change notifications for the check box widgets.
  815. //
  816. //*****************************************************************************
  817. void
  818. OnCheckChange(tWidget *pWidget, uint32_t bSelected)
  819. {
  820.     uint32_t ulIdx;

  821.     //
  822.     // Find the index of this check box.
  823.     //
  824.     for(ulIdx = 0; ulIdx < NUM_CHECK_BOXES; ulIdx++)
  825.     {
  826.         if(pWidget == (tWidget *)(g_psCheckBoxes + ulIdx))
  827.         {
  828.             break;
  829.         }
  830.     }

  831.     //
  832.     // Return if the check box could not be found.
  833.     //
  834.     if(ulIdx == NUM_CHECK_BOXES)
  835.     {
  836.         return;
  837.     }

  838.     //
  839.     // Set the matching indicator based on the selected state of the check box.
  840.     //
  841.     CanvasImageSet(g_psCheckBoxIndicators + ulIdx,
  842.                    bSelected ? g_pucLightOn : g_pucLightOff);
  843.     WidgetPaint((tWidget *)(g_psCheckBoxIndicators + ulIdx));

  844. }

  845. //*****************************************************************************
  846. //
  847. // Handles press notifications for the push button widgets.
  848. //
  849. //*****************************************************************************
  850. void
  851. OnButtonPress(tWidget *pWidget)
  852. {
  853.     uint32_t ulIdx;

  854.     //
  855.     // Find the index of this push button.
  856.     //
  857.     for(ulIdx = 0; ulIdx < NUM_PUSH_BUTTONS; ulIdx++)
  858.     {
  859.         if(pWidget == (tWidget *)(g_psPushButtons + ulIdx))
  860.         {
  861.             break;
  862.         }
  863.     }

  864.     //
  865.     // Return if the push button could not be found.
  866.     //
  867.     if(ulIdx == NUM_PUSH_BUTTONS)
  868.     {
  869.         return;
  870.     }

  871.     //
  872.     // Toggle the state of this push button indicator.
  873.     //
  874.     g_ulButtonState ^= 1 << ulIdx;

  875.     //
  876.     // Set the matching indicator based on the selected state of the check box.
  877.     //
  878.     CanvasImageSet(g_psPushButtonIndicators + ulIdx,
  879.                    (g_ulButtonState & (1 << ulIdx)) ? g_pucLightOn :
  880.                    g_pucLightOff);
  881.     WidgetPaint((tWidget *)(g_psPushButtonIndicators + ulIdx));

  882. }

  883. //*****************************************************************************
  884. //
  885. // Handles notifications from the slider controls.
  886. //
  887. //*****************************************************************************
  888. void
  889. OnSliderChange(tWidget *pWidget, int32_t lValue)
  890. {
  891.     static char pcCanvasText[5];
  892.     static char pcSliderText[5];

  893.     //
  894.     // Is this the widget whose value we mirror in the canvas widget and the
  895.     // locked slider?
  896.     //
  897.     if(pWidget == (tWidget *)&g_psSliders[SLIDER_CANVAS_VAL_INDEX])
  898.     {
  899.         //
  900.         // Yes - update the canvas to show the slider value.
  901.         //
  902.         usprintf(pcCanvasText, "%3d%%", lValue);
  903.         CanvasTextSet(&g_sSliderValueCanvas, pcCanvasText);
  904.         WidgetPaint((tWidget *)&g_sSliderValueCanvas);

  905.         //
  906.         // Also update the value of the locked slider to reflect this one.
  907.         //
  908.         SliderValueSet(&g_psSliders[SLIDER_LOCKED_INDEX], lValue);
  909.         WidgetPaint((tWidget *)&g_psSliders[SLIDER_LOCKED_INDEX]);
  910.     }

  911.     if(pWidget == (tWidget *)&g_psSliders[SLIDER_TEXT_VAL_INDEX])
  912.     {
  913.         //
  914.         // Yes - update the canvas to show the slider value.
  915.         //
  916.         usprintf(pcSliderText, "%3d%%", lValue);
  917.         SliderTextSet(&g_psSliders[SLIDER_TEXT_VAL_INDEX], pcSliderText);
  918.         WidgetPaint((tWidget *)&g_psSliders[SLIDER_TEXT_VAL_INDEX]);
  919.     }
  920. }

  921. //*****************************************************************************
  922. //
  923. // Handles change notifications for the radio button widgets.
  924. //
  925. //*****************************************************************************
  926. void
  927. OnRadioChange(tWidget *pWidget, uint32_t bSelected)
  928. {
  929.     uint32_t ulIdx;

  930.     //
  931.     // Find the index of this radio button in the first group.
  932.     //
  933.     for(ulIdx = 0; ulIdx < NUM_RADIO1_BUTTONS; ulIdx++)
  934.     {
  935.         if(pWidget == (tWidget *)(g_psRadioButtons1 + ulIdx))
  936.         {
  937.             break;
  938.         }
  939.     }

  940.     //
  941.     // See if the radio button was found.
  942.     //
  943.     if(ulIdx == NUM_RADIO1_BUTTONS)
  944.     {
  945.         //
  946.         // Find the index of this radio button in the second group.
  947.         //
  948.         for(ulIdx = 0; ulIdx < NUM_RADIO2_BUTTONS; ulIdx++)
  949.         {
  950.             if(pWidget == (tWidget *)(g_psRadioButtons2 + ulIdx))
  951.             {
  952.                 break;
  953.             }
  954.         }

  955.         //
  956.         // Return if the radio button could not be found.
  957.         //
  958.         if(ulIdx == NUM_RADIO2_BUTTONS)
  959.         {
  960.             return;
  961.         }

  962.         //
  963.         // Sind the radio button is in the second group, offset the index to
  964.         // the indicators associated with the second group.
  965.         //
  966.         ulIdx += NUM_RADIO1_BUTTONS;
  967.     }

  968.     //
  969.     // Set the matching indicator based on the selected state of the radio
  970.     // button.
  971.     //
  972.     CanvasImageSet(g_psRadioButtonIndicators + ulIdx,
  973.                    bSelected ? g_pucLightOn : g_pucLightOff);
  974.     WidgetPaint((tWidget *)(g_psRadioButtonIndicators + ulIdx));

  975. }

  976. #endif


  977. //*****************************************************************************
  978. // Handles paint requests for the Message Board canvas widget.
  979. //*****************************************************************************
  980. void OnDisplayBoardPaint(tWidget *pWidget, tContext *pContext)
  981. {
  982.     GrContextFontSet(pContext, &g_sFontCm18);
  983.     GrContextForegroundSet(pContext, ClrSilver);
  984.     GrStringDraw(pContext, strBuf, -1,
  985.                  0, 32, 0);
  986.     GrStringDraw(pContext, "Graphics Library.", -1, 0, 50, 0);
  987.     GrStringDraw(pContext, "Each panel shows a different feature of", -1, 0,
  988.                  74, 0);
  989.     GrStringDraw(pContext, "the graphics library. Widgets on the panels", -1, 0,
  990.                  92, 0);
  991.     GrStringDraw(pContext, "are fully operational; pressing them will", -1, 0,
  992.                  110, 0);
  993.     GrStringDraw(pContext, "result in visible feedback of some kind.", -1, 0,
  994.                  128, 0);
  995.     GrStringDraw(pContext, "Press the + and - buttons at the bottom", -1, 0,
  996.                  146, 0);
  997.     GrStringDraw(pContext, "of the screen to move between the panels.", -1, 0,
  998.                  164, 0);
  999.     WidgetPaint(WIDGET_ROOT);
  1000. }

  1001. void OnButtonPress(tWidget *psWidget)
  1002. {
  1003.         static uint32_t flag = 0 ;

  1004.         if ( flag == 0 )
  1005.         {
  1006.                 flag = 1;
  1007.             sprintf ( strBuf, "T:%3d C[H:%d][L:%d]",ui32TempValueC,ui32TempValueCMax,ui32TempValueCMin);
  1008.         } else
  1009.         {
  1010.                 flag = 0;
  1011.             sprintf ( strBuf, "T:%3d F[H:%d][L:%d]",ui32TempValueF,ui32TempValueFMax,ui32TempValueFMin);
  1012.         }
  1013.     PushButtonTextSet(&g_sPushBtn, strBuf);
  1014. }

  1015. void Timer0IntHandler(void)
  1016. {
  1017.         static uint32_t counter = 0;
  1018.         // Clear the timer interrupt
  1019.         TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  1020.     g_ui32TickCount++;

  1021.     counter++;
  1022.     if (counter > 200 )
  1023.     {        counter = 0;
  1024.         // WidgetPaint(WIDGET_ROOT);
  1025.     }

  1026. #if 0
  1027.         // Read the current state of the GPIO pin and
  1028.         // write back the opposite state
  1029.         if(GPIOPinRead(GPIO_PORTF_BASE, GPIO_PIN_2))
  1030.         {
  1031.                 GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3, 0);
  1032.         }
  1033.         else
  1034.         {
  1035.                 GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 4);
  1036.         }
  1037. #endif
  1038. }

  1039. //*****************************************************************************
  1040. //
  1041. // A simple demonstration of the features of the Stellaris Graphics Library.
  1042. //
  1043. //*****************************************************************************
  1044. int
  1045. main(void)
  1046. {
  1047.     tContext sContext;
  1048.     uint_fast16_t ui16ItemCount = 0;
  1049.         uint32_t ui32Period;
  1050.         uint32_t ui32LastTickCount;

  1051.         uint32_t ui32ADC0Value[4];
  1052.         volatile uint32_t ui32TempAvg;



  1053.     FPUEnable();
  1054.     FPULazyStackingEnable();

  1055.     // Set the clock to 40Mhz derived from the PLL and the external oscillator
  1056.     SysCtlClockSet(SYSCTL_SYSDIV_5 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);


  1057.     // setup timer 0
  1058.     SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  1059.            TimerConfigure(TIMER0_BASE, TIMER_CFG_PERIODIC);
  1060.            ui32Period = (SysCtlClockGet() / 100) / 2;
  1061.            TimerLoadSet(TIMER0_BASE, TIMER_A, ui32Period -1);
  1062.            IntEnable(INT_TIMER0A);
  1063.            TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  1064.            IntMasterEnable();

  1065.            TimerEnable(TIMER0_BASE, TIMER_A);

  1066.            // setup ADC
  1067.         SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
  1068.         ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
  1069.         ADCSequenceStepConfigure(ADC0_BASE, 1, 0, ADC_CTL_TS);
  1070.         ADCSequenceStepConfigure(ADC0_BASE, 1, 1, ADC_CTL_TS);
  1071.         ADCSequenceStepConfigure(ADC0_BASE, 1, 2, ADC_CTL_TS);
  1072.         ADCSequenceStepConfigure(ADC0_BASE, 1, 3, ADC_CTL_TS|ADC_CTL_IE|ADC_CTL_END);
  1073.         ADCSequenceEnable(ADC0_BASE, 1);


  1074.     Kentec320x240x16_SSD2119Init();    // Initialize the display driver.
  1075.     GrContextInit(&sContext, &g_sKentec320x240x16_SSD2119);    // Initialize the graphics context.

  1076. #ifdef BANNER
  1077.     // Fill the top 24 rows of the screen with blue to create the banner.
  1078.     sRect.i16XMin = 0;
  1079.     sRect.i16YMin = 0;
  1080.     sRect.i16XMax = GrContextDpyWidthGet(&sContext) - 1;
  1081.     sRect.i16YMax = 23;
  1082.     GrContextForegroundSet(&sContext, ClrDarkGoldenrod);
  1083.     GrRectFill(&sContext, &sRect);

  1084.     // Put a white box around the banner.
  1085.     GrContextForegroundSet(&sContext, ClrWhite);
  1086.     GrRectDraw(&sContext, &sRect);
  1087.     GrContextFontSet(&sContext, &g_sFontCm20);
  1088.     GrStringDrawCentered(&sContext, "grlib demo", -1,  GrContextDpyWidthGet(&sContext) / 2, 8, 0);
  1089. #endif

  1090.     // Configure and enable uDMA
  1091.     SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
  1092.     SysCtlDelay(10);
  1093.     uDMAControlBaseSet(&sDMAControlTable[0]);
  1094.     uDMAEnable();

  1095.     // Initialize the touch screen driver and have it route its messages to the
  1096.     // widget tree.
  1097.     TouchScreenInit();
  1098.     TouchScreenCallbackSet(WidgetPointerMessage);

  1099.     //
  1100.     GrOffScreen4BPPInit(&g_sOffscreenDisplay, g_pui8OffscreenBuf, SCOPE_SCREEN_WIDTH, SCOPE_SCREEN_HIGHT);
  1101.     GrOffScreen4BPPPaletteSet(&g_sOffscreenDisplay, g_pui32Palette, 0, NUM_PALETTE_ENTRIES);

  1102.     g_sSeries0.pvData = g_i8SeriesData0;
  1103.     g_sSeries1.pvData = g_i8SeriesData1;

  1104.     StripChartSeriesAdd(&g_sStripChart, &g_sSeries0);
  1105.     StripChartSeriesAdd(&g_sStripChart, &g_sSeries1);

  1106.     WidgetAdd(WIDGET_ROOT, &g_sStripChart.sBase);
  1107.     WidgetAdd(WIDGET_ROOT, (tWidget *)&g_sBackground);

  1108.     WidgetPaint(WIDGET_ROOT);

  1109.     while(1)
  1110.     {
  1111.         float fElapsedTime;
  1112.         float fRadians;
  1113.         float fSine;

  1114.         //
  1115.         // Wait for the next timer tick.
  1116.         //
  1117.         while(ui32LastTickCount == g_ui32TickCount)
  1118.         {
  1119.         }
  1120.         ui32LastTickCount = g_ui32TickCount;


  1121.             ADCIntClear(ADC0_BASE, 1);
  1122.             ADCProcessorTrigger(ADC0_BASE, 1);

  1123.             while(!ADCIntStatus(ADC0_BASE, 1, false))
  1124.             {
  1125.             }

  1126.             ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
  1127.             ui32TempAvg = (ui32ADC0Value[0] + ui32ADC0Value[1] + ui32ADC0Value[2] + ui32ADC0Value[3] + 2)/4;
  1128.             ui32TempValueC = (1475 - ((2475 * ui32TempAvg)) / 4096)/10;
  1129.             ui32TempValueF = ((ui32TempValueC * 9) + 160) / 5;

  1130.             if (ui32TempValueC>ui32TempValueCMax)
  1131.                     ui32TempValueCMax = ui32TempValueC;
  1132.             if (ui32TempValueC<ui32TempValueCMin)
  1133.                     ui32TempValueCMin = ui32TempValueC;

  1134.             if (ui32TempValueF>ui32TempValueFMax)
  1135.                     ui32TempValueFMax = ui32TempValueF;
  1136.             if (ui32TempValueF<ui32TempValueFMin)
  1137.                     ui32TempValueFMin = ui32TempValueF;

  1138.             // Preparing to add a new data point to the strip chart ...
  1139.         // If the number count of items in the strip chart has reached the
  1140.         // maximum value, then the data points need to "slide down" in the
  1141.         // buffer so new data can be added at the end.
  1142.         //
  1143.         if(ui16ItemCount == SERIES_LENGTH)
  1144.         {
  1145.             memmove(&g_i8SeriesData0[0], &g_i8SeriesData0[1], SERIES_LENGTH - 1);
  1146.             memmove(&g_i8SeriesData1[0], &g_i8SeriesData1[1], SERIES_LENGTH - 1);
  1147.         }

  1148.         //
  1149.         // Otherwise, the series data buffer is less than full so just
  1150.         // increment the count of data points.
  1151.         //
  1152.         else
  1153.         {
  1154.             //
  1155.             // Increment the number of items that have been added to the strip
  1156.             // chart series data buffer.
  1157.             //
  1158.             ui16ItemCount++;

  1159.             //
  1160.             // Since the count of data items has changed, it must be updated in
  1161.             // the data series.
  1162.             //
  1163.             g_sSeries0.ui16NumItems = ui16ItemCount;
  1164.             g_sSeries1.ui16NumItems = ui16ItemCount;
  1165.         }

  1166.         //
  1167.         // Compute the elapsed time in decimal seconds, in floating point
  1168.         // format.
  1169.         //
  1170.         fElapsedTime = (float)g_ui32TickCount * FSECONDS_PER_TICK;

  1171.         //
  1172.         // Convert the time to radians.
  1173.         //
  1174.         fRadians = fElapsedTime * 2.0 * M_PI;

  1175.         //
  1176.         // Adjust the period of the wave.  This will give us a wave period
  1177.         // of 4 seconds, or 0.25 Hz.  This number was chosen arbitrarily to
  1178.         // provide a nice looking wave on the display.
  1179.         //
  1180.         fRadians /= 4.0;

  1181.         //
  1182.         // Compute the sine.  Multiply by 0.5 to reduce the amplitude.
  1183.         //
  1184.         fSine = sinf(fRadians) * 0.5;

  1185.         //
  1186.         // Finally, save the sine value into the last location in the series
  1187.         // data point buffer.  Convert the sine amplitude to display pixels.
  1188.         // (Amplitude 1 = 32 pixels)
  1189.         //
  1190.         //g_i8SeriesData[ui16ItemCount - 1] = (int8_t)(fSine * SCOPE_SCREEN_HIGHT/2.0);
  1191.         g_i8SeriesData0[ui16ItemCount - 1] = (int8_t)( ui32TempValueC * SCOPE_SCREEN_HIGHT / 100 );
  1192.         g_i8SeriesData1[ui16ItemCount - 1] = (int8_t)( ui32TempValueF * SCOPE_SCREEN_HIGHT / 100 );

  1193.         //
  1194.         // Now that a new data point has been added to the series, advance
  1195.         // the strip chart.
  1196.         //
  1197.         StripChartAdvance(&g_sStripChart, 1);

  1198.         //
  1199.         // Request a repaint and run the widget processing queue.
  1200.         //
  1201.         //WidgetPaint(WIDGET_ROOT);
  1202.         StripChartPaint(&g_sStripChart.sBase);
  1203.         WidgetMessageQueueProcess();
  1204.     }
  1205. }





复制代码
发表于 2014-1-27 13:05:15 | 显示全部楼层
重新校准
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-12-18 13:35 , Processed in 0.028512 second(s), 10 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表