Update on Library support (eg FastLED)

For some reason the namespace does not get used for const CRGB& rgb.

As a temporary workaround you could add it manually like this const NSFastLED::CRGB& rgb.

@ScruffR, I wonder if the pre-processor is playing havoc here. Perhaps a #pragma SPARK_NO_PREPROCESSOR is worth testing?

1 Like

@peekay123, yes this works.
It’s just odd that @bongo didn’t have this problem a few days ago.

Maybe there was some tweaking of the preproc going on in the background that caused some new oddities :wink:

So @bongo to circumvent this new issue add these lines to the top of your sketch

// to apply namespace to function parameter types too, use
#pragma SPARK_NO_PREPROCESSOR
//not required for FastLED since "application.h" gets included there already
//but SPARK_NO_PREPROCESSOR usually requires to add this include
//#include "application.h" 

If you should also get errors about some functions being unknown, you’d need to provide function prototypes.


Maybe @jgoggins or @suda could enlighten us about possible reasons for the change in behaviour :wink:

1 Like

Still does not compile. Here's my sample sketch:

// to apply namespace to function parameter types too, use
#pragma SPARK_NO_PREPROCESSOR
//not required for FastLED since "application.h" gets included there already
//but SPARK_NO_PREPROCESSOR usually requires to add this include
//#include "application.h"

// This #include statement was automatically added by the Spark IDE.
#include "FastLED/FastLED.h"
FASTLED_USING_NAMESPACE;

#define NUM_LEDS 256

#define DATA_PIN A5
#define CLOCK_PIN A3

CRGB leds[NUM_LEDS];

void setup() { 
    FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, GRB>(leds, NUM_LEDS);
}

void loop() { 
  
  led[1]=CRGB(255,0,0);
  FastLED.show();
  delay(500);
    
  led[1]=CRGB(0,0,0);
  FastLED.show();
  delay(500);
    
}

And here's the compiler output:

In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/FastLED.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/colorpalettes.cpp:4:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/colorutils.cpp:6:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/hsv2rgb.cpp:4:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/lib8tion.cpp:3:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/noise.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/power_mgt.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from FastLED/wiring.cpp:2:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
fastled_test.cpp:2:0: warning: ignoring #pragma SPARK_NO_PREPROCESSOR [-Wunknown-pragmas]
#pragma SPARK_NO_PREPROCESSOR
^
In file included from fastled_test.cpp:8:0:
FastLED/FastLED.h:12:2: warning: #warning FastLED version 3001000 (Not really a warning, just telling you here.) [-Wcpp]
#warning FastLED version 3001000 (Not really a warning, just telling you here.)
^
In file included from ../inc/spark_wiring.h:29:0,
from ../inc/application.h:29,
from FastLED/led_sysdefs_arm_stm32.h:4,
from FastLED/led_sysdefs.h:16,
from FastLED/FastLED.h:34,
from fastled_test.cpp:8:
../../core-common-lib/SPARK_Firmware_Driver/inc/config.h:12:2: warning: #warning "Defaulting to Release Build" [-Wcpp]
#warning "Defaulting to Release Build"
^
fastled_test.cpp: In function 'void loop()':
fastled_test.cpp:24:3: error: 'led' was not declared in this scope
led[1]=CRGB(255,0,0);
^
make: *** [fastled_test.o] Error 1

Error: Could not compile. Please review your code.

In this case it's not an library/IDE issue, but a coding typo.
You declared leds[] but try to use led[1] :wink:

Doh! Thanks @ScruffR. I had not seen the long list of warning messages I started seeing 7 days ago when I tried to compile code with a mistake. And thus I missed a genuine error in my code described at the end of a long list of messages.

My apologies to all who spent some time on this and my thanks for helping this novice.

Bongo

3 Likes

Hey there! I have been waiting to play with FastLED and the spark core for a long time now, and i am really happy to see it has been done!! So now i’m trying to get i compiling locally with NetBeans, but i keep running in to some obstacles and now i need help moving forward.
I have just installed NetBeans again following Elco ans seulater’s tutorials (THIS) except i’m not using ST-Link to flash, and i am using the feature/HAL branch.

First of all ā€œall warnings being treated as errorsā€ i set, but not form the makefile. I have been looking to see if the ā€œCFLAGS -Wno-errorā€ is being set elsewhere but haven’t accomplished to do so. So i tried to set it to ā€œ-Wno-errorā€ in the makefile, but it does not have any affect… Any idea why i am getting all warnings as errors, has it anything to do with the Spark-CLI?

The reason i am getting an warning is the way that FastLED is showing its version number, so I tried to just out comment that warning in the code (the easy-fix… apparently!) but now I am getting new errors…

 Building firmware for Spark core, platform ID: 0
   text	   data	    bss	    dec	    hex	filename
  12936	    632	   3564	  17132	   42ec	../build/target/bootloader/platform-0/bootloader.elf
