Skip to content

Commit

Permalink
formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
apal6981 committed Oct 31, 2024
1 parent 688fa17 commit 90cc792
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 26 deletions.
9 changes: 3 additions & 6 deletions display/physical_screen2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,16 @@ def _create_display(self):
# need to have an array of ip addresses if more panels
panel_array = [
[
SevenSegment(
ip_address="172.0.0.3",
brightness=self.brightness
)
SevenSegment(ip_address="172.0.0.3", brightness=self.brightness)
for j in range(self.num_segs_across)
]
for i in range(self.num_segs_down)
]

self.display = Display(
panel_array,
self.num_segs_across*16,
self.num_segs_down*6*2,
self.num_segs_across * 16,
self.num_segs_down * 6 * 2,
)

def _close_display(self):
Expand Down
46 changes: 27 additions & 19 deletions display/seven_seg2.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def __init__(
self.num_per_segment = 8
self.baudrate = baudrate if baudrate < 10000000 else 10000000
# self._buf = [0] * self.num_digits
self._command_buf = [0]*(2+self.num_segments)
self._buf = [0] *(2+ self.num_digits)
self._buf[0] = 0 # data
self._command_buf = [0] * (2 + self.num_segments)
self._buf = [0] * (2 + self.num_digits)
self._buf[0] = 0 # data
self._buf[1] = self.num_digits
self._display_buf = [0]*self.num_digits
self.addr = (ip_address,port)
self.panel_sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
self.commandSerializer = struct.Struct("B"*(self.num_segments+2))
self.dataSerialer = struct.Struct("B"*(self.num_digits+2))
self._display_buf = [0] * self.num_digits
self.addr = (ip_address, port)
self.panel_sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
self.commandSerializer = struct.Struct("B" * (self.num_segments + 2))
self.dataSerialer = struct.Struct("B" * (self.num_digits + 2))

# Setup the display
self.command(MAX7219_REG_SHUTDOWN, 1) # 1 enables the display
Expand All @@ -67,9 +67,14 @@ def __init__(
self.brightness(brightness)

# Set up cascaded segemtn orientation stuff to enable 2 functions
self.display = (
[[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]
) # [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]
self.display = [
[1, 2],
[3, 4],
[5, 6],
[7, 8],
[9, 10],
[11, 12],
] # [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]
self._display_y_len = len(self.display) if self.display is not None else None

self._flush_index = []
Expand All @@ -94,7 +99,7 @@ def command(self, register_num, value):
]:
raise ValueError(f"register_num is not a correct value: {register_num}")
# check value is good
if not isinstance(value, (int,list)):
if not isinstance(value, (int, list)):
raise ValueError(f"value is not a correct type: {type(value)}")
if type(value) == int and not (0 <= value < 16):
raise ValueError(f"value is not within bounds [1:15]: {value}")
Expand All @@ -103,7 +108,9 @@ def command(self, register_num, value):
# generate command buffer
self._command_buf[0] = register_num
self._command_buf[1] = self.num_segments
self._command_buf[2:] = value if type(value) == list else [value]*self.num_segments
self._command_buf[2:] = (
value if type(value) == list else [value] * self.num_segments
)
self._write_command()

def close(self, clear=True, shutdown=True):
Expand Down Expand Up @@ -140,7 +147,7 @@ def brightness(self, value):
value (int) or (list): brightness value to set
"""
# check value is good
if not isinstance(value, (int,list)):
if not isinstance(value, (int, list)):
raise ValueError(f"value is not a correct type: {type(value)}")
if type(value) == int and not (0 <= value < 16):
raise ValueError(f"value is not within bounds [1:15]: {value}")
Expand Down Expand Up @@ -194,7 +201,7 @@ def raw(self, position, value, flush=False):
# Check if char is int between 0 and 255
if not isinstance(value, (int)) or value < 0 or value > 255:
raise ValueError("value is either not an int or out of bounds (0-255)")
self._buf[position+2] = value
self._buf[position + 2] = value
# self._flush_index.append(position)

if flush:
Expand Down Expand Up @@ -228,7 +235,7 @@ def letter(self, position, char, dot=False, flush=False):
):
raise ValueError("position is not a valid number")
value = sy.get_char2(char) | (dot << 7)
self._buf[position+2] = value
self._buf[position + 2] = value
# self._flush_index.append(position)
if flush:
self.flush()
Expand Down Expand Up @@ -305,12 +312,13 @@ def text2(self, x, y, txt, horizontal=True, flush=False):

# Write data buffer to panel through socket
def _write_data(self):
self.panel_sock.sendto(self.dataSerialer.pack(*self._buf),self.addr)
self.panel_sock.sendto(self.dataSerialer.pack(*self._buf), self.addr)

# Write command buffer to panel through socket
def _write_command(self):
self.panel_sock.sendto(self.commandSerializer.pack(*self._command_buf),self.addr)

self.panel_sock.sendto(
self.commandSerializer.pack(*self._command_buf), self.addr
)

# Get position in the buffer for a given x,y coordinate
def _get_pos(self, x, y):
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def run_simulator():
)
def run_kiosk(simulate, newhardware, testing):
"""CLI command to run kiosk."""
kiosk.run(simulate, testing=testing,newhardware=newhardware)
kiosk.run(simulate, testing=testing, newhardware=newhardware)


@cli.command("demo")
Expand Down
1 change: 1 addition & 0 deletions runners/kiosk.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ def run(simulate, testing=False, newhardware=False):
from display.virtual_screen import ( # pylint: disable=import-outside-toplevel
VirtualScreen,
)

logger.debug("Starting virtual screen")
screen = VirtualScreen()
elif newhardware:
Expand Down

0 comments on commit 90cc792

Please sign in to comment.