Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change some variables in tinyNeoPixel from private to protected #1103

Open
moose4lord opened this issue May 23, 2024 · 4 comments
Open

Change some variables in tinyNeoPixel from private to protected #1103

moose4lord opened this issue May 23, 2024 · 4 comments
Assignees
Labels
design decision A design decision is needed prior to implementation.

Comments

@moose4lord
Copy link
Contributor

moose4lord commented May 23, 2024

Hi, I'm using a NeoPixel library that inherits from the Adafruit_NeoPixel class and would like to modify the library to instead inherit from your tinyNeoPixel class. Adafruit_NeoPixel exposes some of the nitty gritty details of its inner workings by declaring some critical variables as "protected", making them available to classes that inherit from Adafruit_Neopixel.

protected:
#ifdef NEO_KHZ400 // If 400 KHz NeoPixel support enabled...
  bool is800KHz; ///< true if 800 KHz pixels
#endif
  bool begun;         ///< true if begin() previously called
  uint16_t numLEDs;   ///< Number of RGB LEDs in strip
  uint16_t numBytes;  ///< Size of 'pixels' buffer below
  int16_t pin;        ///< Output pin number (-1 if not yet set)
  uint8_t brightness; ///< Strip brightness 0-255 (stored as +1)
  uint8_t *pixels;    ///< Holds LED color values (3 or 4 bytes each)
  uint8_t rOffset;    ///< Red index within each 3- or 4-byte pixel
  uint8_t gOffset;    ///< Index of green byte
  uint8_t bOffset;    ///< Index of blue byte
  uint8_t wOffset;    ///< Index of white (==rOffset if no white)
  uint32_t endTime;   ///< Latch timing reference

Unfortunately, those variables are declared private in tinyNeoPixel, so are not reachable. Would you be willing to change the declaration to protected?

Thanks for sharing all your ATtiny hard work.

@SpenceKonde
Copy link
Owner

Can you explain what the reasoning is behind:

  1. Why they might ever have been made private? I am a C person, this C++ object oriented stuff and classes - I don't have the instinct there.

@SpenceKonde SpenceKonde added the design decision A design decision is needed prior to implementation. label Jul 26, 2024
@moose4lord
Copy link
Contributor Author

I have to go back to 2017 to find a version of the Adafruit_Neopixel lib that has those variables declared as private. When Adafruit released v1.1.2 of that lib on Jun 28, 2017, they changed the designation from private to protected. No real mention of it in the release, they just kind of snuck it in there.

The three access specifiers in C++ are:
public - members are accessible from outside the class.
private - members cannot be accessed from outside the class.
protected - members cannot be accessed from outside the class, however, they can be accessed in inherited classes.

So protected is almost the same as private, but a little less restrictive for classes that inherit from a base class. I help maintain the LED effects lib WS2812FX, which inherits from the Adafruit_Neopixel lib and makes use of the variables that are declared protected. Alternatively, to inherit from your tinyNeoPixel lib for ATtiny devices, I need the variables declared protected as well.

Hope that makes things a little clearer.

@SpenceKonde
Copy link
Owner

So you're saying we missed a correction in adafruits version that should be applied here too?

@moose4lord
Copy link
Contributor Author

moose4lord commented Jul 28, 2024

Yes, that's what it looks like to me.

Did you notice the pull request I created?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design decision A design decision is needed prior to implementation.
Projects
None yet
Development

No branches or pull requests

2 participants