Close

Nexion display: Understanding the Nexion code

A project log for Building the Thor robot

Building a 6-axis robot based on the Thor robot. When size DOES matter!

olaf-baeyensOlaf Baeyens 08/29/2017 at 21:072 Comments

Mystery why the Nexion Arduino code only reacted on a button release is this:

The button press is triggered by this attach-Push command.

    MotorEnable_Z.attachPush(MotorEnable_Callback, &MotorEnable_Z);

The button release  is triggered by this attach-Pop command.

     MotorEnable_Z.attachPop(MotorEnable_Callback, &MotorEnable_Z);

I took some example code from Nexion and apparently used the Pop (=release button) only

I mistakenly confused it with a LIFO buffer.  Push-Pop


Analyzing the Nexion protocol I also discover that it is not wise to use big names as buttons at the HMI implementation. When you request data from the HMI then it sends a big command to the Nexion slowing down the serial communication.


The Nexion Arduino implementation is actually very good code if you look at the sources, but I am probably going to start from scratch and squeeze out every bit of performance now that I understand the code.

The current implementation is a way to attach multiple callback events to a list. But one of my screens the number of buttons will be huge. I have a hunch that the MHI can support about 255 buttons per page. 

void NexTouch::iterate(NexTouch **list, uint8_t pid, uint8_t cid, int32_t event)
{
    NexTouch *e = NULL;
    uint16_t i = 0;
    if (NULL == list)
    {
        return;
    }
    
    for(i = 0; (e = list[i]) != NULL; i++)
    {
        if (e->getObjPid() == pid && e->getObjCid() == cid)
        {
            e->printObjInfo();
            if (NEX_EVENT_PUSH == event)
            {
                e->push();
            }
            else if (NEX_EVENT_POP == event)
            {
                e->pop();
            }
            
            break;
        }
    }
}

 Why would I need 255 buttons? Well imagine that you create touch zones ;-)


So how would I optimize such a thing? 

I want one button on one page = only one callback for both button down and button up. This way I can flash jump to that callback instantly without a loop. The HMI sends very compact codes to the Arduino controller.

It is sad that a day does not have 72 hours, I really need more free time :-)

Discussions

Olaf Baeyens wrote 08/30/2017 at 16:58 point

Not everything is correct on my posts, it is a learning curve.

  Are you sure? yes | no

Sepio wrote 08/30/2017 at 11:52 point

Nice work. A few days I looked at the Nextion forum. Many people are complaining about the bad or outdated help.  In a couple of weeks I'am also going to use the Nextion Editor and you posts will be a good source of information.

  Are you sure? yes | no