-
-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Example with len superior of 02 #15
Comments
Hello, From what I can understand, you are using the custom commands, with one new command group "L". You are receiving only one, because with In your example, you will to write one more time Also, Whatever you need, do not hesitate to write :) |
Ok, I get it. for example, you can capture the content, store it in a class variable and call the function, then in user custom commands, anyone can call that variable to get the value more easy EDIT: Or maybe more efficient, declare a weak function for custom commands, and if command isn't "P" or "T", it calls the weak function with two parameters, the command letter, and the content based on the . That way, the user don't need to change the library files, staying it intact Didn't tested, but here's the idea extern void readCustomCommand();
extern void readCustomCommand() __attribute__((weak));
void EasyNex::readCommand(){
switch(_cmd1){
case 'P':
/* code here for P */
break;
case 'T':
/* code here for T */
break;
}
/* _data computed and stored in class variable before reaching here */
readCustomCommand(_cmd1, _data, _len);
} |
I understand your point . The readCustomCommands has a different meaning and it is used for a custom protocol feature. You can read about it at this link: I also have in mind to make the custom protocol as a weak function but as it is a very special feature and only advanced on programing users can use it, it is not necessary for them, as they can easily modify the .cpp file of the library. It will be good to avoid modifying on library's file, as an update of library can erase the custom code. examples for trigger function
If you want to capture a value or to turn ON/OFF a relay you don't have to complicate it with a custom protocol as you simply use the trigger function. I hope that I have answered your questions. |
In the last days, I spent reading your docs, some of them more than once to fully understand how this library works. |
Ok, for the moment and until I make the changes, you can write the code for case letter and you can call it from readCustomCommands.cpp with only one line void EasyNex::readCommand(){
switch(_cmd1){
case 'L':
letterLCase();
break;
case 'P':
/* code here for P */
break;
case 'T':
/* code here for T */
break;
}
} Also an array like this always helps to handle many cases const uint8_t TOTAL_RELAY = 6 // How many warning relays we use
const uint8_t relayPin[TOTAL_RELAY] = {2, 3, 4, 5, 6, 7}; // assigns the pin number for every relay
/*
* Declare that pin D2 is the pin that controls the Relay No0 (front lights)
* Declare that pin D3 is the pin that controls the Relay No1 (Backyard lights)
* Declare that pin D4 is the pin that controls the Relay No2 (swimming pool lights)
* Declare that pin D5 is the pin that controls the Relay No3 (roofgarden lights)
* Declare that pin D6 is the pin that controls the Relay No4 (adviser lights)
* Declare that pin D7 is the pin that controls the Relay No5 (extra auxiliary lights)
*/ |
I did some changes in your code, and it seems to work as expected, I didn't coded the data variable but the rest is working. At the end of the extern void easyNexReadCustomCommand(uint8_t _cmd1, uint8_t _len);
extern void easyNexReadCustomCommand(uint8_t _cmd1, uint8_t _len) __attribute__((weak));
void EasyNex::readCommand(){
switch(_cmd1){
case 'P':
/* code */
break;
case 'T':
/* code */
break;
default:
easyNexReadCustomCommand(_cmd1, _len);
} In my void easyNexReadCustomCommand(uint8_t cmd1, uint8_t len) {
Serial.println(cmd1, HEX); //This is reporting the letter as expected -> 4C
Serial.println(len); // Reporting the correct length -> 03
} The only thing left is the content being captured and passed into the function. |
let me see it more carefully |
if you can point me the direction to catch the data, I can try to make a pull request if you want |
This is the way I'm using. This example mentioned earlier |
Ok,
so the code inside the |
No problem with the point to the direction |
If user wants to implement Group Commands/Letters, he has to declare the function himself. If don't, just ignore and don't declare. |
Will you intend to implement the data being parsed into the function? |
So from users code file you can use the switch function again |
This is an example of my idea void easyNexReadCustomCommand(uint8_t cmd1, uint8_t len, char data) {
switch(cmd1){
case 'L':
lights[(int)data[0]].setState((int)data[1]);
break;
case 'S':
shutters[(int)data[0].setLevel((int)data[1])];
break;
}
} Something like this, if it makes sense |
Where Serial the Serial you are using for Nextion void easyNexReadCustomCommand(uint8_t cmd1) {
int cmd1 = cmd1;
switch(cmd1){
case 'L':
data[Serial.read()] = Serial.read(); //EDITED
// read the fist byte and use it to point the place of the data array
// read the secont byte and set the data["first byte we read"] place equal with the value of the second byte
break;
}
} |
Is that working? |
we must avoid to parsed the data into the function as this will be for general use and we don't know the needs of each user as someone may need to specify more than two ids |
For my case, it seems more useful to do like this: About your example, it seems more useful to expose Anyways, I think it's useful to pass either the |
data can be parsed and not used, atleast the user has the ability to use that more easily. |
No it is not by mistake it better to save the parsed data in a variable before you use them ( maybe uint_8 is better)
First we must keep the functions for general use, I cannot think a way to read the data for the library as those data can vary for user to user. So the way is to read the next bytes from the
I don't understand this command
This comes second at this time as a new function for serial read can de added (
The most easy and reliable and keep the general purpose of the library is to read and assign the data from the user code |
Yes but how many data we must read? Isn't more creative to let the used do that upon its needs? We must keep it as simply as we can, a full documentation of two or more pages is not simply use. |
This is just an example of my code, isn't about your library. In my case I have an array of Light Objects, the first byte is the ID of the array, and the second byte is the state to change. So, the code posted is an example to catch those two bytes and put into action. Just for sharing, so you can understand better I'll make some examples Example 1
easyNexReadCustomCommand(cmd1 /*'L'*/, data /*[01, 01]*/); Example 2
easyNexReadCustomCommand(cmd1 /*'P'*/, data /*[03]*/); Example 3
easyNexReadCustomCommand(cmd1 /*'K'*/, data /*[03, 04, 00, 01]*/); PS: The above code is just for understanding what's underneath the variable names when calling the function I hope this makes sense. |
You are right I don't want to add extra code to catch all the entire data as it is dynamic and it is going to be very compilated. I am going to add
Is that OK? |
Yes, seems ok that way.
|
Yes, and you could call it from the main code |
Ok, nice. |
Ah, one thing I noticed, maybe could be useful to trigger the function for use caseWhen page changes, arduino sends the requires data into the nextion so can update the components |
I think that we are OK now. |
The files is attached, forgot to mention it. |
I made some tests, and everything seems to work good 👍 |
Ok I am going to do some test with the other examples to check the compatibility and I will start writing comments and documentation and I will begin to make the new release. Thank you for your help :) |
Can you please create a new branch and publish the code to there? That way is much easier to start fully working and testing |
I find this way more complicating, for me at least. I prefer the new releases and also I have done some work already and I have made other changes in the code, to other functions . Just give me some time to finish it. |
I noticed you added new files, can I test with those or is incomplete? |
A new release was just published. If we do not need this issue, close it whenever you want :) |
So far, everything is working as expected. |
I cannot find any example with second parameter (len) superior of 02
I tried to do this to catch the next 3 bytes:
Nextion button:
C++ code:
the above code reports 01 only, and not the entire combination like "01 01"
Is there anything to combine both in single variable?
Or how do you do in your cases?
EDIT: when first posted I said it reports twice but I was wrong. It is reporting only once
The text was updated successfully, but these errors were encountered: