Go Down

Topic: Path - Own Libary / SubLibary / Header (Read 659 times) previous topic - next topic

Reiter


I have three questions about libaries and there pathes


Which libary path should i use:

I built my own libary and i cluded them in C:\Users\<usernam>\Documents\Arduino\libraries

Is that right or shall i use the other path C:\Users\<usernam>\AppData\Local\Arduino15


Which libary path should i use:

Is it possible to use includes from C:\Users\<usernam>\Documents\Arduino\libraries AND C:\Users\<usernam>\AppData\Local\Arduino15 in the sketch at the same time?

Use a sub-libary:
I create a libary with a subfile font.h.
Now, the font.h, the basiclib.cpp and the basiclib.h are in the same folder (basiclib). It's that correct or should i place the font.h in the sublib, because when i implement the libary in a sketch, the font.h is inserted with the basiclib (#include basliclib.h and #include font.h) and i don't want this.

{sketchbook folder}
|_libraries
   |_basiclib
      |_keywords.txt
      |_library.properties
      |_examples
      |_src
      |  |_basiclib.cpp
      |  |_basiclib.h
      |_sublib
         |_sub.cpp
         |_sub.h


Thank's for helping.

pert

Is that right or shall i use the other path C:\Users\<usernam>\AppData\Local\Arduino15
The first one is right. C:\Users\<usernam>\AppData\Local\Arduino15 won't work. Libraries bundled with hardware cores are installed to a subfolder of that location (e.g., C:\Users\<username>\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.2\libraries, but those libraries are only accessible when a board from that core is selected from the Arduino IDE's Tools > Board menu, and any libraries you add to that location will be lost every time you update the hardware core.

Is it possible to use includes from C:\Users\<usernam>\Documents\Arduino\libraries AND C:\Users\<usernam>\AppData\Local\Arduino15 in the sketch at the same time?
I think I explained that well enough above.

It's that correct or should i place the font.h in the sublib
Recursive compilation is only done in the src subfolder so that library structure won't even work. You can move the sublib folder inside the src folder if you like. The general idea is that the header files directly under the src folder contain the declarations for the public API, while the files in subfolders contain code that's not intended to be used by the user.