../build/target/main/platform-0/src/application.o: In function `addLeds<(NSFastLED::ESPIChipsets)0u, 1u, 0u, (NSFastLED::EOrder)66u>':
C:\Repos\spark-firmware\main/./libraries/FastLED/firmware/FastLED.h:191: undefined reference to `NSFastLED::CLEDController::m_pHead'
C:\Repos\spark-firmware\main/./libraries/FastLED/firmware/FastLED.h:191: undefined reference to `NSFastLED::CLEDController::m_pTail'
C:\Repos\spark-firmware\main/./libraries/FastLED/firmware/FastLED.h:191: undefined reference to `NSFastLED::CFastLED::addLeds(NSFastLED::CLEDController*, NSFastLED::CRGB*, int, int)'
../build/target/main/platform-0/src/application.o: In function `NSFastLED::CFastLED::showColor(NSFastLED::CRGB const&)':
C:\Repos\spark-firmware\main/./libraries/FastLED/firmware/FastLED.h:399: undefined reference to `NSFastLED::CFastLED::showColor(NSFastLED::CRGB const&, unsigned char)'
../build/target/main/platform-0/src/application.o: In function `loop':
C:\Repos\spark-firmware\main/src/application.cpp:25: undefined reference to `NSFastLED::FastLED'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [../build/target/main/platform-0/main.elf] Fejl 1
make: *** [main] Fejl 2

BUILD FAILED (exit value 2, total time: 7s)

I have placed the library in the library folder and included it like this ā€œlibraries/FastLED/firmware/FastLED.hā€

//#pragma SPARK_NO_PREPROCESSOR

#include "application.h"

#include "libraries/FastLED/firmware/FastLED.h"
FASTLED_USING_NAMESPACE;

SYSTEM_MODE(SEMI_AUTOMATIC);

#define NUM_LEDS 160

#define DATA_PIN D1
#define CLOCK_PIN D0

CRGB leds[NUM_LEDS];

void setup() { 
    FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, GRB>(leds, NUM_LEDS);
}

void loop() { 
    FastLED.showColor(CRGB::Green);
}

Why am i getting those errors, have i implemented the library in a wrong way? Should i add anything to the makefile?

Also I wondered what is the best way to handle different libraries and multiply projects(application.cpp’s and other files) in NetBeans? Should i follow the uber library guide and just add them into the libraries folder and how can i choose witch project should get compile, in best meaner?

Thanks!

Can you elaborate a little bit on this?

When I declare this above setup() I get the following error on compilation:

error: 'rgb' declared as reference but not initialized

How do I actually use it in a function like this:

void testColor(CRGB color) {
    ....
}

How would I call the function?

testColor(CRGB::Red); throws an error when compiling:

error: 'CRGB' was not declared in this scope

@gotnull, have you tried the #pragma SPARK_NO_PREPROCESSOR and in the quote you posted above the important bit was the manually added namespace qualifier

And this exact line of code would not really help you, since your over all program (which you haven't shown to have a look at ;-)) does not require that line, but Bongo's program did.

In your case you'd need to alter your code by adding the namespace like this

void testColor(NSFastLED::CRGB color) {
  ...
}

If I create the method like above and then call the following:

testColor(NSFastLED::CRGB::Black);

I get the same error:

error: 'CRGB' was not declared in this scope

Since I’m not using this lib and can’t really test any of my suggestions as such, I’m only going by my C++ experience.
Maybe @kriegsman can help you better with your particular problem :wink:

I don’t recall the exact details, because it was about two months ago that I helped someone with this (and have missed the conversation on this post), but there is something that the spark preprocessor was doing that was causing definitions to end up being moved (I think it was prototypes?) above the using statement. In their case it was enough to move their method declarations before usages, but I don’t recall exactly which. My entire dev setup is a bit hosed at the moment, but I’m working on spinning it back up as I have a bunch of M0 work to do as well as 2 photons showing up later this week.

1 Like

Just so I’m clear (I’m a huge FastLED user with my arduino boards) – This will not work out of the box with the Particle Photons … it needs to be ā€œportedā€? That sucks!

@webdevbrian, won’t be long before the official new firmware release happens. Then… porting fever!

1 Like

Porting is necessary and common when moving optimized low-level code between different systems. You can’t take a PS4 game and run it on an XBox without porting, nor take a iOS app and run it on android.

The same is true when moving Arduino libraries to Particle devices, particularly when they use specific low-level features of the ATMega386p. The arduino is 8-bit, the STM32 in Particle devices 32-bit. You can’t put a square peg in a round hole without changes!

Would that be the HAL I’ve read about @peekay123?

Just talked to dan actually – I know he’s working hard (we all have FT jobs, totally understandable) – just really excited to see the possibility with the increase of ram, flash and CPU clock speed … this is going to get interesting!

Firmware release … this piques my interest! Sorry, can you share more details? I own a shop with 20k+ FastLED Lib deployments, this is hugely of interest to me and my team. Thank you!

Sorry - didn’t see this response via email reply (I got a few email replies but not of a notification of your comment) –

Trust me, I understand the difference between systems, let alone deployments! My team and I do this for a living. I was under the impression that the photon was an arduino equivalent, especially with the arduino IDE.

We have a ton of deployments using micros, minis and unos – I just needed to understand the STM32, which I get, wholeheartedly. I’ve already spoke with Dan – the man is a pure machine and a legend in his own right for sure.

I might be able to fit a square ped in a hole … give me a few tools! :smile:

Being that this looks like the right thread:

Is there any LED lib support for the photon yet? FastLED, ADA … no go so far it looks like (that I can find). Ordered a few dozen of these things, WHOOPS!