These are chat archives for Makuna/NeoPixelBus

1st
Feb 2018
Michael Miller
@Makuna
Feb 01 2018 00:36
@dguerizec What do you mean choked? What platform are you using? I will take a deeper look tonight into that once you let me know the platform.
dguerizec
@dguerizec
Feb 01 2018 15:26
@Makuna here is the error message:
/tmp/arduino_modified_sketch_907016/NeoPixelBufferShader.ino: In function 'void loop()':
NeoPixelBufferShader:163: error: no matching function for call to 'NeoBuffer<NeoBufferMethod<NeoGrbFeature> >::Render(NeoPixelBus<NeoGrbFeature, NeoEsp8266DmaMethodBase<NeoEsp8266DmaSpeed800Kbps> >&, BrightnessShader<NeoGrbFeature>&)'
image.Render<BrightnessShader<NeoGrbFeature>>(strip, shader);
I'm trying to compile for ESP8266
actually the problem seems to lie in the NeoBuffer class missing a Render method
since image is declared as a NeoBuffer
trying to use NeoDib instead of NeoBuffer for image instance does not work either
Ash
@ashthespy
Feb 01 2018 19:17

Greetz could I trouble you all with a general C/C++ question?
I am trying to make my code portable to different boards, that may or may not have all pins.
So, I am attempting to setup the GPIO pins, based on what type of board it is, something like this

/**
 * Pass the HW pin definitions and set outputs
 *
 * @param Type  Controller board type [BoardType]
 * @param RPin  Red Pin number [uint8_t]
 * @param GPin  Green Pin number [uint8_t]
 * @param BPin  Blue Pin number [uint8_t]
 * @param WWPin WarmWhite Pin number [uint8_t]
 * @param CWPin ColdWhite Pin number [uint8_t]
 */
void pinDef(BoardType type, uint8_t rpin, uint8_t gpin, uint8_t bpin);
void pinDef(BoardType type, uint8_t wwpin, uint8_t cwpin);
void pinDef(BoardType type, uint8_t rpin, uint8_t gpin, uint8_t bpin, uint8_t wwpin);
void pinDef(BoardType type, uint8_t rpin, uint8_t gpin, uint8_t bpin, uint8_t wwpin, uint8_t cwpin);
void pinDef(BoardType type, uint8_t wwpin);
void pinDef(BoardType type, uint8_t cwpin);

Would there be a more efficient way of doing such a thing?

Michael Miller
@Makuna
Feb 01 2018 19:19
@ashthespy Is the pinDef a member of a class or just a function?
Do you use the BoardType for anything specific inside?
Michael Miller
@Makuna
Feb 01 2018 19:27
@dguerizec Oh wow. After some deep investigation, it looks like I missed a step in an old checkin. One of those examples was to be replaced by the other. The current NeoPixelBufferShader is an OLD model of doing it; of which I deprecated with the new model as demonstrated in NeoPixelDibTest
Ash
@ashthespy
Feb 01 2018 19:36
@Makuna pinDef is a member of a class
Combining some other members such as bool writeOutput(const RGBW& currColour,bool update);
Michael Miller
@Makuna
Feb 01 2018 19:39
@ashthespy Is the class that pinDef is part of, is it instanced for one boardtype per "compiled" code? Is Boardtype dynamic in nature?
Ash
@ashthespy
Feb 01 2018 19:44
pinDef would indeed be instanced only once for a boardtype per compiled code.
i.e I select boardtype --> flash to that board type :-s
Michael Miller
@Makuna
Feb 01 2018 19:47
You have a good case for using templates here. The class would take a template param of the board, the board classes would be specific to the board types. This is very similar to how NeoPixelBus works with color patterns BGR, BGRW, etc.
Ash
@ashthespy
Feb 01 2018 19:48
Aha! I recall talking about templates here long time back, got overwhelmed. I will look into it a bit more!
Michael Miller
@Makuna
Feb 01 2018 19:49
A favorite book of mine on the subject is "Modern C++ Design" by Andrei Alexandrescu.
Ash
@ashthespy
Feb 01 2018 19:50
Will check if uni has it :-)
Would NeoGamma.h be a good example to base things on?
Michael Miller
@Makuna
Feb 01 2018 19:52
That's a simple enough example of idea, yes.
Ash
@ashthespy
Feb 01 2018 20:10
@Makuna - would you have a few mins and the mental space right now?
I want to check if I did indeed understand the basics of templates correctly!
Michael Miller
@Makuna
Feb 01 2018 20:15
make it quick
Ash
@ashthespy
Feb 01 2018 20:17
In the NeoGamma example,
template<typename T_METHOD> class NeoGamma defines a template class NeoGamma, that based on T_METHOD would call the appropriate Correct method
Where T_METHOD should be a valid class with a defined Correct method yes?
Michael Miller
@Makuna
Feb 01 2018 20:17
Yes
Ash
@ashthespy
Feb 01 2018 20:18
:+1:
Hmm, this is beautiful.
Michael Miller
@Makuna
Feb 01 2018 20:19
Once you wrap your head around it, it does become very elegant way to solve problems. The syntax can get a little tricky at times though.
The biggest thing is, the compiler produces very efficient code with this way; while older OOP models of derivation of classes isn't so effecient
Ash
@ashthespy
Feb 01 2018 20:21
Hmm, is there a 'sanity check' at compile time to check if T_METHOD is actually a valid class, that has a valid Correct method?
Michael Miller
@Makuna
Feb 01 2018 20:21
Keep this thought in mind; "think contains A, not is A"
Yes, this is the other nice thing, everything is caught at compile time ;-)
Ash
@ashthespy
Feb 01 2018 20:22
in analogy with the example at hand,
"Think NeoGamma contains NeoGammaTableMethod" ?
Michael Miller
@Makuna
Feb 01 2018 20:23
yes, in more complex examples it will be even more so, where you might actually store an instance of the type.
Ash
@ashthespy
Feb 01 2018 20:24
So in my example, I shall now define a new template class that sets up, and toggles GPIOS, with methods specific to my BoardType
I should probably sketch out this code before hitting the keys :-p
Thank you for your patience Michael.
Have a good night!
Michael Miller
@Makuna
Feb 01 2018 20:25
A general term for clarification, Method classes and Feature classes are definitions of types of classes that applied to template classes.
Method generally meaning I have functionality that is different, complex functions.
Feature generally meaning I have constants that are different, simple static functions.
good night
Ash
@ashthespy
Feb 01 2018 20:28
That is just naming convention correct?
dguerizec
@dguerizec
Feb 01 2018 21:53
@Makuna ok, I saw that file, but I thought NeoDib was a 1D version of NeoBuffer, so not that convenient to use for a LED matrix
what would be the best way to do a 2D shader without having to explicitely convert index to/from (x, y) ?
Michael Miller
@Makuna
Feb 01 2018 22:46
@dguerizec Ahh, you need the 2D version then. I was originally planning on doing that, but I pulled back on doing it due to complexity. Let me take a look.
@ashthespy Yes, its just a naming convention.
dguerizec
@dguerizec
Feb 01 2018 22:47
I tried to adapt the Render function from the NeoDib to the NeoBuffer class, but I had no success
dguerizec @dguerizec having problems of C++ understanding
dguerizec
@dguerizec
Feb 01 2018 22:52
BTW @Makuna I'm currently using NeoBuffer in another application, and in order to be able to use its GetPixelColor method, I had to remove its const qualifier
here is the complete error message:
/home/david/Arduino/libraries/NeoPixelBus/src/internal/NeoBuffer.h: In instantiation of 'typename T_BUFFER_METHOD::ColorObject NeoBuffer<T_BUFFER_METHOD>::GetPixelColor(int16_t, int16_t) const [with T_BUFFER_METHOD = NeoBufferMethod<NeoGrbFeature>; typename T_BUFFER_METHOD::ColorObject = RgbColor; int16_t = short int]': /tmp/arduino_build_esprit/sketch/app.cpp:45:55: required from here /home/david/Arduino/libraries/NeoPixelBus/src/internal/NeoBuffer.h:70:53: error: passing 'const NeoBuffer<NeoBufferMethod<NeoGrbFeature> >' as 'this' argument of 'uint16_t NeoBuffer<T_BUFFER_METHOD>::pixelIndex(int16_t, int16_t) [with T_BUFFER_METHOD = NeoBufferMethod<NeoGrbFeature>; uint16_t = short unsigned int; int16_t = short int]' discards qualifiers [-fpermissive] return _method.GetPixelColor(pixelIndex(x, y));
declaration of my buffer: NeoBuffer<NeoBufferMethod<MyPixelColorFeature>> buffer(img_width, img_height + 1, NULL);
and the call that don't pass the compilation because of const: RgbColor color = buffer.GetPixelColor(i, 0);