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

QR Encoder refactor + fountain encoder restart() #494

Merged
merged 8 commits into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions src/seedsigner/gui/screens/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from seedsigner.gui.keyboard import Keyboard, TextEntryDisplay
from seedsigner.gui.renderer import Renderer
from seedsigner.hardware.buttons import HardwareButtonsConstants, HardwareButtons
from seedsigner.models.encode_qr import BaseQrEncoder
from seedsigner.models.settings import SettingsConstants
from seedsigner.models.threads import BaseThread, ThreadsafeCounter

Expand Down Expand Up @@ -657,10 +658,10 @@ def swap_selected_button(new_selected_button: int):

@dataclass
class QRDisplayScreen(BaseScreen):
qr_encoder: 'EncodeQR' = None
qr_encoder: BaseQrEncoder = None

class QRDisplayThread(BaseThread):
def __init__(self, qr_encoder: 'EncodeQR', qr_brightness: ThreadsafeCounter, renderer: Renderer,
def __init__(self, qr_encoder: BaseQrEncoder, qr_brightness: ThreadsafeCounter, renderer: Renderer,
tips_start_time: ThreadsafeCounter):
super().__init__()
self.qr_encoder = qr_encoder
Expand Down
13 changes: 12 additions & 1 deletion src/seedsigner/helpers/ur2/fountain_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def __init__(self, message, max_fragment_len, first_seq_num = 0, min_fragment_le
self.fragment_len = FountainEncoder.find_nominal_fragment_length(self.message_len, min_fragment_len, max_fragment_len)
self.fragments = FountainEncoder.partition_message(message, self.fragment_len)
self.seq_num = first_seq_num
self.current_part: Part = None

@staticmethod
def find_nominal_fragment_length(message_len, min_fragment_len, max_fragment_len):
Expand Down Expand Up @@ -143,7 +144,17 @@ def next_part(self):
indexes = choose_fragments(self.seq_num, self.seq_len(), self.checksum)
mixed = self.mix(indexes)
data = bytes(mixed)
return Part(self.seq_num, self.seq_len(), self.message_len, self.checksum, data)
self.current_part = Part(self.seq_num, self.seq_len(), self.message_len, self.checksum, data)
return self.current_part


def restart(self):
"""
Restart from the beginning; each cycle's first n frames are full data frames
(not XOR composites).
"""
self.seq_num = 0


def mix(self, indexes):
result = [0] * self.fragment_len
Expand Down
18 changes: 16 additions & 2 deletions src/seedsigner/helpers/ur2/ur_encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,26 @@ def is_complete(self):
def is_single_part(self):
return self.fountain_encoder.is_single_part()

def next_part(self):
part = self.fountain_encoder.next_part()
def next_part(self) -> str:
if self.is_single_part():
return UREncoder.encode(self.ur)
else:
part = self.fountain_encoder.next_part()
return UREncoder.encode_part(self.ur.type, part)

def current_part(self) -> str:
if self.is_single_part():
return UREncoder.encode(self.ur)
else:
part = self.fountain_encoder.current_part
if not part:
part = self.fountain_encoder.next_part()
return UREncoder.encode_part(self.ur.type, part)


def restart(self):
self.fountain_encoder.restart()


@staticmethod
def encode_part(type, part):
Expand Down
Loading
Loading