I'd like to use a Class to Transprot Data between ans ESP 8266 and nd Arduino Mega). The Transfer works as intended, but i wrote a Method to clear all Values of the Class instance, but it seems to have no effect. The Code for the Class is the following:
I never worte a lot of Code in C and thus am not experienced with this language. Do i need to use pointers here. If so, how would I use them.
Help would be greatly appreciated.
KInd regards!
Thanks for the Answer, the full Code is too long to post here, but i can give you the relevant Code Snippets.
Init of variable
TransferData recv_data;
Code which runs from void loop() on the Mega and receives the Values send over Serial from the ESP. If ii send the Class with processByte as 1 and Mode as 1 the first Time it shows exactly that output. If i then send proces Byte 2 and Brightness 5, it shows these as well, but also says that mode is still 1, which means that the clear() function does not work the way i intend
I have attached the Full Code as Files in the Post, but i think its very difficult to read all of it because i didnt comment on it a lot. If needed I can attach all Cpp and Header Files, but i think that goes a bit too far.
If not tell me and ill post it.
IronInt:
Ok so, I cant actually post the FULL Code in here except for in a file/ a directory, because of size limitations.
As already requested in Reply #3, create and post an MRE. This is the smallest, complete code that demonstrates the problem you're seeing and only that problem. Leave out all code that is unrelated to the problem as it's simply clutter.
Using the following Code snippet my Code seems to work as intended, so i probably need to investigate how Serialtransfer stores Data inside my TransferData Object
septillion:
PS Don't be surprised to find the bug yourself while making a MCVE
But from what I can see of the code: for C there is NO defined "clear" state. A variable exists (and thus has a value) or it does not. You can threat a specific value as clear but that's up to you. For example, you could see 0 as cleared. Or call it 'NULL'. But 'NULL' is nothing special, it just sets the value (to 0 actually). It just indicates in code that a value of 'NULL' should be treated as "no valid data". But the actually doing so is fully up to you. Also, because 'NULL' is just defined as 0, actual valid data can never be 0 then, because you can't see any difference. So you need to make the data field wide enough to accept all possible data values + a "not valid" marker. Or, have a separate (bool) which you set (on writing valid data) or reset (on a clear) to indicate valid data or not.