Closed rafaellehmkuhl closed 6 years ago
@patrickelectric
I am trying to create an OLEDDisplayUi object (on the setUI function) and sending the display object as a parameter:
Display::Display() :
// Initialize the OLED display using brzo_i2c
// D3 -> SDA
// D5 -> SCL
display(new SSD1306Brzo(0x3c, SDA, SCL))
{
debug("Starting Display.");
// Initialising the UI will init the display too.
display->init();
display->flipScreenVertically();
display->setFont(ArialMT_Plain_10);
}
void Display::setUI()
{
// Initialize the UI
ui(new OLEDDisplayUi(&display));
}
but I am receiveing this error:
/home/rafael/Arduino/libraries/arduino_951116/OLEDDisplayUi.h:164:5: note: no known conversion for argument 1 from 'SSD1306Brzo**' to 'OLEDDisplay*'
I thought the display object (SSD1306Brzo class) inherited from the OLEDDisplay class.
Any idea?
This sould work [EDITED]:
ui(new OLEDDisplayUi(display));
Like said here:
note: no known conversion for argument 1 from 'SSD1306Brzo**' to 'OLEDDisplay*'
You need a pointer and not a pointer pointer :)
This is what I am already doing but doesnt work...
I have changed the code to
void Display::setUI()
{
// Initialize the UI
ui(new OLEDDisplayUi(display));
}
and now I'm receiving this error:
/home/rafael/HaLiO_Fork/HaLiO-sw/smartmeter/build/sketch/display.cpp: In member function 'void Display::setUI()':
display.cpp:42: error: expression cannot be used as a function
ui(new OLEDDisplayUi(display));
^
How should I call this?
maybe OLEDDisplayUi ui(display);
should work.
Worked! Thanks! Do you know why using the new operator, doesnt work?
To use new, your ui need to be an OLEDDisplayUi* ui
, which is not your case
This is the code now (just the relevant parts):
Display::Display() :
display(new SSD1306Brzo(0x3c, SDA, SCL))
{
debug("Starting Display.");
setUI();
FrameCallback frames[] = {displayData, displayLogo};
int frameCount = 2;
}
void Display::displayData(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y)
{
}
void Display::displayLogo(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y)
{
}
I am trying to pass the functions displayData and displayLogo to an array of type FrameCallback, which is the way the OLEDDisplayUi library handles the fucntions (this functions are indeed the frames that will be displayed). The error I'm receiveing is this:
display.cpp:35: error: cannot convert 'Display::displayLogo'
from type 'void (Display::)(OLEDDisplay*, OLEDDisplayUiState*, int16_t, int16_t)
{aka void (Display::)(OLEDDisplay*, OLEDDisplayUiState*, short int, short int)}'
to type 'FrameCallback
{aka void (*)(OLEDDisplay*, OLEDDisplayUiState*, short int, short int)}'
I am not able to test you code now, please, can you send me a patch ?
git commi diff >> potato.diff
You may whant to try static_cast, FrameCallback frames[] = {static_cast<FrameCallback*>(displayData), ...
Diff file:
Tys, @rafaellehmkuhl. I'll test it now. ps: you don't need to zip it :) ps2: you need to make your diff ou patch based on master. Without args git diff will create a diff from the last commit. I don't have your last commit, so you'll need to create a diff from master, ou applying a PR for me to check. ps3: I'll use your patch and modify it to work in my case.
@rafaellehmkuhl, to solve your problem using our actual struct, the best approach is via lambda functions, can you test this code ?//
FrameCallback frames[] = {
[=](OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
//logo
},
[=](OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
//data
}
};
Would never tought about it.
Just tested. It compiles, but screen is not working.
Another thing: where are you passing displayLogo and displayData to the array on you solution?
Yes, what are you putting over this lambda functions ? I still think that would be awesome to have a PR about this issue :)
Without arguments inside the lambda functions (where the comments are, right?) it compiles. With the displayData and displayLogo functions inside it gives an error.
Im pushing the PR so you cant take a better look.
Patrick, did you take a look at how the Demo included on the library handles all?
#include "OLEDDisplayUi.h"
#include "images.h"
SSD1306Brzo display(0x3c, D3, D5);
OLEDDisplayUi ui ( &display );
void drawFrame1(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
}
void drawFrame2(OLEDDisplay *display, OLEDDisplayUiState* state, int16_t x, int16_t y) {
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(0 + x, 10 + y, "Arial 10");
}
// This array keeps function pointers to all frames. Frames are the single views that slide in
FrameCallback frames[] = { drawFrame1, drawFrame2, drawFrame3, drawFrame4, drawFrame5 };
int frameCount = 5;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println();
ui.setTargetFPS(30);
// Customize the active and inactive symbol
ui.setActiveSymbol(activeSymbol);
ui.setInactiveSymbol(inactiveSymbol);
ui.setFrameAnimation(SLIDE_LEFT);
ui.setFrames(frames, frameCount);
ui.init();
display.flipScreenVertically();
}
void loop() {
int remainingTimeBudget = ui.update();
if (remainingTimeBudget > 0) {
// You can do some work here
// Don't do stuff if you are below your
// time budget.
delay(remainingTimeBudget);
}
}
What is the correct way to pass a function inside a lambda function in c++?
This approach is already in master, can we close this issue ?
Yes, we can close it
Implementing scroll on the display, switching between the HaLiO Logo and the information screen