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

Support static areas (such as bottom line of pixels) that get excluded from scrolling #23

Closed
thediveo opened this issue Mar 30, 2017 · 4 comments
Assignees
Milestone

Comments

@thediveo
Copy link

When using a smaller font for scrolling text through the LED matrix, a static top/bottom row of pixels could be used to signal some static information, such as a progress bar, status "bar", et cetera.

@Gadgetoid
Copy link
Member

This is an interesting idea. I'll have to think if there's a graceful way to integrate it into the library without beginning to make things overly complicated.

@Gadgetoid Gadgetoid self-assigned this Mar 31, 2017
@Gadgetoid
Copy link
Member

I think this may be one of those things that's best demonstrated with an example, rather than building it directly into the library itself.

That said, it does require a redraw of the lower portion of the buffer after each scroll to place the "fix" portion into the right place. So perhaps a static layer is a good idea?

Thinking about it, a balance between these two extremes- keeping the library simple, but making it easier to produce an example that accomplishes this effect (and more)- might be the best approach.

Here's the contents of show() presently:

def show(self):
"""Show the buffer contents on the display.
The buffer is copied, then scrolling, rotation and flip y/x
transforms applied before taking a 17x7 slice and displaying.
"""
self.setup()
next_frame = 0 if self._current_frame == 1 else 0
display_shape = self.get_shape()
display_buffer = self._grow_buffer(self.buf, display_shape)
for axis in [0,1]:
if not self._scroll[axis] == 0:
display_buffer = numpy.roll(display_buffer, -self._scroll[axis], axis=axis)
# Chop a width * height window out of the display buffer
display_buffer = display_buffer[:display_shape[0], :display_shape[1]]
if self._flipx:
display_buffer = numpy.flipud(display_buffer)
if self._flipy:
display_buffer = numpy.fliplr(display_buffer)
if self._rotate:
display_buffer = numpy.rot90(display_buffer, self._rotate)
output = [0 for x in range(144)]
for x in range(self._width):
for y in range(self._height):
idx = self._pixel_addr(x, self._height-(y+1))
try:
output[idx] = self._gamma_table[int(display_buffer[x][y] * self._brightness)]
except IndexError:
output[idx] = 0
self._bank(next_frame)
offset = 0
for chunk in self._chunk(output, 32):
#print(chunk)
self.i2c.write_i2c_block_data(self.address, _COLOR_OFFSET + offset, chunk)
offset += 32
self._frame(next_frame)
del display_buffer

What if we had a before_display handler- a function you could pass to show() which received the buffer right after it's grabbed in the line: display_buffer = display_buffer[:display_shape[0], :display_shape[1]] but just before the horizontal/vertical flip and rotation are applied.

This would allow you to modify the buffer in-place right before it's displayed on Scroll pHAT HD, giving an opportunity to draw static UI over the top without having a whole spaghetti mess of static drawing functions and an additional buffer stored within the library.

How does that sound?

@Gadgetoid Gadgetoid added this to the 1.2.0 milestone Jan 23, 2018
@thediveo
Copy link
Author

Sounds very sound!

Gadgetoid added a commit that referenced this issue Jan 24, 2018
@Gadgetoid
Copy link
Member

See: f6447a6

This includes a proposed static drawing hook, plus an example to demonstrate how it works.

You get direct access to the raw buffer right before it's rotated and drawn. This buffer is two dimensional, indexed X then Y and is the same size as the Scroll pHAT HD display. It represents the slice of the full buffer that is going to be drawn in that show() call.

My example is not very imaginative, but serves to demonstrate how it works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants