Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vmapper #1009

Merged
merged 7 commits into from
Mar 18, 2020
Merged

Vmapper #1009

Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 35 additions & 1 deletion examples-api-use/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,40 @@ two chains with 8 panels each

(`--led-chain=8 --led-parallel=2 --led-pixel-mapper="U-mapper"`).

#### V-mapper

By default, when you add panels on a chain, they are added horizontally.
If you have 2 panels of 64x32, you get 128x32. What if you wanted 64x64?
V-mapper allows the stacking to be vertical and not horizontal.

It is compatible with parallel output, so if you have 12 128x64 panels, without this
mapper, you can either do a matrix of 3x3 panels (384x192). Adding more panels
would force you to have a 4x3 layout (512x192) while you probably want a 3x4
layout (384 * 256) for a better aspect ratio.

```
./demo --led-rows=64 --led-cols=128 --led-chain=4 -led-parallel=3 --led-pixel-mapper=V-mapper -D0
```

Note that this is not a U mapper, all the panels are correct side up, and you need
more cable length. It looks like this, 3 chains of 4 panels for a total of 32K pixels
per chain. This is also a good time to mention that this is probably an upper limit of
what you can reasonably output without having an unusable fresh rate
( Try these options to help: --led-pwm-bits=7 --led-pwm-dither-bits=1 and get about 100Hz )

```
[O < I] [O < I] [O < I]
,---' ,---' ,---'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, pretty :)

[O < I] [O < I] [O < I]
,---' ,---' ,---'
[O < I] [O < I] [O < I]
,---' ,---' ,---'
[O < I] [O < I] [O < I]
^ ^ ^
Ch3 Ch2 Ch1
```


#### Rotate

The "Rotate" mapper allows you to rotate your screen. It takes an angle
Expand Down Expand Up @@ -387,4 +421,4 @@ line option in C++ and Python.
[git-submodules]: http://git-scm.com/book/en/Git-Tools-Submodules
[pixelpush]: https://github.com/hzeller/rpi-matrix-pixelpusher
[pp-vid]: ../img/pixelpusher-vid.jpg
[otf2bdf]: https://github.com/jirutka/otf2bdf
[otf2bdf]: https://github.com/jirutka/otf2bdf
45 changes: 45 additions & 0 deletions lib/pixel-mapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,50 @@ class UArrangementMapper : public PixelMapper {
int parallel_;
};



class VerticalMapper : public PixelMapper {
public:
VerticalMapper() {}

virtual const char *GetName() const { return "V-mapper"; }

virtual bool SetParameters(int chain, int parallel, const char *param) {
chain_ = chain;
parallel_ = parallel;
return true;
}

virtual bool GetSizeMapping(int matrix_width, int matrix_height,
int *visible_width, int *visible_height)
const {
*visible_width = matrix_width * parallel_ / chain_;
*visible_height = matrix_height * chain_ / parallel_;
fprintf(stderr, "%s: C:%d P:%d. Turning W:%d H:%d Physical "
"into W:%d H:%d Virtual\n",
GetName(), chain_, parallel_,
*visible_width, *visible_height, matrix_width, matrix_height);
return true;
}

virtual void MapVisibleToMatrix(int matrix_width, int matrix_height,
int x, int y,
int *matrix_x, int *matrix_y) const {
int panel_width = matrix_width / chain_;
int panel_height = matrix_height / parallel_;
*matrix_x = (x % panel_width) + int(y/panel_height)* panel_width;
*matrix_y = (y % panel_height) + int(x/panel_width) * panel_height;

//fprintf(stderr, "%s: Panel-W:%d Panel-H:%d. X: %3d -> %3d, Y: %3d -> %3d\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't leave commented-out code in the final version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I left it there on purpose it case it helps someone (possibly me) writing the next mapper. Understanding how things worked without it would have been hard (it was non obvious to see how things were mapped)
If you'd prefer, I can put it under an #ifdef 0 or something else, though, but if you really don't want it, I can remove it and apply it again in my tree as I will definitely want it again in the future if I write another mapper.
What's your call?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing commented-out here. Someone who will want to debug this will add something very similar in the working copy, but here, we should leave out the clutter.

Also above in the GetSizeMapping(), the output should not be there, but you can #if 0 that out if you want.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, PTAL

// GetName(), panel_width, panel_height, x, *matrix_x, y, *matrix_y);
}

private:
int chain_;
int parallel_;
};


typedef std::map<std::string, PixelMapper*> MapperByName;
static void RegisterPixelMapperInternal(MapperByName *registry,
PixelMapper *mapper) {
Expand All @@ -233,6 +277,7 @@ static MapperByName *CreateMapperMap() {
// Register all the default PixelMappers here.
RegisterPixelMapperInternal(result, new RotatePixelMapper());
RegisterPixelMapperInternal(result, new UArrangementMapper());
RegisterPixelMapperInternal(result, new VerticalMapper());
RegisterPixelMapperInternal(result, new MirrorPixelMapper());
return result;
}
Expand Down