IBEXcps / HaLiO-sw

GNU Lesser General Public License v2.1
0 stars 2 forks source link

Scroll between Logo and Information #2

Closed rafaellehmkuhl closed 6 years ago

rafaellehmkuhl commented 7 years ago

Implementing scroll on the display, switching between the HaLiO Logo and the information screen

rafaellehmkuhl commented 7 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?

patrickelectric commented 7 years ago

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 :)

rafaellehmkuhl commented 7 years ago

This is what I am already doing but doesnt work...

rafaellehmkuhl commented 7 years ago

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?

patrickelectric commented 7 years ago

maybe OLEDDisplayUi ui(display); should work.

rafaellehmkuhl commented 7 years ago

Worked! Thanks! Do you know why using the new operator, doesnt work?

patrickelectric commented 7 years ago

To use new, your ui need to be an OLEDDisplayUi* ui, which is not your case

rafaellehmkuhl commented 7 years ago

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)}'
patrickelectric commented 7 years ago

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), ...

rafaellehmkuhl commented 7 years ago

Diff file:

potato.diff.zip

patrickelectric commented 7 years ago

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.

patrickelectric commented 7 years ago

@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
        }
    };
rafaellehmkuhl commented 7 years ago

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?

patrickelectric commented 7 years ago

Yes, what are you putting over this lambda functions ? I still think that would be awesome to have a PR about this issue :)

rafaellehmkuhl commented 7 years ago

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.

rafaellehmkuhl commented 7 years ago

Patrick, did you take a look at how the Demo included on the library handles all?

include "SSD1306Brzo.h"

#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);
  }
}
rafaellehmkuhl commented 7 years ago

What is the correct way to pass a function inside a lambda function in c++?

patrickelectric commented 6 years ago

This approach is already in master, can we close this issue ?

rafaellehmkuhl commented 6 years ago

Yes, we can close it