Sample program using the menu display functions of the AdvancedMenu library.

This sample program displays the following screen.

main()

  

settings()

  • Uses check box.
  • Uses numeric input field.
  • Display using AM_JUMP_MARK.
     

edit_name()

  • Uses alphabetic input field.
  • Displays shift mode.
  • Displays candidate characters.
  

task1()

  • Read only the barcode of EAN/UPC.

task2()

  • Read only the barcode of EAN/UPC.
  • You can also enter the barcode by key input.
  

task3()

  • Read QR code.
  • The read result is displayed in the multi-line input field (AM_TEXT_EDIT).

Sample

#include <stdio.h>
#include <string.h>
#include "lib.h"
#include "AdvancedMenu.h"

// Prototypes
void settings(MENU_HANDLE hMain);
void edit_name(char *namebuf, int length);
void task1(void);
void task2(void);
void task3(void);

///////////////////////////////////////////////////////////////////
// Color palettes
///////////////////////////////////////////////////////////////////
#define MENU_FORE_COLOR     RGB_WHITE
#define MENU_BACK_COLOR     0x427cbe    //Dull blue
#define MENU_BUTTON_COLOR   RGB_YELLOW
#define MENU_APPLY_COLOR    0xfcd9ff    //Color of Start icon (Light pink)
#define MENU_SELECT_COLOR   0x284a70    //Dark blue

#define FORE_COLOR          RGB_WHITTE
#define BACK_COLOR          0xf7f7f7    //Light gray
#define SELECT_COLOR        RGB_BLUE
#define DISABLE_COLOR       0xb0b0b0    //Gray
#define GIUDE_BUTTON        RGB_BLUE
#define APPLY_COLOR         RGB_MAGENTA
#define TITLE_SET_COLOR     RGB_BLUE
#define TITLE_TASK_COLOR    0x008000    //Dark Green

static const AM_ColorPalette CustomColor[] = {
    //ForeColor,        BackColor,        Select_ForeColor, Select_BackColor,  Control_ForeColor
    { MENU_FORE_COLOR,  MENU_BACK_COLOR,  RGB_WHITE,        MENU_SELECT_COLOR, MENU_BUTTON_COLOR }, //#0: Task menu base color
    { MENU_FORE_COLOR,  MENU_BACK_COLOR,  0,                0,                 MENU_APPLY_COLOR  }, //#1: Task menu apply color
    { RGB_BLACK,        BACK_COLOR,       RGB_WHITE,        SELECT_COLOR,      GIUDE_BUTTON      }, //#2: Base color
    { RGB_WHITE,        RGB_BLUE,         0,                0,                 0                 }, //#3: Title of Setting
    { GIUDE_BUTTON,     BACK_COLOR,       0,                0,                 GIUDE_BUTTON      }, //#4: Guide color
    { RGB_WHITE,        TITLE_TASK_COLOR, 0,                0,                 0                 }, //#5: Title 0f tasks
    { RGB_BLACK,        RGB_WHITE,        RGB_BLACK,        RGB_YELLOW,        RGB_BLUE          }, //#6: Input field color
    { APPLY_COLOR,      BACK_COLOR,       0,                0,                 APPLY_COLOR       }, //#7: Apply color
};
#define PX_MENU           0	 // Task menu base color
#define PX_MENU_APPLY     1  // Task menu apply color
#define PX_BASE           2  // Base color
#define PX_TITLE_SETTING  3  // Title of Setting
#define PX_GUIDE          4  // Guide color
#define PX_TITLE_TASK     5  // Title 0f tasks
#define PX_EDIT           6  // Input field color
#define PX_APPLY          7  // Apply color

///////////////////////////////////////////////////////////////////
// Task menu screen
///////////////////////////////////////////////////////////////////

// Options for the task menu screen
static const AM_Option MenuOption = {
    MENU_FORE_COLOR,                                // MenuForeColor
    DISABLE_COLOR,                                  // MenuDisabledForeColor
    MENU_BACK_COLOR,                                // MenuBackColor
    sizeof(CustomColor)/sizeof(AM_ColorPalette),  	// NumberOfColorPalette
    (pAM_ColorPalette)CustomColor,                  // ColorPalettes
    0,                                              // OptionFlag
    HUGE_FONT,                                      // DefaultFont
    1                                               // DefaultLineSpacing
};

// Definition of the task menu screen
// Item ID
enum _MAIN_ITEM_ID {
    MENU_ID_TASK1 = 1,
    MENU_ID_TASK2,
    MENU_ID_TASK3,
    MENU_ID_NOTASK,
    MENU_ID_START,
};
// Table of the menu items for the task menu screen
static const AM_MenuItem MainMenuTable[] = {
//   itemID,        y,           x, menuText,     Palette,       visible, enabled, selectable, showControl,   checked, font
    {MENU_ID_TASK1, 1,           1, " Task #1 ",  PX_MENU,       true,    true,    true,       AM_NO_CONTROL},
    {MENU_ID_TASK2, 2,           1, " Task #2 ",  PX_MENU,       true,    true,    true,       AM_NO_CONTROL},
    {MENU_ID_TASK3, 3,           1, " Task #3 ",  PX_MENU,       true,    true,    true,       AM_NO_CONTROL},
    {MENU_ID_NOTASK,1,           1, "No task",    PX_MENU,       false,   true,    false,      AM_NO_CONTROL},
    {0,             AM_PIX(114), 0, "Settings",   PX_MENU,       true,    true,    false,      AM_F1_ICON,    false,   MEDIUM_FONT},
    {MENU_ID_START, AM_PIX(129), 0, "Start task", PX_MENU_APPLY, true,    true,    false,      AM_SCAN_ICON,  false,   MEDIUM_FONT},
    {-1}
};

void main(void)
{
    MENU_HANDLE hMenu;
    int event;
    int task;

    hMenu = AM_CreateMenu(MainMenuTable, (const pAM_Option)&MenuOption);

    while(1){
        // Update "enabled" property of the [Start] icon.
        AM_SetEnabled(hMenu, MENU_ID_START, AM_IsVisible(hMenu, MENU_ID_TASK1) || AM_IsVisible(hMenu, MENU_ID_TASK2) || AM_IsVisible(hMenu, MENU_ID_TASK3));
        // Display "No task" when the [start] icon is disabled.
        AM_SetVisible(hMenu, MENU_ID_NOTASK, !AM_IsEnabled(hMenu, MENU_ID_START));

        // Update task menu screen.
        AM_ShowMenu(hMenu, AM_SELECT_ANY_ID);

        while(1){
            event = AM_ExecMenu(hMenu);
            if (event == F1_KEY){
                // Open setting screen
                AM_StopUpdateScreen(hMenu);
                settings(hMenu);
                break;
            }else if (event == SCAN_KEY){
                // Open screen of selected task.
                task = AM_GetSelectedLine(hMenu);
                switch (task){
                case MENU_ID_TASK1:
                    task1();
                    break;
                case MENU_ID_TASK2:
                    task2();
                    break;
                case MENU_ID_TASK3:
                    task3();
                    break;
                default:
                    continue;
                }
                break;
            }
        }
    }
}


////////////////////////////////////////////////////
// Setting screen
////////////////////////////////////////////////////

// Options for the setting screen
static const AM_Option SettingOption = {
    RGB_BLACK,                                      // MenuForeColor
    DISABLE_COLOR,                                  // MenuDisabledForeColor
    BACK_COLOR,                                     // MenuBackColor
    sizeof(CustomColor)/sizeof(AM_ColorPalette),  	// NumberOfColorPalette
    (pAM_ColorPalette)CustomColor,                  // ColorPalettes
    0,                                              // OptionFlag
    MEDIUM_FONT,                                    // DefaultFont
    1                                               // DefaultLineSpacing
};

// Text field parameter
static char UID_EditBuf[8+1] = {""};
static const AM_EditParam EditParamUID = {
    8,                  // MaxDigits
    RGB_WHITE,          // Cursor foregraund Color
    RGB_BLUE,           // Cursor backgraund Color
    RGB_WHITE,          // Shift mode foregraund Color
    RGB_BLUE,           // Shift mode backgraund Color
    AM_EDIT_NUMERIC|AM_EDIT_UNDERLINE|AM_EDIT_CLEAR_ON_FIRST_CHAR|AM_EDIT_NO_CURSOR,    // EditOption
    NULL,               // alphaCandidateTable
    UID_EditBuf,        // Value
    sizeof(UID_EditBuf) // ValueBufSize
};
static char Name_Buf[20+1] = {""};

// Item ID
enum _SETTING_ITEM_ID {
    SET_ID_TASK1 = 1,
    SET_ID_TASK2,
    SET_ID_TASK3,
    SET_ID_UID,
    SET_ID_NAME,
    SET_ID_APPLY,
};

// Table of the menu items for the setting screen
static const AM_MenuItem SettingtMenuTable[] = {
//   itemID,       y,           x,          menuText,                 Palette,          visible, enabled, selectable, showControl
    {0,            0,           0,          "Settings",               PX_TITLE_SETTING, true,    true,    false,      AM_TITLE_LINE},
    {SET_ID_TASK1, 2,           1,          " Task #1 ",              PX_BASE,          true,    true,    true,       AM_CHECK_BOX},
    {SET_ID_TASK2, 3,           1,          " Task #2 ",              PX_BASE,          true,    true,    true,       AM_CHECK_BOX},
    {SET_ID_TASK3, 4,           1,          " Task #3 ",              PX_BASE,          true,    true,    true,       AM_CHECK_BOX},
    {0,            6,           1,          "UserID:",                PX_BASE,          true,    true,    false,      AM_NO_CONTROL},
    {SET_ID_UID,   6,           9,          (void *)&EditParamUID,    PX_EDIT,          true,    true,    true,       AM_TEXT_EDIT},
    {0,            8,           1,          "Name:",                  PX_BASE,          true,    true,    false,      AM_NO_CONTROL},
    {SET_ID_NAME,  8,           7,          "",                       PX_BASE,          true,    true,    true,       AM_JUMP_MARK},
    {0,            AM_PIX(129), 0,          "Cancel",                 PX_GUIDE,         true,    true,    false,      AM_CLEAR_ICON},
    {SET_ID_APPLY, AM_PIX(129), AM_PIX(64), "Apply",                  PX_APPLY,         true,    true,    false,      AM_ENT_ICON},
    {-1}
};

void settings(MENU_HANDLE hMain)
{
    MENU_HANDLE hMenu;
    int event;
    bool exit = false;

    hMenu = AM_CreateMenu(SettingtMenuTable, (const pAM_Option)&SettingOption);

    AM_SetChecked(hMenu, SET_ID_TASK1, AM_IsVisible(hMain, MENU_ID_TASK1));
    AM_SetChecked(hMenu, SET_ID_TASK2, AM_IsVisible(hMain, MENU_ID_TASK2));
    AM_SetChecked(hMenu, SET_ID_TASK3, AM_IsVisible(hMain, MENU_ID_TASK3));

    while(1){
        if (strlen(Name_Buf) > 0){
            AM_SetText(hMenu, SET_ID_NAME, Name_Buf);
        }else{
            AM_SetText(hMenu, SET_ID_NAME, "< Blank >");
        }
        AM_ShowMenu(hMenu, AM_SELECT_ANY_ID);

        while(1){
            event = AM_ExecMenu(hMenu);
            if (event == CLR_KEY){
                exit = true;
                break;
            }else if (event == SCAN_KEY){
                if (AM_GetSelectedLine(hMenu) == SET_ID_NAME){
                    edit_name(Name_Buf, sizeof(Name_Buf));
                    break;
                }
            }else if (event == ENT_KEY){
                AM_SetVisible(hMain, MENU_ID_TASK1, AM_IsChecked(hMenu, SET_ID_TASK1));
                AM_SetVisible(hMain, MENU_ID_TASK2, AM_IsChecked(hMenu, SET_ID_TASK2));
                AM_SetVisible(hMain, MENU_ID_TASK3, AM_IsChecked(hMenu, SET_ID_TASK3));
                exit = true;
                break;
            }
        }
        if (exit){
            break;
        }
    }

    AM_ReleaseMenu(hMenu);
    return;
}

