Advertisement
Guest User

Untitled

a guest
Jan 20th, 2015
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.15 KB | None | 0 0
  1. /* SGUI example */
  2. #include "main.h"
  3. #include "stm32_ub_sgui.h"
  4.  
  5. SLABEL_t *label, *window2_label;
  6. SBUTTON_t *btn1, *btn2, *btn3, *btn_ok, *btn_cancel;
  7. SLED_t* led1;
  8. volatile uint8_t action;
  9.  
  10. //--------------------------------------------------------------
  11. void create_Window1(void);
  12. //--------------------------------------------------------------
  13.  
  14. /* Handle "On" button */
  15. void btn1_fkt(bool aktiv) {
  16.     if (aktiv == false) {
  17.         /* Set action, Led On if OK pressed */
  18.         action = 0x00;
  19.         SGUI_LabelSetText(window2_label, "LED On?");
  20.         SGUI_WindowShow(2);
  21.     }
  22. }
  23.  
  24. /* Handle "Off" button */
  25. void btn2_fkt(bool aktiv) {
  26.     if (aktiv == false) {
  27.         /* Set action, Led Off if OK pressed */
  28.         action = 0x01;
  29.         SGUI_LabelSetText(window2_label, "LED Off?");
  30.         SGUI_WindowShow(2);
  31.     }
  32. }
  33.  
  34. /* Handle "Toggle" button */
  35. void btn3_fkt(bool aktiv) {
  36.     if (aktiv == false) {
  37.         /* Set action, Led toggle if OK pressed */
  38.         action = 0x02;
  39.         SGUI_LabelSetText(window2_label, "Toggle?");
  40.         SGUI_WindowShow(2);
  41.     }
  42. }
  43.  
  44. /* Handle "OK" button */
  45. void btn_ok_handler(bool aktiv) {
  46.     /* On button release */
  47.     if (aktiv == false) {
  48.         switch (action) {
  49.             case 0x00:
  50.                 SGUI_LedSetAktiv(led1, true);
  51.                 break;
  52.             case 0x01:
  53.                 SGUI_LedSetAktiv(led1, false);
  54.                 break;
  55.             case 0x02:
  56.                 SGUI_LedToggle(led1);
  57.                 break;
  58.             default:
  59.                 break;
  60.         }
  61.  
  62.         /* Confirm and close window */
  63.         SGUI_WindowShowPrev();
  64.     }
  65. }
  66.  
  67. /* Handle "Cancel" button */
  68. void btn_cancel_handler(bool aktiv) {
  69.     /* Close window */
  70.     if (aktiv == false) {
  71.         SGUI_WindowShowPrev();
  72.     }
  73. }
  74.  
  75. void create_Window1(void) {
  76.     /* Create main window */
  77.     SGUI_WindowCreateMain(1);
  78.     /* Create label for main window */
  79.     label=SGUI_LabelCreate(10,10,220,50);
  80.     SGUI_LabelSetText(label,"Window-1");
  81.  
  82.     /* Led settings */
  83.     led1 = SGUI_LedCreate(120, 300, 18);
  84.     SGUI_LedSetAktiv(led1, false);
  85.     SGUI_LedSetFrameSize(led1, 5);
  86.  
  87.     /* Create 3 buttons */
  88.     /* Led ON */
  89.     btn1 = SGUI_ButtonCreate(10, 100, 219, 50);
  90.     SGUI_ButtonSetText(btn1, "LED On");
  91.     SGUI_ButtonSetHandler(btn1, btn1_fkt);
  92.     /* Led Off */
  93.     btn2 = SGUI_ButtonCreate(10, 160, 219, 50);
  94.     SGUI_ButtonSetText(btn2, "LED Off");
  95.     SGUI_ButtonSetHandler(btn2, btn2_fkt);
  96.     /* Led Toggle */
  97.     btn3 = SGUI_ButtonCreate(10, 220, 219, 50);
  98.     SGUI_ButtonSetText(btn3, "LED Toggle");
  99.     SGUI_ButtonSetHandler(btn3, btn3_fkt);
  100.  
  101.     /* Create child window for "Alert" messages */
  102.     SGUI_WindowCreateChild(2, 10, 10, 219, 150);
  103.     window2_label = SGUI_LabelCreate(10, 10, 200, 50);
  104.     SGUI_LabelSetText(window2_label, "Child window");
  105.  
  106.     /* Create 2 more buttons */
  107.     /* "OK" confirm button */
  108.     btn_ok = SGUI_ButtonCreate(10, 90, 95, 50);
  109.     SGUI_ButtonSetText(btn_ok, "OK");
  110.     SGUI_ButtonSetHandler(btn_ok, btn_ok_handler);
  111.     /* "Cancel" discard button */
  112.     btn_cancel = SGUI_ButtonCreate(115, 90, 95, 50);
  113.     SGUI_ButtonSetText(btn_cancel, "Cancel");
  114.     SGUI_ButtonSetHandler(btn_cancel, btn_cancel_handler);
  115. }
  116.  
  117. /* Main functions */
  118. int main(void) {
  119.     /* System init */
  120.     SystemInit();
  121.  
  122.     /* SGUI Initialize */
  123.     SGUI_Init();
  124.  
  125.     /* Create windows */
  126.     create_Window1();
  127.  
  128.     /* Show window 1 */
  129.     SGUI_WindowShow(1);
  130.  
  131.     while(1) {
  132.         /* Do stuff */
  133.         SGUI_Do();
  134.     }
  135. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement