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.64k stars 1.16k forks source link

Offset only 1 chain out of 3? #1130

Open multimarcus opened 4 years ago

multimarcus commented 4 years ago

Dear Zeller, Thank you for writing this amazing library and thanks to everyone for adding to it.

This might be a bit of silly question, I am new to C+ and I am learning bit by bit as I go. Is there a function/way to offset the x or y coordinate of just one chain out of three? I am working on a custom shape screen and would like to achieve the following, while still retaining a complete image? Yep, I can edit the image/animation in Photoshop/After Effects, but it would be much quicker to do it through code.

Thanks a lot for your help!

Screenshot 2020-08-31 at 16 08 35
hzeller commented 4 years ago

You might need to custom-implement a PixelMapper for this https://github.com/hzeller/rpi-rgb-led-matrix/blob/master/include/pixel-mapper.h . This should be a fairly simple implementation; here some rough pseudocode of the meat:

include "pixel-mapper.h"

class ShiftMapper : public rgb_matrix::PixelMapper {
  virtual const char *GetName() const { return "ThirdShiftMapper"; }
  virtual bool GetSizeMapping(int matrix_width, int matrix_height,
                              int *visible_width, int *visible_height) const {
    *visible_height = matrix_height;
    *visible_width = matrix_width + 32;   // because our square we cover is one panel wider
    return true;
  }

  void MapVisibleToMatrix(int matrix_width, int matrix_height,
                          int visible_x, int visible_y,
                          int *matrix_x, int *matrix_y) const {
    *matrix_y = visible_y;  // y always stays the same
    *matrix_x = visible_x;
    if (visible_y > 64)  { // third chain
      *matrix_x += 32;   // or minus, depending on shift
    }
  }
};

Then somewhere before you call RGBMatrix::CreateFromFlags(), register it:

rgb_matrix::RegisterPixelMapper(new ShiftMapper());

You then can use your new mapper by specifying on the command line --led-pixel-mapper=ThirdShiftMapper

If you have trouble with the c++, ask someone you know who does; they will be able to make something out of the above.

hzeller commented 4 years ago

? where would you murder the CPU ?

hzeller commented 4 years ago

The mapper is applied once at initialization time; nothing is used at runtime. And the code pushing data to the panels is only concerned about the actual panels, so there is now overhead in memory or runtime.

(David, I'd like you to please only respond to user issues if you know the details. You have helped users with the correct information before, so please more of that. But for things you can only speculate it is probably better to not add confusing information).

hzeller commented 4 years ago

Yes you are mistaken. The mapper is used to set-up a look-up table initially, then never used again.

multimarcus commented 4 years ago

Hey! Thanks a lot for all of the above! I will have a go at it over the next few days and will send an update!!!