////////////////////////////////////////////////////
// Name screen
////////////////////////////////////////////////////

void edit_name(char *namebuf, int length)
{
    /////////////////////////////////////////
    // Local definition of the menu items
    /////////////////////////////////////////
    static char name_EditBuf[20+1] = {""};
    static const AM_EditParam EditParamName = {
        20,                  // MaxDigits
        RGB_WHITE,           // Cursor foregraund Color
        RGB_BLUE,            // Cursor backgraund Color
        RGB_WHITE,           // Shift mode foregraund Color
        RGB_BLUE,            // Shift mode backgraund Color
        AM_EDIT_SET_ALPHA | AM_EDIT_MOVE_CURSOR_BY_Q1Q2,    // EditOption
        NULL,                // alphaCandidateTable
        name_EditBuf,        // Value
        sizeof(name_EditBuf) // ValueBufSize
    };

    // Item ID
    enum _SETTING_NAME_ITEM_ID {
        SET_ID_ENAME = 1,
        SET_ID_EAPPLY,
    };

    // Table of the menu items for the name screen
    static const AM_MenuItem SettingtNameTable[] = {
    //   itemID,       y,           x,          menuText,                Palette,          visible, enabled, selectable, showControl
        {0,            0,           0,          "Name",                  PX_TITLE_SETTING, true,    true,    false,      AM_TITLE_LINE},
        {0,            2,           1,          "Name:",                 PX_BASE,          true,    true,    false,      AM_NO_CONTROL},
        {SET_ID_ENAME, 3,           1,          (void *)&EditParamName,  PX_EDIT,          true,    true,    true,       AM_TEXT_EDIT},
        {0,            5,           1,          "",                      PX_GUIDE,         true,    true,    false,      AM_SHIFT_MODE},
        {0,            5,           7,          "",                      PX_GUIDE,         true,    true,    false,      AM_SHIFT_CANDIDATE},
        {0,            AM_PIX(129), 0,          "Cancel",                PX_GUIDE,         true,    true,    false,      AM_CLEAR_ICON},
        {SET_ID_EAPPLY,AM_PIX(129), AM_PIX(64), "Apply",                 PX_APPLY,         true,    true,    false,      AM_ENT_ICON},
        {-1}
    };
    /////////////////////////////////////////

    MENU_HANDLE hMenu;
    int event;

    strncpy(name_EditBuf, namebuf, sizeof(name_EditBuf)-1);

    hMenu = AM_CreateMenu(SettingtNameTable, (const pAM_Option)&SettingOption);

    AM_ShowMenu(hMenu, AM_SELECT_ANY_ID);

    while(1){
        event = AM_ExecMenu(hMenu);
        if (event == CLR_KEY){
            break;
        }else if (event == ENT_KEY){
            memset(namebuf, 0, length);
            strncpy(namebuf, name_EditBuf, length - 1);
            break;
        }
    }
    AM_ReleaseMenu(hMenu);
    return;
}

////////////////////////////////////////////////////
// Task #1: Read EAN/UPC code
////////////////////////////////////////////////////

// Options for task #1, #2  and #3 screen
static const AM_Option TaskOption = {
    RGB_BLACK,                                      // MenuForeColor
    DISABLE_COLOR,                                  // MenuDisabledForeColor
    BACK_COLOR,                                     // MenuBackColor
    sizeof(CustomColor)/sizeof(AM_ColorPalette),  	// NumberOfColorPalette
    (pAM_ColorPalette)CustomColor,                  // ColorPalettes
    0,                                              // OptionFlag
    MEDIUM_FONT,                                    // DefaultFont
    1                                               // DefaultLineSpacing
};


// Definition of the task #1 screen
// Item ID
enum _TASK1_ITEM_ID {
    TASK1_ID_RESULT = 1,
};

// Table of the menu items for task #1 screen
static const AM_MenuItem Task1MenuTable[] = {
//   itemID,           y,           x,          menuText,              Palette,       visible, enabled, selectable, showControl,   checked, font
    {0,                0,           0,          "Task #1",             PX_TITLE_TASK, true,    true,    false,      AM_TITLE_LINE, false,   LARGE_FONT},
    {0,                2,           1,          "Read EAN/UPC code.",  PX_BASE,       true,    true,    false,      AM_NO_CONTROL},
    {TASK1_ID_RESULT,  4,           1,          "",                    PX_BASE,       true,    true,    false,      AM_NO_CONTROL},
    {0,                AM_PIX(114), 0,          "Read barcode",        PX_GUIDE,      true,    true,    false,      AM_SCAN_ICON},
    {0,                AM_PIX(129), 0,          "Exit",                PX_GUIDE,      true,    true,    false,      AM_CLEAR_ICON},
    {-1}
};

void task1(void)
{
    MENU_HANDLE hMenu;
    int event;
    char barcodebuff[13+1];
    AM_BarcodeBuffer buffer;

    buffer.dataBuf = barcodebuff;
    buffer.dataBufLength = sizeof(barcodebuff);

    hMenu = AM_CreateMenu(Task1MenuTable, (const pAM_Option)&TaskOption);

    // Set option commands
    //  B0:  Disable all symbology
    //  R1:  Enable UPC
    //  R4:  Enable EAN/JAN
    AM_ConfigBarcodeReader(hMenu, &buffer, "B0R1R4");

    AM_ShowMenu(hMenu, AM_SELECT_NO_ID);
    AM_EnableBarcodeReader(hMenu);

    while(1){
        event = AM_ExecMenu(hMenu);
        // Waiting scan
        if (event == AMENU_BARCODE_READ){
            AM_DisableBarcodeReader(hMenu);
            // Got result
            AM_SetText(hMenu, TASK1_ID_RESULT, barcodebuff);
            AM_EnableBarcodeReader(hMenu);
            continue;
        }else if (event == CLR_KEY){
            //Exit
            break;
        }
    }
    AM_DisableBarcodeReader(hMenu);

    AM_ReleaseMenu(hMenu);
    return;
}


////////////////////////////////////////////////////
// Task #2: Read EAN/UPC code or input with keyboard
////////////////////////////////////////////////////

// Text field parameter
static char EAN_EditBuf[16] = {""};
static const AM_EditParam EditParamEAN = {
    13,                 // MaxDigits
    RGB_WHITE,          // Cursor foregraund Color
    RGB_BLUE,           // Cursor backgraund Color
    RGB_WHITE,          // Shift mode foregraund Color
    RGB_BLUE,           // Shift mode backgraund Color
    AM_EDIT_NUMERIC,    // EditOption
    NULL,               // alphaCandidateTable
    EAN_EditBuf,        // Value
    sizeof(EAN_EditBuf) // ValueBufSize
};

// Definition of task #2 screen
// Item ID
enum _TASK2_ITEM_ID {
    TASK2_ID_BARCODE = 1,
    TASK2_ID_RESULT,
    TASK2_ID_SCAN,
    TASK2_ID_EXIT,
    TASK2_ID_CANCEL,
    TASK2_ID_APPLY,
};

// Table of the menu items for task #2 screen
static const AM_MenuItem Task2MenuTable[] = {
//   itemID,           y,           x,          menuText,              Palette,       visible, enabled, selectable, showControl,   checked, font
    {0,                0,           0,          "Task #2",             PX_TITLE_TASK, true,    true,    false,      AM_TITLE_LINE, false,   LARGE_FONT},
    {0,                2,           1,          "EAN/UPC code:",       PX_BASE,       true,    true,    false,      AM_NO_CONTROL},
    {TASK2_ID_BARCODE, AM_PIX(42),  1,          (void *)&EditParamEAN, PX_EDIT,       true,    true,    false,      AM_TEXT_EDIT,  false,   LARGE_FONT},
    {0,                5,           1,          "Result:",             PX_BASE,       true,    true,    false,      AM_NO_CONTROL},
    {TASK2_ID_RESULT,  6,           2,          "",                    PX_BASE,       true,    true,    false,      AM_NO_CONTROL},
    {TASK2_ID_SCAN,    AM_PIX(114), 0,          "Read barcode",        PX_GUIDE,      true,    true,    false,      AM_SCAN_ICON},
    {TASK2_ID_EXIT,    AM_PIX(129), 0,          "Exit",                PX_GUIDE,      true,    true,    false,      AM_CLEAR_ICON},
    {TASK2_ID_CANCEL,  AM_PIX(129), 0,          "Cancel",              PX_GUIDE,      false,   true,    false,      AM_CLEAR_ICON},
    {TASK2_ID_APPLY,   AM_PIX(129), AM_PIX(64), "Apply",               PX_APPLY,      false,   true,    false,      AM_ENT_ICON},
    {-1}
};

void task2(void)
{
    MENU_HANDLE hMenu;
    int event;
    bool nowEditing = false;
    char barcodebuff[32];
    AM_BarcodeBuffer buffer;

    buffer.dataBuf = barcodebuff;
    buffer.dataBufLength = sizeof(barcodebuff);
    memset(EAN_EditBuf,0,sizeof(EAN_EditBuf));

    hMenu = AM_CreateMenu(Task2MenuTable, (const pAM_Option)&TaskOption);

    // Set option commands
    //  B0:  Disable all symbology
    //  R1:  Enable UPC
    //  R4:  Enable EAN/JAN
    AM_ConfigBarcodeReader(hMenu, &buffer, "B0R1R4");

    AM_ShowMenu(hMenu, AM_SELECT_NO_ID);
    AM_EnableBarcodeReader(hMenu);

    while(1){
        event = AM_ExecMenu(hMenu);
        if (!nowEditing){
            // Waiting scan
            if (event == AMENU_BARCODE_READ){
                AM_DisableBarcodeReader(hMenu);
                AM_SetText(hMenu, TASK2_ID_BARCODE, barcodebuff);
                // Got result
                AM_SetText(hMenu, TASK2_ID_RESULT, barcodebuff);
                AM_EnableBarcodeReader(hMenu);
                continue;
            }else if(event >='0' && event<='9'){
                char work[2];
                work[0] = event;
                work[1] = 0;
                AM_SetText(hMenu, TASK2_ID_BARCODE, work);
                //Switch to edit mode
                AM_DisableBarcodeReader(hMenu);
                nowEditing=true;
                AM_SetSelectable(hMenu, TASK2_ID_BARCODE, true);
                AM_SelectLine(hMenu, TASK2_ID_BARCODE);
                AM_SetVisibleRange(hMenu, TASK2_ID_SCAN, TASK2_ID_EXIT, false);
                AM_SetVisibleRange(hMenu, TASK2_ID_CANCEL, TASK2_ID_APPLY, true);
                continue;
            }else if (event == CLR_KEY){
                //Exit
                break;
            }

        }else{
            // Edit mode
            if (event == CLR_KEY){
                //Cancel
                //Switch to scan mode
                AM_SelectLine(hMenu, AM_SELECT_NO_ID);
                AM_SetSelectable(hMenu, TASK2_ID_BARCODE, false);
                AM_SetText(hMenu, TASK2_ID_BARCODE, "");
                AM_EnableBarcodeReader(hMenu);
                nowEditing=false;
                AM_SetVisibleRange(hMenu, TASK2_ID_CANCEL, TASK2_ID_APPLY, false);
                AM_SetVisibleRange(hMenu, TASK2_ID_SCAN, TASK2_ID_EXIT, true);
                continue;
            }else if (event == ENT_KEY){
                // Got result
                AM_SetText(hMenu, TASK2_ID_RESULT, EAN_EditBuf);
                AM_SelectLine(hMenu, AM_SELECT_NO_ID);
                AM_SetSelectable(hMenu, TASK2_ID_BARCODE, false);
                //Switch to scan mode
                AM_EnableBarcodeReader(hMenu);
                nowEditing = false;
                AM_SetVisibleRange(hMenu, TASK2_ID_CANCEL, TASK2_ID_APPLY, false);
                AM_SetVisibleRange(hMenu, TASK2_ID_SCAN, TASK2_ID_EXIT, true);
                continue;
            }
        }

    }
    AM_DisableBarcodeReader(hMenu);

    AM_ReleaseMenu(hMenu);
    return;
}

