stepan-mitkin / drakon_editor

DRAKON Editor
349 stars 57 forks source link

Using Drakon for Arduino #20

Open sanyaade-iot opened 7 years ago

sanyaade-iot commented 7 years ago

Hello All,

Good day to you all.

I started learning Drakon to use it in my teaching class with kids working/coding with Arduino.

I have not found on how to re-arrange the order of how the code will be be generated. for example

image

in the above I want the Setup() to be above and to be genrated first before the Loop(). I could not move the Setup() diagram above the Loop() diagram in order to have it code generated first. The students will like to have the facility in their work. Many thanks!

God blesses!!!

Best regards, Sanyaade

vasili111 commented 7 years ago

As far as I know it is not possible to arrange DRAKON diagram code generation order. But it is possible to add any text (code) before generated code and after generated code. To do that, go to File / File description... To add some code at the beginning (header) of generated file add this code to File description:

===header===
Some code here

To add code at the end (footer) of generated file add this code to File description:

===footer===
Some code here
sanyaade-iot commented 7 years ago

@vasili111

Many thanks for your quick reply. I am not talking about code but about the call hierarchy. if you look on the screenshot below: image

Setup diagram was created by a student before the Loop diagram was done. But Drakon re-arranged the them alphabetically in ascending order (L before S) which means the code for Loop was generated before that of Setup.

For use in Arduino environment there wont be a need for forward declaration since Arduino.h will be include in using "===c_header=== directives. What I want is that to remove re-order of the call hierarchy so that it Drakon can be use with existing Arduino library and a backend compiler for Arduino.

Many thanks!

God blesses!!!

Best regards, Sanyaade

ACJA commented 7 years ago

I am not sure what the problem is, but you can rename Loop and Setup to 0002-Loop and 0001-Setup and now you get some order in the left-side list as you want. If you must keep the name Loop and Setup, you can create the directory 0001 and cut/paste Setup diagram there, and directory 0002 for the Loop diagram (without changing the names Loop or Setup). The folder names (0001 and 0002) are meaningless in the final output and nowhere to be seen. image On the other hand, if you're talking about something like template code that must be "instantiated" (and not "forward" declared), then it is another story altogether. The templates are compiled twice: Without instantiation, the template code itself is checked for correct syntax, such as missing semicolon At the time of instantiation, the template code is checked to ensure that all calls are valid, such as unsupported function calls This leads to a problem in handling of templates in practice. When a function template is used in a way that triggers its instantiation, a compiler will (at some point) need to see that template definition. This breaks the usual compile and link distinctions for ordinary functions, when the declaration of a function is sufficient to compile its use. There are methods of handling this problem. Attached is a set of DRAKON projects following SAMS teach yourself book (version 5) for passing items to template. See attached example (19.05-Pass_template_items chapter from SAMS), check how the code was inserted in the DRAKON description section of CTB_Array (class template base) and not as a diagram. The abnormal template source code implemented in the header file will piggy-back everywhere the header file is included. 19.05-Pass_template_items.tar.gz

sanyaade-iot commented 7 years ago

@ACJA , Everybody,

Many thanks for your reply!

I have got past the ordering of the diagram hierarchy on the left pane.

What I need help for is: TCL code (in the generator) to comment out a line of text. For example I will like to comment out void Setup() in the .h (generated header file).

I am getting compile error function already declared. This is due to the fact that Arduino.h already declared Setup(). I only need it in source file --> .cpp and not in .h file. Currently now I have to manually commented that line out but for my students who 14 -16year age, not a programmer are finding it difficult to debug.

Many thanks for your continuous help!

God blesses!!!

Best regards, Sanyaade

ACJA commented 7 years ago

Assuming you're using Linux you can use a BASH script to make all kind of corrections in the output files. I could help you with this but you have to provide a full project with explanation for changes needed in the output files. If you're using Windows you're on your own, try power shell.

sanyaade-iot commented 7 years ago

@ACJA , Everybody,

Many thanks for your reply. What I need is tcl script that can automatically open a file, look for a particular function inside the file and commented out that particular function. See below my comment below and in the attached Drakon example zip file.

/ Autogenerated with DRAKON Editor 1.27 /

ifndef ARDUINO_TEST3_H46878

define ARDUINO_TEST3_H46878

// I do not need or want these two particular functions declared in the header file // as they conflict with those in the library being used

void loop(); void setup();

// I need Drakon comment out the above specific two lines to the one shown below. A Drakon tcl script to do the below commenting will be great! Many thanks!

// void loop(); // void setup();

[#endif]

sample.zip