when i implement the libary in a sketch, the font.h is inserted with the basiclib (#include basliclib.h and #include font.h) and i don't want this.
I'm going to guess that by "implement", you mean Sketch > Include Library in the Arduino IDE, or the equivalent in Arduino Web Editor. You'll have better luck here if you are clear in your questions instead of being so vague. By default, Sketch > Include Library adds #include directives for all header files directly under the library's src folder. If you want to control which #include directives are added, you can do this via the includes field in library.properties. Details here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format
Quote
includes - (available from IDE 1.6.10) (optional) a comma separated list of files to be added to the sketch as #include <...> lines. This property is used with the "Include library" command in the IDE. If the includes property is missing all the headers files (.h) on the root source folder are included.

Reiter

The first one is right. C:\Users\<usernam>\AppData\Local\Arduino15 won't work. Libraries bundled with hardware cores are installed to a subfolder of that location (e.g., C:\Users\<username>\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.2\libraries, but those libraries are only accessible when a board from that core is selected from the Arduino IDE's Tools > Board menu, and any libraries you add to that location will be lost every time you update the hardware core.

I think I explained that well enough above.

Recursive compilation is only done in the src subfolder so that library structure won't even work. You can move the sublib folder inside the src folder if you like. The general idea is that the header files directly under the src folder contain the declarations for the public API, while the files in subfolders contain code that's not intended to be used by the user.
ok!! Thank's a lot.

Is there a good guide or description how to create boards, variants arduino.h's (=> everything about the hardware folder). I think many do it somehow, but you should stick to the standard library and link from it. So there are fewer problems with cross-platform libraries.


I'm going to guess that by "implement", you mean Sketch > Include Library in the Arduino IDE, or the equivalent in Arduino Web Editor. You'll have better luck here if you are clear in your questions instead of being so vague. By default, Sketch > Include Library adds #include directives for all header files directly under the library's src folder. If you want to control which #include directives are added, you can do this via the includes field in library.properties. Details here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5:-Library-specification#libraryproperties-file-format
Great, Thank's. I will try this in the afternoon.



If you link header (only arrays of characters) with a cpp-file (font.h & font.cpp) or just the header alone?

I have a preprocessor directive (# ifdef # def # endif). But when I include the header in the library and additionally in the main.cpp (sketch.ino), this will not work! Why?

pert

Is there a good guide or description how to create boards, variants arduino.h's (=> everything about the hardware folder). I think many do it somehow
There is a lot of useful information here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification
Unfortunately it isn't really a guide. Arduino has actually been considering using the technical writer supplied to us via the Google Season of Docs program to write such a guide, but there is only one technical writer allocated and a list of potential projects so it's not certain whether that will be the project chosen by the writer.

I think a lot of the hardware core authors used existing hardware cores as a model when they wrote their own. If you can find a core that is somewhat along the lines of what you want to do, then it makes things much easier. There is the ever popular Arduino AVR Boards:
https://github.com/arduino/ArduinoCore-avr
Arduino SAMD Boards:
https://github.com/arduino/ArduinoCore-samd
ESP8266:
https://github.com/esp8266/Arduino/
MightyCore:
https://github.com/MCUdude/MightyCore
ATTinyCore:
https://github.com/SpenceKonde/ATTinyCore
and so on. I actually published a list of all known Arduino hardware cores:
https://github.com/per1234/ino-hardware-package-list/blob/master/ino-hardware-package-list.tsv

The great thing is that Arduino's hardware system allows you to reference resources from other cores:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#referencing-another-core-variant-or-tool
That allows you to create custom hardware cores with only a couple files. An example is carlosefr/atmega:
https://github.com/carlosefr/atmega/tree/master/avr
Notice how the entire core is only two files because it references resources from Arduino AVR Boards!


If you link header (only arrays of characters) with a cpp-file (font.h & font.cpp) or just the header alone?
It's not clear to me what you mean by that.

I have a preprocessor directive (# ifdef # def # endif). But when I include the header in the library and additionally in the main.cpp (sketch.ino), this will not work! Why?
If you have a proper include guard, you should have no problem with multiple #include directives for a library. However, an include guard only protects against multiple inclusions in the same translation unit. It does not protect against inclusions in multiple translation units (nor would you want it to). The .ino files of your sketch are a separate translation unit from .cpp or .c files in a library or even in your sketch. For this reason, it is possible to write code in a .h file that causes a compilation error when the file is #included in multiple translation units. However, it's certainly possible to fix that issue. If you want specific help with the issue, you'll need to post your code.

Reiter

Quote
There is a lot of useful information here:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification
Unfortunately it isn't really a guide. Arduino has actually been considering using the technical writer supplied to us via the Google Season of Docs program to write such a guide, but there is only one technical writer allocated and a list of potential projects so it's not certain whether that will be the project chosen by the writer.

I think a lot of the hardware core authors used existing hardware cores as a model when they wrote their own. If you can find a core that is somewhat along the lines of what you want to do, then it makes things much easier. There is the ever popular Arduino AVR Boards:
https://github.com/arduino/ArduinoCore-avr
Arduino SAMD Boards:
https://github.com/arduino/ArduinoCore-samd
ESP8266:
https://github.com/esp8266/Arduino/
MightyCore:
https://github.com/MCUdude/MightyCore
ATTinyCore:
https://github.com/SpenceKonde/ATTinyCore
and so on. I actually published a list of all known Arduino hardware cores:
https://github.com/per1234/ino-hardware-package-list/blob/master/ino-hardware-package-list.tsv

The great thing is that Arduino's hardware system allows you to reference resources from other cores:
https://github.com/arduino/Arduino/wiki/Arduino-IDE-1.5-3rd-party-Hardware-specification#referencing-another-core-variant-or-tool
That allows you to create custom hardware cores with only a couple files. An example is carlosefr/atmega:
https://github.com/carlosefr/atmega/tree/master/avr
Notice how the entire core is only two files because it references resources from Arduino AVR Boards!
BAM.. Thank you!!


Quote
It's not clear to me what you mean by that.
I have a header font.h with a lot of ASCII-Signs. I included it in a matrix-libary (in .ccp file) to put out an array from a character. I want to know what is the right way ("programmer convention") to include the file:


1. the font.h with a font.cpp file

2. only the font.h (now, my option)

3. only the font.h and initialize the arrays with extern
Code: [Select]


#ifndef __FONT8X8_H__
#define __FONT8X8_H__


uint8_t ascii_8x5_whitespace[8] ={
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000000,
  0b00000011
};


*////////////////////
MANY ARRAYS
////////////////////*

uint8_t *ascii [] = {
ascii_8x5_whitespace, 
ascii_8x5_exclamationmark,
ascii_8x5_doublequote,
ascii_8x5_hash,
ascii_8x5_dollar,
ascii_8x5_percent,
ascii_8x5_ampersand,
ascii_8x5_singlequote,
ascii_8x5_openparenthesis,
ascii_8x5_closeparenthesis,
ascii_8x5_asterisk,
ascii_8x5_plus,
ascii_8x5_comma,
ascii_8x5_minus,
ascii_8x5_dot,
ascii_8x5_slash,
ascii_8x5_0,
ascii_8x5_1,
ascii_8x5_2,
ascii_8x5_3,
ascii_8x5_4,
ascii_8x5_5,
ascii_8x5_6,
ascii_8x5_7,
ascii_8x5_8,
ascii_8x5_9,
ascii_8x5_colon,
ascii_8x5_semicolon,
ascii_8x5_lessthan,
ascii_8x5_equal,
ascii_8x5_greaterthan,
ascii_8x5_questionmark,
ascii_8x5_at,
ascii_8x5_A, 
ascii_8x5_0b,   
ascii_8x5_C,   
ascii_8x5_D,   
ascii_8x5_E,   
ascii_8x5_F,   
ascii_8x5_G,   
ascii_8x5_H,   
ascii_8x5_I,   
ascii_8x5_J,   
ascii_8x5_K,   
ascii_8x5_L,   
ascii_8x5_M,   
ascii_8x5_N,   
ascii_8x5_O,   
ascii_8x5_P,   
ascii_8x5_Q,   
ascii_8x5_R,   
ascii_8x5_S,   
ascii_8x5_T,   
ascii_8x5_U, 
ascii_8x5_V,   
ascii_8x5_W,   
ascii_8x5_X,
ascii_8x5_Y,   
ascii_8x5_Z,
ascii_8x5_openbracket,
ascii_8x5_backslash,
ascii_8x5_closebracket,
ascii_8x5_carat,
ascii_8x5_underscore,
ascii_8x5_backquote,
ascii_8x5_a,
ascii_8x5_b,
ascii_8x5_c,
ascii_8x5_d,
ascii_8x5_e,
ascii_8x5_f,
ascii_8x5_g,
ascii_8x5_h,
ascii_8x5_i,
ascii_8x5_j,
ascii_8x5_k,
ascii_8x5_l,
ascii_8x5_m,
ascii_8x5_n,
ascii_8x5_o,
ascii_8x5_p,
ascii_8x5_q,
ascii_8x5_r,
ascii_8x5_s,
ascii_8x5_t,
ascii_8x5_u,
ascii_8x5_v,
ascii_8x5_w,
ascii_8x5_x,
ascii_8x5_y,
ascii_8x5_z,
ascii_8x5_openbrace,
ascii_8x5_bar,
ascii_8x5_closebrace,
ascii_8x5_tilde
};

#endif /* __FONT8X8_H__ */



Quote
If you have a proper include guard, you should have no problem with multiple #include directives for a library. However, an include guard only protects against multiple inclusions in the same translation unit. It does not protect against inclusions in multiple translation units (nor would you want it to). The .ino files of your sketch are a separate translation unit from .cpp or .c files in a library or even in your sketch. For this reason, it is possible to write code in a .h file that causes a compilation error when the file is #included in multiple translation units. However, it's certainly possible to fix that issue. If you want specific help with the issue, you'll need to post your code.
When i include the font.h file in the matrix-library and in the main.cpp i get an error!
I thought the preprocessor directives prevent this. (Double Insertion)

Juraj

one more simple example on how to define own boards
https://github.com/jandrassy/my_boards
You can't write an Arduino sketch if you didn't learn programming. Not the language, but the concepts of programming - algorithms and data types.

Go Up