////////////////////////////////////////////////////
// Task #3: Read QR code
////////////////////////////////////////////////////

// Text field parameter
static char QR_EditBuf[60+1] = {""};
static const AM_EditParam EditParamQR1 = {
    20,                 // MaxDigits
    0,                  // Cursor foregraund Color
    0,                  // Cursor backgraund Color
    0,                  // Shift mode foregraund Color
    0,                  // Shift mode backgraund Color
    0,                  // EditOption
    NULL,               // alphaCandidateTable
    QR_EditBuf,         // Value
    sizeof(QR_EditBuf)  // ValueBufSize
};
static const AM_EditParam EditParamQR2 = {
    20                  // MaxDigits
};
static const AM_EditParam EditParamQR3 = {
    20                  // MaxDigits
};

// Definition of the task #3 screen
// Item ID
enum _TASK3_ITEM_ID {
    TASK3_ID_RESULT = 1,
};

// Table of the menu items for task #3 screen
static const AM_MenuItem Task3MenuTable[] = {
//   itemID,           y,           x,          menuText,              Palette,       visible, enabled, selectable, showControl,   checked, font,        itemOption
    {0,                0,           0,          "Task #3",             PX_TITLE_TASK, true,    true,    false,      AM_TITLE_LINE, false,   LARGE_FONT},
    {0,                2,           1,          "Read QR code.",       PX_BASE,       true,    true,    false,      AM_NO_CONTROL},
    {TASK3_ID_RESULT,  4,           1,          (void *)&EditParamQR1, PX_EDIT,       true,    true,    false,      AM_TEXT_EDIT,  false,   MEDIUM_FONT, AM_MULTI_START},
    {0,                5,           1,          (void *)&EditParamQR2, PX_EDIT,       true,    true,    false,      AM_TEXT_EDIT,  false,   MEDIUM_FONT, AM_MULTI_MID},
    {0,                6,           1,          (void *)&EditParamQR3, PX_EDIT,       true,    true,    false,      AM_TEXT_EDIT,  false,   MEDIUM_FONT, AM_MULTI_END},
    {0,                AM_PIX(114), 0,          "Read barcode",        PX_GUIDE,      true,    true,    false,      AM_SCAN_ICON},
    {0,                AM_PIX(129), 0,          "Exit",                PX_GUIDE,      true,    true,    false,      AM_CLEAR_ICON},
    {-1}
};

void task3(void)
{
    MENU_HANDLE hMenu;
    int event;
    char barcodebuff[64+1];
    AM_BarcodeBuffer buffer;

    buffer.dataBuf = barcodebuff;
    buffer.dataBufLength = sizeof(barcodebuff);

    memset(QR_EditBuf,0,sizeof(QR_EditBuf));

    hMenu = AM_CreateMenu(Task3MenuTable, (const pAM_Option)&TaskOption);

    // Set option commands
    //  [BC1:  Enable QR
    AM_ConfigBarcodeReader(hMenu, &buffer, "[BC1");

    AM_ShowMenu(hMenu, AM_SELECT_NO_ID);
    AM_EnableBarcodeReader(hMenu);

    while(1){
        event = AM_ExecMenu(hMenu);
        // Waiting scan
        if (event == AMENU_BARCODE_READ){
            AM_DisableBarcodeReader(hMenu);
            // Got result
            AM_SetText(hMenu, TASK3_ID_RESULT, barcodebuff);
            AM_EnableBarcodeReader(hMenu);
            continue;
        }else if (event == CLR_KEY){
            //Exit
            break;
        }
    }
    AM_DisableBarcodeReader(hMenu);

    AM_ReleaseMenu(hMenu);
    return;
}




Last updated: 2021/11/11