Start a new topic

How to capture the wake-up event from Arduno

I want my project to go to sleep, after inactivity.  So I send:


thup=1 (followed by 3 0xFF)

sleep=1 (followed by 3 0xFF)


Works good.  Ok so now I want to capture the WAKE event, to reset the sleep timer on Arduino.  I see classes for buttons, pages, image buttons, etc.. all the rest of the controls.  I am lost when it comes to receiving the wake-command.  Can please get some help?


 Hi Erich,


after a sleep=1, the Nextion still stays active and responds to a touch ... means, when you touch the panel, no matter thup is 0 or 1, if any touch operation in sleep mode happens, the device will send touch coordinates to the serial port.


And that's what you must catch with your Arduino code ...

Via a polling loop, via uart interrupt, ... there are many different possibilities how to do ...


Gerry

In the NexHardware.cpp file of the Nextion library,

- this functionality would need to be added to the NexLoop procedure.


As we can see the library is currently

- capturing the Nextion Touch Pressed and Released Events 0x65 Return Code Data


You probably want to capture the 0x86 and 0x87 Nextion Return Codes


As per the Nextion Instruction Set: Format_of_Device_Return_Data

0X86 Device automatically enters into sleep mode 0X86+End

: Only when the device automatically enters into sleep mode will return this data. If execute serial command “sleep = 1” to enter into sleep mode, it will not return this data.

0X87 Device automatically wake up 0X87+End

: Only when the device automatically wake up will return this data. If execute serial command “sleep=0” to wake up, it will not return this data.


So first these defines would need to be added at the top

#define NEX_RET_EVENT_AUTOSLEEP     (0x86)

#define NEX_RET_EVENT_AUTOWAKE      (0x87)


Then in the NexLoop the code for this needs to be entered into the while loop.

It would resemble something like

 

 

 

        if (NEX_RET_EVENT_AUTOSLEEP  == c)
        {
            if (nexSerial.available() >= 3)
            {
                __buffer[0] = c;  
                for (i = 1; i < 4; i++)
                {
                    __buffer[i] = nexSerial.read();
                }
                __buffer[i] = 0x00;              
                if (0xFF == __buffer[1] && 0xFF == __buffer[2] && 0xFF == __buffer[3])
                {
                    // Need to create a new function to call when falls asleep
                    // call this new onsleep function
                }
            }
        }

        if (NEX_RET_EVENT_AUTOWAKE  == c)
        {
            if (nexSerial.available() >= 3)
            {
                __buffer[0] = c;  
                for (i = 1; i < 4; i++)
                {
                    __buffer[i] = nexSerial.read();
                }
                __buffer[i] = 0x00;              
                if (0xFF == __buffer[1] && 0xFF == __buffer[2] && 0xFF == __buffer[3])
                {
                    // Need to create a new function to call when now wakes up
                    // call this new onwake function
                }
            }
        }

 

 

 


Ok, so I must modify NexHardware.cpp add the code to handle this function.  Thank you for the reply.

Login or Signup to post a comment