/var/www/restricted/ssh/stm32/www/stm32circle/ STM CircleOS forum / MENU_Question() Problem

Username:     
Password:     
             

Forum

# 1   2014-03-04 15:54:43 MENU_Question() Problem

hollaender
New member
Registered: 2014-01-25
Posts: 8

MENU_Question() Problem

Hi all,
I have this code fragment:
...
bool HasToQuit = FALSE;
MENU_Question("Quit?",&HasToQuit);           
if(HasToQuit == TRUE)
                {               
                // I am always landing here, even if the answer is NO
                }                 
...
Moreover, the compiler reports:

warning: passing argument 2 of '(u32 (*)(u32,  u32))(*ptrCircle_API)[162]' makes integer from pointer without a cast 
expected 'u32' but argument is of type 'enum bool *' 

I looked into circle.h, the forward declaration is
void  MENU_Question( const u8* str, bool* answer );

What is the correct way of using the MENU_Question function? I am using OS V4.61 on a STM324x Primer.
Thanks for any help.
Igor

Offline

 

# 2   2014-03-05 08:04:21 MENU_Question() Problem

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: MENU_Question() Problem

The function is defined in circle_api.h for the application (CircleOS API), and circle.h for CircleOS internal uses.
I supposed you implement it into an application.

The API functions with 2 parameters are defined by the generic prototype, in circle_api.h :
typedef u32( *tCircleFunc2 )( u32 param1, u32 param2 );

It seems there is a little mistake in circle_api.h, int the MENU_QUESTION definition
#define MENU_Question(a,b)                            ((tCircleFunc2)(Circle_API [MENU_QUESTION_ID])) ((u32)(a),(bool*)(b))     /* void MENU_Question( u8* str, bool* answer ); */

If you want to suppress the warning, change the line before, by :
#define MENU_Question(a,b)                            ((tCircleFunc2)(Circle_API [MENU_QUESTION_ID])) ((u32)(a),(u32)(b))     /* void MENU_Question( u8* str, bool* answer ); */


Just another remark, the MENU_Question just set the corresponding menu, so the function does not block until the response, it immediately gives the hand back. The variable HasToQuit will only change after the user action.

Offline

 

# 3   2014-03-07 09:30:26 MENU_Question() Problem

hollaender
New member
Registered: 2014-01-25
Posts: 8

Re: MENU_Question() Problem

Thanks. I have corrected the declaration in circle_api.h, that's fine. I also see now that the MENU_Question() is a non-blocking function. So I deployed it like this:

..
static bool HasToQuit =FALSE;
..

enum MENU_code Application_Handler(void)
{
...
if (HasToQuit==TRUE)
{
...//finalize
}
...
}

}

...
// somewhere inside a handler serving (e.g.) a button touch
MENU_Question("Quit STiM32?",&HasToQuit);                       
...

The problem is, even in this case, it seems like HasToQuit will always be assigned TRUE even if the user ends the Question menu with a 'NO' answer.

Offline

 

# 4   2014-03-10 09:27:59 MENU_Question() Problem

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: MENU_Question() Problem

In fact, the HasToQuit variable changes, but the MENU_Question does not gives the hand back to your application, but to the OS. So you think that HasToQuit is true, but check with a watch.
I think that MENU_Question is not appropriate (it is used for CircleOS internal use, like configuration menu).

You should implement your own menu like this:

static bool HasToQuit =FALSE;
bool fRedraw = TRUE;

enum MENU_code SetYes( void )
{
    HasToQuit = TRUE;
    fRedraw = TRUE;                  // Force to redraw application page
    return MENU_CONTINUE_COMMAND;
}

enum MENU_code SetNo( void )
{
    HasToQuit = FALSE;
    fRedraw = TRUE;                  // Force to redraw application page
    return MENU_CONTINUE_COMMAND;
}


tMenu MyMenu =
{
    1,
    " Quit StiM32 ",
    2, 0, 0, 0, 0, 0,
    0,
    {
        { "Yes", SetYes, Application_Handler, 0 },
        { "No",  SetNo,  Application_Handler, 0 },
    }
};

enum MENU_code Application_Handler(void)
    {
    // This routine will get called repeatedly by CircleOS, until we
    // return MENU_LEAVE
       
    if (fRedraw )
    {
        fRedraw = FALSE;
        BUTTON_SetMode( BUTTON_ONOFF ) ;
        LCD_FillRect( 0, 0, 240, 240, RGB_WHITE );
    }

    // Check for operator menu request
    if ( BUTTON_GetState() == BUTTON_PUSHED )
    {
        BUTTON_WaitForRelease();
        MENU_Set( ( tMenu* ) &MyMenu );
        return MENU_CHANGE;
    }

    if (HasToQuit)
         return MENU_Quit();
}

Offline

 

# 5   2014-03-21 09:53:18 MENU_Question() Problem

hollaender
New member
Registered: 2014-01-25
Posts: 8

Re: MENU_Question() Problem

Dear yrt, thanks. For a longer time, I was still not able to get this working, but now I found the reason why.

My symptoms were the following: whatever I did, the visual behaviour of the menus was fine but the callback function actually called was always the FIRST one in the list. Then I realized what my problem was.

I always declared the tMenu structure as 'const', as I though this is the correct way to do things (the tMenu struct should no change, should it?). But I was wrong:


const tMenu MyMenu =  // THIS IS WRONG
//if you do this, you will always end up calling Item1Handler
{
    1,
    " Menu title",
    2, 0, 0, 0, 0, 0,
    0,
    {
        { "Item1 ", Item1Handler, Application_Handler, 0 },
        { "Item2",  Item2Handler,  Application_Handler, 0 },
    }
};

tMenu MyMenu =  // THIS IS CORRECT (no 'const' modifier)
{
   ...
};

Maybe just my ignorance is C.
Hope it helps others too.

Offline

 

# 6   2014-03-21 10:25:21 MENU_Question() Problem

yrt
Administrator
From: Grenoble-France
Registered: 2008-06-11
Posts: 520
Website

Re: MENU_Question() Problem

Some parameters in the menu are not constants because internally used by CircleOS : x and y position, selected items.... It concerns 0 values in the menu declaration. (see the tMenu declaration)

Offline

 

Board footer