Page 1 of 1

Unable to set data to send back to the UI

Posted: Thu Sep 28, 2017 12:47 am
by RoboBill
I'm using VS2015 and because of my sketch size, I've split the single ino file into 6.

I'm trying to set the background color of a button based on an arduino variable.

I can declare the following:

InterfacePanel Panel; // The VS editor accepts this enty

But


Panel.set blah blah blah //The VS editor only accepts this before Setup(). Anywhere else i.e. loop() and beyond, it will give me an error during compiling.


What am I doing wrong?

Thanks

RoboBill

Re: Unable to set data to send back to the UI

Posted: Fri Sep 29, 2017 6:28 am
by philr
Hi Bill, could you please share more detail about the error and if possible example code?

Cheers
Phil

Re: Unable to set data to send back to the UI

Posted: Sat Sep 30, 2017 11:43 pm
by RoboBill
After declaring the InterfacePanel Control_Panel

I can use Control_Panel again in the Setup as noted here
SetupCodeError.jpg
SetupCodeError.jpg (242.63 KiB) Viewed 13251 times

But VS will not allow me to put Control_Panel in the loop as shown here:
LoopCodeError.jpg
LoopCodeError.jpg (100.62 KiB) Viewed 13251 times


Thanks

RoboBill

Re: Unable to set data to send back to the UI

Posted: Sun Oct 01, 2017 5:09 am
by philr
Hi Bill, could you please send me a copy of the code to

support@megunolink.com? I'll check it out and see if I can get it working here.

What build tool are you using? Visual Micro or the MegunoLink one?

Cheers
Phil

Re: Unable to set data to send back to the UI

Posted: Sun Oct 01, 2017 1:56 pm
by RoboBill
Since I'm not a programmer, I don't know what build tool I'm using. I'm also not comfortable sending out my code. Since its well over a thousand lines, I'll step aside and work with a simple sketch then work it into the main code.

I'll keep you in the loop.

Thanks

RoboBill

Re: Unable to set data to send back to the UI

Posted: Sun Oct 01, 2017 10:11 pm
by RoboBill
To begin, I am using VisualMicro Pro with VS 2015.

My first step to better understand this problem was to run the MLP example: Data Receiver Demo by itself... No problem there.

Next I put the following lines from the MLP example into a single file version of my current code.

// Progress value
int Progress;

// The interface panel we are sending data to
InterfacePanel Panel;


and

Panel.SetProgress("Progress", Progress);
Panel.SetNumber("Current", Progress);


NO Problem

Lastly I put the same MLP lines in the multi-file (and current) version of my code and BURP... NO GOOD

It appears your "talk back to UI" stuff doesn't like multi file versions of Arduino codes


Thanks,

RoboBill

Re: Unable to set data to send back to the UI

Posted: Mon Oct 02, 2017 5:01 am
by Paul
Hi RoboBill,

Great idea to start breaking your program up into smaller chunks. 1,000 lines is quite a bit for a single file. And breaking your problem down to the simplest example is a good idea too.

Without the actual source it is a little hard to be sure what the problem is but my best guess is you're not sharing the global variables across multiple code files.

The solution is to put the common variables declarations into a shared file that gets included into each program file (shared.h here) and the implementation into a source file (Shared.cpp here). Use #include "Shared.h" to get access to the globals for each source file (.cpp or .ino) that needs them.

Shared.h
-----------

Code: Select all

// The Panel object is declared external so that all who include this file know about it. 
// This doesn't actually make an InterfacePanel it just lets everyone know what Panel is. 
extern InterfacePanel Panel;

// This is the declaration for a function that we want to make available to multiple files. 
void MyFunction(int p);
Shared.cpp
-------------

Code: Select all

// This is the actual instance of the object. It sets aside the memory and other things for the panel. 
InterfacePanel Panel;

// Here's the definition of the function. Notice it is using Panel
void MyFunction(int p)
{
  Panel.SetProgress("Progress", p);
  Panel.SetNumber("Current", p);
}
MainProgram.ino
--------------------

Code: Select all

#include "Shared.h" // so we know what Panel is. 

void loop()
{
  // The panel can be used here because there is a declaration for it in Shared.h (which got included above)
  Panel.SetProgress("Progress", Progress);
  Panel.SetNumber("Current", Progress);

  // Also, we can use the function we declared in Shared.h
  MyFunction(Progress);

  //etc. 
}
Its possible I didn't quite understand your question. If that doesn't make any sense, please zip up the simple sketch example and send it through.

Have a great day,
Paul.

Re: Unable to set data to send back to the UI

Posted: Mon Oct 02, 2017 8:57 am
by RoboBill
Hi Paul,

Thanks for the explanation. When I split the large program file into multiple files, I kept the global variable declarations, the setup() and loop() in the "main" file. All called functions were grouped in numerous multiple files. I didn't add any "#include other files "stuff in the main file. It compiles and runs your megunolink.h & SerialCommandHandler.Process(); stuff just fine. I can put SerialCommandHandler.Process(); anywhere in any of the files.

But when I add "int Progress;" & "InterfacePanel Panel;" to the global area of the main file of a multi file program, I'm unable to put "Panel.blah blah" in the loop() section which is still located in the main file.

My question is; while using VS 2015, have you guys been able to send data back to the UI with a multi file program? If so then its somehow me.... which would not be too surprising.

Thanks again

RoboBill

Re: Unable to set data to send back to the UI

Posted: Wed Oct 04, 2017 11:16 pm
by RoboBill
OK as usual, I think I found the error. I needed to put the "Interfacepanel" in the global area. Now VS accepts the Panel.set blah blah

Thanks for your patients

RoboBill