AddMenuOptionTable

Availability All terminals
Description Function that makes it possible to extend the list of already supported menu options by adding a table with additional menu options.
Syntax int AddMenuOptionTable( OPTION menu_table[], int nr_of_entries );
Arguments
OPTION menu_table[]
Array of menu options. The structure OPTION is defined as follows:
typedef const struct
{
    char code[4];
    void* variable;
    unsigned char clear_mask;
    unsigned char set_mask;
}OPTION;
Member Description
code String of 2, 3 or 4 characters containing a unique menu option code. If the added menu option code is already supported by the OS it will overrule the existing OS functionality.
variable Pointer to the address of a 1 byte variable that can be logically changed using 'set_mask' and 'clear_mask'. Alternatively it can also used to point to a function that needs to be executed when the menu option is read.
clear_mask set_mask clear_mask & set_mask can be used to clear and set bits of 'variable'. For example, using 0xFF as clear_mask value will reset all 8 bits to zero and using 0x07 as set_mask will set bit 0,1,2 to one.
In case 'variable' is used as a function pointer, then both 'clear_mask' and 'set_mask' need to be set to 0xFF.
Returns
OK The menu option table has been added to the OS.
Remarks - Adding a menu option table can be especially useful in combination with the ExecuteMenuLabel() function, which makes it possible to read menu labels like non-terminal Opticon barcode readers.
- To remove a previously added menu option table, call this function again with 'NULL' as the parameter for 'menu_table[]'.
- An added menu option table will need to be added again after a restart since it will not be stored in non-volatile memory.
- If an added menu option code is already supported by the OS, then it will overrule the existing OS functionality. However, it's also possible to inherit the old functionality by adding a SystemSetting() call to the existing OS menu option in the added menu option function.
- See also ApplicationSettingsMemorizing() and SystemSettingsMemorizing() for more information on how to store all your configurations in non-volitale memory.
Example
// This program executes menu labels and demonstrates the adding of menu options to the OS
#include <stdio.h>
#include "lib.h"

unsigned char buzzer_enabled;

// Customized default
void Custom_Default(void)
{
    SystemSetting("U2");            // Inherit OS menu option "U2"
    SystemSetting("A0");            // Enable all decoders
    buzzer_enabled = TRUE;
    SystemSetting("YC");            // Enable menu labels
}

//
// The following table implements SystemSetting options that need to be added to the OS or overruled
//
// Note: The use of 'SystemSetting()' inside the functions in the table below is limited to protect against recursion.
//       It is still possible to use SystemSetting() but only with 1 menu option per function call.
//
const OPTION menu_option_table[] =
{                                                // CLEAR mask                              SET mask (use 0xFF 0xFF in case of a function call)
    { "U2",(void*)Custom_Default,                   0xFF,                                   0xFF                        },
    { "W0",(void*)&(buzzer_enabled),                0x01,                                   0x00                        },
    { "W8",(void*)&(buzzer_enabled),                0x00,                                   0x01                        },
};

#define MAX_OPTIONS sizeof(menu_option_table)/sizeof(OPTION)


void main( void )
{
    char bcr_buf[42] = {0};
    struct barcode code  = {0};
    int result;

    //
    // The following function implements systemsettings / menu options that aren't present in the OS or need to be overruled
    //
    AddMenuOptionTable(menu_option_table, MAX_OPTIONS);

    SystemSetting("U2");        // Reset to customized default

    code.min   = 1;
    code.max   = 41;
    code.text  = bcr_buf;

    ScannerPower(TRIGGER | SINGLE, 250);    // Trigger mode, 5 seconds read time, scanner off after 1 barcode

    for(;;)
    {
        if(ReadBarcode(&code) == OK)
        {
            result = 0;

            if(code.id == MENU_CODE)
            {
                ScannerPower(ON, -1);        // Scanner on indefinitely

                while(result != EXITING_MENU_MODE && result != ERROR)
                {
                    if(result == 0 || ReadBarcode(&code) == OK)
                    {
                       switch( (result=ExecuteMenuLabel(&code)) )
                       {
                           case ENTERING_MENU_MODE:
                               Sound(TSTANDARD, VHIGH, SHIGH, SMEDIUM, SHIGH, 0);
                               break;

                           case EXITING_MENU_MODE:
                               ScannerPower(OFF, 0);
                               Sound(TSTANDARD,VHIGH, SHIGH, SMEDIUM, SHIGH, 0);

                               while(TriggerPressed())               // Wait for release before resetting read mode
                                   Idle();

                               ScannerPower(TRIGGER | SINGLE, 250);  // Reset read mode, because it's turned off after reading menu labels
                               break;

                           case INVALID_OPTION_READ:
                               Sound(TLONG, VHIGH, SLOW, 0);
                               break;

                           case VALID_OPTION_READ:
                               Sound(TSTANDARD, VHIGH, SHIGH, SMEDIUM, SHIGH,0);
                               break;

                           case LABEL_IGNORED:
                               break;

                           case ERROR:
                               ScannerPower(OFF, 0);

                               while(TriggerPressed())               // Wait for release before resetting read mode
                                   Idle();

                               ScannerPower(TRIGGER | SINGLE, 250);  // Reset read mode, because it's turned off after reading menu labels
                               break;
                        }
                    }
                }
            }
            else
            {
                if(buzzer_enabled)        // Read menu option "W0" and "W8" to enable/disabled the buzzer
                    Sound(TSTANDARD, VHIGH, SMEDIUM, SHIGH, 0);

                GoodReadLed(GREEN, 10);
            }
        }

        Idle();        // Reduces power consumption
    }
}