Fix Scroll() buffer manipulation for mirrored display
This commit is contained in:
@@ -92,7 +92,6 @@ class Display(object):
|
||||
if Immediate == True:
|
||||
self.np.write()
|
||||
except KeyError:
|
||||
#print("No such word")
|
||||
pass
|
||||
|
||||
def WriteSentence(self,sentence,color=(25,25,0)):
|
||||
@@ -102,50 +101,43 @@ class Display(object):
|
||||
self.np.write()
|
||||
|
||||
def Scroll(self,Direction,Fill=[(0,0,0)]*16):
|
||||
"""Optimized scroll using direct buffer manipulation for all directions."""
|
||||
"""Optimized scroll for horizontally mirrored display (NeoPixel 0 at top-right)."""
|
||||
newbuf=bytearray(b'')
|
||||
|
||||
if Direction == 'l':
|
||||
# Optimized left scroll - existing implementation
|
||||
for Row in range(0,self.Rows,2):
|
||||
newbuf += self.np.buf[Row*16*3+3:Row*16*3+48]
|
||||
newbuf+=bytearray([Fill[Row][1],Fill[Row][0],Fill[Row][2]])
|
||||
newbuf += bytearray([Fill[Row][1],Fill[Row][0],Fill[Row][2]])
|
||||
newbuf += bytearray([Fill[Row+1][1],Fill[Row+1][0],Fill[Row+1][2]])
|
||||
newbuf += self.np.buf[Row*16*3+48:Row*16*3+93]
|
||||
self.np.buf=newbuf
|
||||
|
||||
elif Direction == 'r':
|
||||
# Optimized right scroll using buffer manipulation
|
||||
for Row in range(0,self.Rows,2):
|
||||
# Add fill pixels at the start
|
||||
newbuf += bytearray([Fill[Row][1],Fill[Row][0],Fill[Row][2]])
|
||||
newbuf += bytearray([Fill[Row+1][1],Fill[Row+1][0],Fill[Row+1][2]])
|
||||
# Copy existing pixels (minus the last one from each row)
|
||||
newbuf += self.np.buf[Row*16*3:Row*16*3+45]
|
||||
newbuf += self.np.buf[Row*16*3+48:Row*16*3+93]
|
||||
newbuf += self.np.buf[Row*16*3+51:Row*16*3+96]
|
||||
newbuf += bytearray([Fill[Row+1][1],Fill[Row+1][0],Fill[Row+1][2]])
|
||||
self.np.buf=newbuf
|
||||
|
||||
elif Direction == 'u':
|
||||
# Optimized up scroll - skip first row, add fill at bottom
|
||||
newbuf = self.np.buf[self.Columns*3:] # Skip first row
|
||||
newbuf = self.np.buf[self.Columns*3:]
|
||||
for Col in range(self.Columns):
|
||||
color = Fill[Col]
|
||||
newbuf += bytearray([color[1], color[0], color[2]])
|
||||
self.np.buf = newbuf
|
||||
|
||||
elif Direction == 'd':
|
||||
# Optimized down scroll - add fill at top, skip last row
|
||||
for Col in range(self.Columns):
|
||||
color = Fill[Col]
|
||||
newbuf += bytearray([color[1], color[0], color[2]])
|
||||
newbuf += self.np.buf[:-self.Columns*3] # Skip last row
|
||||
newbuf += self.np.buf[:-self.Columns*3]
|
||||
self.np.buf = newbuf
|
||||
|
||||
self.np.write()
|
||||
|
||||
def ScrollLetter(self,Direction,Text,Speed,Color=[(50,50,50)],BGColor=[(0,0,0)]):
|
||||
"""Optimized letter scrolling with pre-calculated columns."""
|
||||
# Pre-calculate all columns for all letters
|
||||
all_columns = []
|
||||
for index,Letter in enumerate(Text):
|
||||
for X in range(3,14):
|
||||
@@ -155,7 +147,6 @@ class Display(object):
|
||||
BGColor[index % len(BGColor)])
|
||||
)
|
||||
|
||||
# Now scroll with pre-calculated data
|
||||
for column in all_columns:
|
||||
self.Scroll(Direction, column)
|
||||
sleep(Speed)
|
||||
@@ -171,9 +162,9 @@ class Display(object):
|
||||
NeoPixel 0 is at top-right, serpentine wiring pattern."""
|
||||
Row=self.Num2Row(Pos)
|
||||
Col=self.Num2Column(Pos)
|
||||
if Row%2 == 0: # Even rows go right-to-left (mirrored from original)
|
||||
if Row%2 == 0:
|
||||
NewPos=Row*self.Columns+(self.Columns-1-Col)
|
||||
else: # Odd rows go left-to-right
|
||||
else:
|
||||
NewPos=Pos
|
||||
return NewPos
|
||||
|
||||
|
||||
Reference in New Issue
Block a user