EdwinCroissantArduinoLibraries / SMT172

Library for the ultra-low power, high accuracy SMT172 temperature sensor.
GNU General Public License v3.0
5 stars 2 forks source link

Compilation error due to wrong conceptual file structure #1

Open rkandilarov opened 7 years ago

rkandilarov commented 7 years ago

First I would like to say - GREAT JOB for the library!!! It saves me a lot of time using the SMT172 sensors!

But the library as it is now cannot be used directly (without dummy "hack" - deleting/renaming files) as external lib to Arduino IDE. By default, as I understand it, ARDUINO compiles all *.cpp files under the library/LIBNAME/src folder. So if anybody simply clones this repo (as s/he'll usually do with the other libs) s/he'll have under libraries/SMT172/src 3 incompatible with each other "versions" of the library. Then the compiler fill fail. In my case (Arduino UNO selected as board) it gives the error:

"/home/rossi/.arduino15/packages/arduino/tools/avr-gcc/4.9.2-atmel3.5.3-arduino2/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10613 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR   "-I/home/rossi/.arduino15/packages/arduino/hardware/avr/1.6.17/cores/arduino" "-I/home/rossi/.arduino15/packages/arduino/hardware/avr/1.6.17/variants/standard" "-I/home/rossi/Arduino/libraries/SMT172/src" "/home/rossi/Arduino/libraries/SMT172/src/SMT172_T4.cpp" -o "/tmp/arduino_build_456563/libraries/SMT172/SMT172_T4.cpp.o"
/home/rossi/Arduino/libraries/SMT172/src/SMT172_T4.cpp: In function 'void TIMER4_COMPA_vect()':
/home/rossi/Arduino/libraries/SMT172/src/SMT172_T4.cpp:29:2: error: 'TIMSK4' was not declared in this scope
  TIMSK4 = 0;    // no more interrupts for now from timer 4
  ^

I'm not deep in ARDUINO world but suppose that the clear way to do it should be like in arduino-1.6.*/libraries/IRremote/IRremoteInt.h:

Will try to submit pull request when I have time these days.

EdwinCroissant commented 7 years ago

Thank you for the thumbs up :)

The library compiles fine in Sloeber V4. You are compiling for an atmega328p that has no timer 4. Please try to compile for an atmega2560 and see if the problem persists.

rkandilarov commented 7 years ago

Of course it will work if I select the proper board :). But as I need it for atmega328p I need to rename the files with definitions for the inexistent timers in order to prevent the IDE to try to compile them.

Will sent you proposition for some pragma changes, but when I come back to the project in few weeks.

EdwinCroissant commented 7 years ago

You are right!

I'm using Sloeber V4 so I installed the latest Arduino software and it seems that the behavior of include changed since the last time I tested this with the Arduino software. Include now not only includes the file but all the files in that directory :(

Work around at the moment is to delete the unwanted files in the library.

I think that I have to put in some compiler conditionals so that the files for the timers available in the chip are only visible to the compiler when those timers are present.

Thank you for bringing this up :)

EdwinCroissant commented 7 years ago

I have added compiler conditionals for the microcontroller type. The library now compiles for the atmega328p and the like.

I tested this again and found out that the compiler error is also present in Sloeber. I probably tested the timer 4 and timer 5 code only with the 2560 and never checked if it was still working for the 328 :(

The funny thing is that without the guards you get an error when using the SMT172.h as the compiler also sees SMT172_T4.cpp and SMT172_T5.cpp when compiling for a 328 but does not see the SMT172_T4.h and SMT172_T5.h

I wonder if the compiler only uses the included header files in the first stage and all of the cpp files in the library in the second stage.