Start a new topic

Send dual-state button values as a string

As my GUI design is constantly changing, receiving a component ID when press event happens isn't very useful, as the component ID are changing.


I wanted to see a string that shows the new value of a dual state button after a press event on the serial line that looks likes a command, so I used the following code in the user code of the touch press event of my button:


cov bt0.val,bval.txt,0
printh 70
print "bt0.val="
print bval.txt
printh ff ff ff

 The result is the following:


 

0x70 0x62 0x74 0x30 0x2e 0x76 0x61 0x6c 0x3d 0x31 0xff 0xff 0xff

The first character, in accordance with the Nextion Instruction set, marks the start of string variable data, followed by the string "bt0.val=1" then the three terminating characters.


Unfortunately, there's no means for me to access the objname, so I have to identify it manually in my code, but I could modify the format if I wanted to simply send "bt0=1" or send a more traditional newline character instead of the three 0xff, but I'm trying to adhere to the communications protocol used by the Nextion.


For Itead, it would be nice, in the user code, if I could simply access the object name and refer to the object I'm coding for as "me". My code would then look like the following:

 

cov me.val,bval.txt,0 
printh 70 
print me.objname 
print ".val="
print bval.txt
printh ff ff ff

 The most efficient would be to have the option of a get command with the option of a string response:


get bt0.val,1

In the example above, the second parameter specifies the response format (0 is numeric, 1 is string) The string option would return it in the following format:


bt0.val=1



2 people like this idea

Notice that the examples in the Nextion documentation have spaces between the arguments:
cov t0.txt, j0.val, 0

 THIS WILL NOT COMPILE!!!  :-/
Take out the spaces after the two commas and it will.



 

@Vectorspace You are correct.  But it is a Chinese company, which everyone knows has horrible communication skills (and often no quality control), so what do you expect?  However, your comment doesn't apply to this thread.

 

I was searching for hints on why the official example for "cov" in the docs wouldn't compile for me. I came across this thread as a result of that search. In Paul Dufresne's original post in this thread he writes, "cov bt0.val,bval.txt,0" and indicates that it compiled for him. Thus, by reading this thread, I found out what was wrong with the official example and my problem was solved. Perhaps someone else will benefit as well.

 

Login or Signup to post a comment