hzeller / rpi-rgb-led-matrix

Controlling up to three chains of 64x64, 32x32, 16x32 or similar RGB LED displays using Raspberry Pi GPIO
GNU General Public License v2.0
3.67k stars 1.17k forks source link

Use the library with Qt Creator on Pi 3 Jessie #543

Closed johann74270 closed 6 years ago

johann74270 commented 6 years ago

we have everyone, I'm having trouble including feature libraries in my Qt program. I'm a beginner in programming, if you could help me I have the impression that there is a problem in the library I get sort of wrong:

/home/pi/rpi-rgb-led-matrix/lib/led-matrix.cc:361: error: undefined reference to `rgb_matrix::internal::PixelMapper::get(int, int)'

with this simple code :

OBJECTS += /home/pi/rpi-rgb-led-matrix/lib/led-matrix.o INCLUDEPATH += /home/pi/rpi-rgb-led-matrix/include LIBS += -L/home/pi/rpi-rgb-led-matrix/lib

include

include "led-matrix.h"

include

include

include

include

using rgb_matrix::GPIO; using rgb_matrix::RGBMatrix; using rgb_matrix::Canvas;

volatile bool interrupt_received = false; static void InterruptHandler(int signo) { interrupt_received = true; }

static void DrawOnCanvas(Canvas canvas) { /

  • Let's create a simple animation. We use the canvas to draw
  • pixels. We wait between each step to have a slower animation. */ canvas->Fill(0, 0, 255);

    int center_x = canvas->width() / 2; int center_y = canvas->height() / 2; float radius_max = canvas->width() / 2; float angle_step = 1.0 / 360; for (float a = 0, r = 0; r < radius_max; a += angle_step, r += angle_step) { if (interrupt_received) return; float dot_x = cos(a 2 M_PI) r; float dot_y = sin(a 2 M_PI) r; canvas->SetPixel(center_x + dot_x, center_y + dot_y, 255, 0, 0); usleep(1 * 1000); // wait a little to slow down things. } }

int main(int argc, char *argv[]) { QCoreApplication a(argc, argv);

RGBMatrix::Options defaults;
defaults.hardware_mapping = "regular";  // or e.g. "adafruit-hat"
defaults.rows = 32;
defaults.chain_length = 1;
defaults.parallel = 1;
defaults.show_refresh_rate = true;
Canvas *canvas = rgb_matrix::CreateMatrixFromFlags(&argc, &argv, &defaults);
if (canvas == NULL)
  return 1;

// It is always good to set up a signal handler to cleanly exit when we
// receive a CTRL-C for instance. The DrawOnCanvas() routine is looking
// for that.
signal(SIGTERM, InterruptHandler);
signal(SIGINT, InterruptHandler);

DrawOnCanvas(canvas);    // Using the canvas.

// Animation finished. Shut down the RGB matrix.
canvas->Clear();
delete canvas;

return a.exec();

}

hzeller commented 6 years ago

You need to link the full library lib/librgbmatrix.a not only led-matrix.o in your build system. So

OBJECTS += /home/pi/rpi-rgb-led-matrix/lib/led-matrix.o

won't do it, you rather want something like

LIBS += -L/home/pi/rpi-rgb-led-matrix/lib -lrgbmatrix

This is described in the api integration section.