Start a new topic

PopCallback functions doing nothing - arduino

Hello everyone, I come to you for enlightenment I' m making a gauge cluster for my motorcycle . Finally got examples working had a lot of problems with them, starting by not compiling ending by being shocked by an ungrounded usb port .

The problem is that my PopCallback functions do nothing. Everything I did is based on examples , but I am probably mentally burned out and blind.

Here's the code with out all the moto code and it doesn't work even when all moto stuff is deleted.I had a hard time making any type of communication going. I already know how to make everything work with out the functions ,but hope you can make my life easier . Thank you!

#include <Nextion.h>

NexButton InjConf = NexButton(3, 3, "InjConf");
NexButton SaveFL = NexButton(2, 20, "SaveFL");
NexVariable Tepal_Supil = NexVariable(2, 9, "Fuel_Screen.Tepal_Supil");

NexTouch *nex_listen_list[] = 
{
    &Tepal_Supil,
    &InjConf,
    &SaveFL,
    NULL
};

void SaveFLPopCallback(void *ptr)
{
  dbSerialPrintln("SaveFL");
}

void InjConfPopCallback(void *ptr)
{
  dbSerialPrintln("InjConf");
}

void setup(void) 
{
  nexInit();
  SaveFL.attachPop(SaveFLPopCallback);
  InjConf.attachPop(InjConfPopCallback);
  dbSerialPrintln("setup done"); 
}

void loop(void) 
{
  nexLoop(nex_listen_list);
}

 Regards from Lithuania


Solved

For beginners - make sure that you send the object id on popup if you want your popup function to work!

send the object id on popup???  What popup?


see Nextion Instruction Set - Return Codes.

see IteadLib Nextion Arduino Library source code files


attachPush function is designed to catch component Touch Press Event

- when the Component Touch Press Event in Editor has Send Component ID checked. 

- IF checked, the Nextion sends 0x65 0x03 0x02 0x01 0xFF 0xFF 0xFF across the RX/TX lines.

(where 0x03 is the page number, 0x02 is the component .id, and 0x01 is Pressed)


attachPop function is designed to catch component Touch Released Event

- when the Component Touch Release Event in Editor has Send Component ID checked.

- IF checked, the Nextion sends 0x65 0x03 0x02 0x00 0xFF 0xFF 0xFF across the RX/TX lines.

(where 0x03 is the page number, 0x02 is the component .id, and 0x00 is Released)


For these to work the component in Arduino side code has to be defined, as in

   NexButton InjConf = NexButton(3, 3, "InjConf");  // page 3, component .id 3

- its Pressed Event is an .attachPush  - 0x65 0x03 0x03 0x01 0xFF 0xFF 0xFF

- its Released Event is an .attachPop  - 0x65 0x03 0x03 0x00 0xFF 0xFF 0xFF


The InjConf is the .objname of the Component in Nextion Editor HMI as designed.

This has to be in the NexTouch nex_listen_list to be caught.


BUT IN ORDER FOR IT TO WORK ...


   InjConf.attachPop(InjConfPopCallback);

   InjConf.attachPush(InjConfPushCallback);


this is the form .objname .attachPush/attachPop(user_function_when_caught)

and the user must then write the actual function the described inside the () parenthesis

- the code inside this user written function is run when the 0x65 return code matches.

This is what actually makes it work!


/* All included in the source for the library when it was downloaded and installed

   Library code is as much part of your programming sketch as your loop           */


Yes, thank you,

This was what i was trying to say. 

When I made the HMI file I was sending the component id on the touch press event , but i was trying to use the function for the realese event.

Sorry for wasting your time.

Login or Signup to post a comment