Code Monkey home page Code Monkey logo

Comments (15)

Anton-V-K avatar Anton-V-K commented on September 17, 2024 10

Modifying library code when building sketches for different schematics is a pain in the neck.
Could you please adjust the source code in the way which would allow developers to define constants in their code.
Here is an example how this can be achieved in Adafruit_SSD1306.h:

#ifndef SSD1306_I2C_ADDRESS
#define SSD1306_I2C_ADDRESS   0x3C
#endif
#if !defined(SSD1306_128_64) && !defined(SSD1306_128_32) && !defined(SSD1306_96_16)
#define SSD1306_128_32
#endif

This way you'll keep backward compatibility.

from adafruit_ssd1306.

Jimmy-Z avatar Jimmy-Z commented on September 17, 2024 2

+1

from adafruit_ssd1306.

programus avatar programus commented on September 17, 2024 2

I tried to work out a malloc solution, but it seems the memory is not big enough to support it. So I worked out another solution that separates header files and implementations for each resolution but keep the core source being reused.
This might not be the best solution, but it could avoid changing the source of the library when changing the OLED resolution.
One can change the resolution by changing head file included.

ex.
To use an OLED 128x64:
#include <Adafruit_SSD1306_128_64.h>

from adafruit_ssd1306.

programus avatar programus commented on September 17, 2024 1

redo the library to use malloc is a big work. So I think you can adopt the option from @Anton-V-K before anyone send a perfect malloc PR.
At least, @Anton-V-K 's version allows me to set the resolution by the build flag -D SSD1306_128_64. I could specify a build flag when I use some IDE like platformio instead of the default Arduino IDE.
But current version, I can do nothing if I want to keep the library as is.

from adafruit_ssd1306.

programus avatar programus commented on September 17, 2024 1

@alexgorbatchev I have submitted a PR #94

from adafruit_ssd1306.

ladyada avatar ladyada commented on September 17, 2024 1

hiya, we would accept a solution with malloc that is backward compatible with current code, not #include noodling :)

from adafruit_ssd1306.

fpapadopou avatar fpapadopou commented on September 17, 2024

Hey @tdicola, this is Fotis from codebender. We just added the SSD1306 library to our platform and we've bumped into the same issue. Users have no write access to libraries' files on codebender, so we'd appreciate if you could move the defines to the examples's code, instead of them being hardcoded in the library code.

Thanks in advance!

from adafruit_ssd1306.

ladyada avatar ladyada commented on September 17, 2024

nevermind, this is not actually possible without a pretty fair rewrite because i used #define's not extern variables
there is no way for the library to pick up a #define in the sketch, thats just how C++ works
no fix at this time. will have to go thru and change the design to use malloc & copy the start buffer in from flash

from adafruit_ssd1306.

alexgorbatchev avatar alexgorbatchev commented on September 17, 2024

how much work would it be to address this?

from adafruit_ssd1306.

ladyada avatar ladyada commented on September 17, 2024

someone would have to redo the library to use malloc - feel free to do it and send a PR!

from adafruit_ssd1306.

ladyada avatar ladyada commented on September 17, 2024

anton's solution doesnt work in Arduino, as how C++ handles #defines, they're not global :) we would only accept a PR that works in Arduino since it is how people use the library

from adafruit_ssd1306.

alexgorbatchev avatar alexgorbatchev commented on September 17, 2024

@programus i like this, would you submit a PR for review?

from adafruit_ssd1306.

harbaum avatar harbaum commented on September 17, 2024

This sounds great, please accept this.

from adafruit_ssd1306.

programus avatar programus commented on September 17, 2024

I also tried the malloc solution but it seems consume too much memory to let arduino do something else besides display. So I have to work out this #include noodling thing.

from adafruit_ssd1306.

PaintYourDragon avatar PaintYourDragon commented on September 17, 2024

Fixed as of v1.2; display buffer uses malloc.

from adafruit_ssd1306.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.