Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* SGUI example */
- #include "main.h"
- #include "stm32_ub_sgui.h"
- SLABEL_t *label, *window2_label;
- SBUTTON_t *btn1, *btn2, *btn3, *btn_ok, *btn_cancel;
- SLED_t* led1;
- volatile uint8_t action;
- //--------------------------------------------------------------
- void create_Window1(void);
- //--------------------------------------------------------------
- /* Handle "On" button */
- void btn1_fkt(bool aktiv) {
- if (aktiv == false) {
- /* Set action, Led On if OK pressed */
- action = 0x00;
- SGUI_LabelSetText(window2_label, "LED On?");
- SGUI_WindowShow(2);
- }
- }
- /* Handle "Off" button */
- void btn2_fkt(bool aktiv) {
- if (aktiv == false) {
- /* Set action, Led Off if OK pressed */
- action = 0x01;
- SGUI_LabelSetText(window2_label, "LED Off?");
- SGUI_WindowShow(2);
- }
- }
- /* Handle "Toggle" button */
- void btn3_fkt(bool aktiv) {
- if (aktiv == false) {
- /* Set action, Led toggle if OK pressed */
- action = 0x02;
- SGUI_LabelSetText(window2_label, "Toggle?");
- SGUI_WindowShow(2);
- }
- }
- /* Handle "OK" button */
- void btn_ok_handler(bool aktiv) {
- /* On button release */
- if (aktiv == false) {
- switch (action) {
- case 0x00:
- SGUI_LedSetAktiv(led1, true);
- break;
- case 0x01:
- SGUI_LedSetAktiv(led1, false);
- break;
- case 0x02:
- SGUI_LedToggle(led1);
- break;
- default:
- break;
- }
- /* Confirm and close window */
- SGUI_WindowShowPrev();
- }
- }
- /* Handle "Cancel" button */
- void btn_cancel_handler(bool aktiv) {
- /* Close window */
- if (aktiv == false) {
- SGUI_WindowShowPrev();
- }
- }
- void create_Window1(void) {
- /* Create main window */
- SGUI_WindowCreateMain(1);
- /* Create label for main window */
- label=SGUI_LabelCreate(10,10,220,50);
- SGUI_LabelSetText(label,"Window-1");
- /* Led settings */
- led1 = SGUI_LedCreate(120, 300, 18);
- SGUI_LedSetAktiv(led1, false);
- SGUI_LedSetFrameSize(led1, 5);
- /* Create 3 buttons */
- /* Led ON */
- btn1 = SGUI_ButtonCreate(10, 100, 219, 50);
- SGUI_ButtonSetText(btn1, "LED On");
- SGUI_ButtonSetHandler(btn1, btn1_fkt);
- /* Led Off */
- btn2 = SGUI_ButtonCreate(10, 160, 219, 50);
- SGUI_ButtonSetText(btn2, "LED Off");
- SGUI_ButtonSetHandler(btn2, btn2_fkt);
- /* Led Toggle */
- btn3 = SGUI_ButtonCreate(10, 220, 219, 50);
- SGUI_ButtonSetText(btn3, "LED Toggle");
- SGUI_ButtonSetHandler(btn3, btn3_fkt);
- /* Create child window for "Alert" messages */
- SGUI_WindowCreateChild(2, 10, 10, 219, 150);
- window2_label = SGUI_LabelCreate(10, 10, 200, 50);
- SGUI_LabelSetText(window2_label, "Child window");
- /* Create 2 more buttons */
- /* "OK" confirm button */
- btn_ok = SGUI_ButtonCreate(10, 90, 95, 50);
- SGUI_ButtonSetText(btn_ok, "OK");
- SGUI_ButtonSetHandler(btn_ok, btn_ok_handler);
- /* "Cancel" discard button */
- btn_cancel = SGUI_ButtonCreate(115, 90, 95, 50);
- SGUI_ButtonSetText(btn_cancel, "Cancel");
- SGUI_ButtonSetHandler(btn_cancel, btn_cancel_handler);
- }
- /* Main functions */
- int main(void) {
- /* System init */
- SystemInit();
- /* SGUI Initialize */
- SGUI_Init();
- /* Create windows */
- create_Window1();
- /* Show window 1 */
- SGUI_WindowShow(1);
- while(1) {
- /* Do stuff */
- SGUI_Do();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement