Skip to content

Commit

Permalink
Merge pull request #441 from tadeubas/fix-qrcode-progress
Browse files Browse the repository at this point in the history
Fix some issues with qrcode progress
  • Loading branch information
odudex authored Aug 12, 2024
2 parents 19f99ec + 96983bf commit b9e840f
Show file tree
Hide file tree
Showing 23 changed files with 138 additions and 116 deletions.
1 change: 0 additions & 1 deletion i18n/translations/de-DE.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Helligkeit",
"Buttons": "Tasten",
"Buttons Debounce": "Entprellung der Tasten",
"Calculating Shannon's entropy": "Berechnung der Shannon-Entropie",
"Capture cancelled": "Aufnahme abgebrochen",
"Change": "Change Adresse",
"Change Addresses": "Change Adressen",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/es-MX.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Brillo",
"Buttons": "Botones",
"Buttons Debounce": "Rebote de Botones",
"Calculating Shannon's entropy": "Cálculo de la entropía de Shannon",
"Capture cancelled": "Captura cancelada",
"Change": "Cambio",
"Change Addresses": "Direcciones de Cambio",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Luminosité",
"Buttons": "Boutons",
"Buttons Debounce": "Anti-rebond des boutons",
"Calculating Shannon's entropy": "Calcul de l'entropie de Shannon",
"Capture cancelled": "Capture annulée",
"Change": "Changement",
"Change Addresses": "Adresses de Changement",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/nl-NL.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Helderheid",
"Buttons": "Knoppen",
"Buttons Debounce": "Debounce van knoppen",
"Calculating Shannon's entropy": "Shannon's entropie berekenen",
"Capture cancelled": "Opname geannuleerd",
"Change": "Change",
"Change Addresses": "Wisselgeldadres",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/pl-PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Jasność",
"Buttons": "Przyciski",
"Buttons Debounce": "Debouncing przycisków",
"Calculating Shannon's entropy": "Obliczanie entropii Shannona",
"Capture cancelled": "Anulowano przechwytywanie",
"Change": "Zmiana",
"Change Addresses": "Zmień adresy",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/pt-BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Brilho",
"Buttons": "Botões",
"Buttons Debounce": "Debounce dos Botões",
"Calculating Shannon's entropy": "Calculando a entropia de Shannon",
"Capture cancelled": "Captura cancelada",
"Change": "Troco",
"Change Addresses": "Endereços de Troco",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/ru-RU.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Яркость",
"Buttons": "Кнопки",
"Buttons Debounce": "Антидребезг кнопок",
"Calculating Shannon's entropy": "Вычисление энтропии Шеннона",
"Capture cancelled": "Захват отменен",
"Change": "Сдача",
"Change Addresses": "Адрес Сдачи",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/tr-TR.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Parlaklık",
"Buttons": "Butonlar",
"Buttons Debounce": "Buton Geri-sekmesi",
"Calculating Shannon's entropy": "Shannon entropisi hesaplanıyor",
"Capture cancelled": "Yakalama iptal edildi",
"Change": "Para Üstü",
"Change Addresses": "Para Üstü Adresleri",
Expand Down
1 change: 0 additions & 1 deletion i18n/translations/vi-VN.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"Brightness": "Độ sáng",
"Buttons": "Nút",
"Buttons Debounce": "Loại bỏ nhiễu nút",
"Calculating Shannon's entropy": "Đang tính toán entropy của Shannon",
"Capture cancelled": "Hủy chụp hình",
"Change": "Thay đổi",
"Change Addresses": "Các địa chỉ tiền thối",
Expand Down
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pytest-mock = "^3.14.0"
PyQRCode = "^1.2.1"
pycryptodome = "^3.17.0"
poethepoet = "^0.24.4"
dill = "^0.3.8"

[tool.poetry.extras]
docs = ["mkdocs", "mkdocs-material", "mkdocs-static-i18n", "pymdown-extensions"]
Expand Down
6 changes: 3 additions & 3 deletions src/krux/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ def __init__(self):
self.initialized = False
self.cam_id = None
self.antiglare_enabled = False
self.initialize_sensor()
self._initialize_sensor()

def initialize_sensor(self, grayscale=False):
def _initialize_sensor(self, grayscale=False):
"""Initializes the camera"""
self.initialized = False
self.antiglare_enabled = False
Expand Down Expand Up @@ -191,7 +191,7 @@ def snapshot(self):

def initialize_run(self):
"""Initializes and runs sensor"""
self.initialize_sensor()
self._initialize_sensor()
sensor.run(1)

def stop_sensor(self):
Expand Down
27 changes: 22 additions & 5 deletions src/krux/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class Display:
"""Display is a singleton interface for interacting with the device's display"""

def __init__(self):
self.portrait = True
self.portrait = False
if board.config["type"] == "amigo":
self.flipped_x_coordinates = (
Settings().hardware.display.flipped_x_coordinates
Expand Down Expand Up @@ -224,13 +224,15 @@ def qr_data_width(self):

def to_landscape(self):
"""Changes the rotation of the display to landscape"""
lcd.rotation(LANDSCAPE)
self.portrait = False
if self.portrait:
lcd.rotation(LANDSCAPE)
self.portrait = False

def to_portrait(self):
"""Changes the rotation of the display to portrait"""
lcd.rotation(PORTRAIT)
self.portrait = True
if not self.portrait:
lcd.rotation(PORTRAIT)
self.portrait = True

def to_lines(self, text, max_lines=None):
"""Takes a string of text and converts it to lines to display on
Expand Down Expand Up @@ -410,5 +412,20 @@ def max_menu_lines(self, line_offset=STATUS_BAR_HEIGHT):
"""Maximum menu items the display can fit"""
return (self.height() - line_offset) // (2 * FONT_HEIGHT)

def render_image(self, img):
"""Renders the image based on the board type."""
board_type = board.config["type"]

if board_type == "m5stickv":
img.lens_corr(strength=1.0, zoom=0.56)
lcd.display(img, oft=(0, 0), roi=(68, 52, 185, 135))
elif board_type == "amigo":
x_offset = 40 if self.flipped_x_coordinates else 120
lcd.display(img, oft=(x_offset, 40))
elif board_type == "cube":
lcd.display(img, oft=(0, 0), roi=(0, 0, 224, 240))
else:
lcd.display(img, oft=(0, 0), roi=(0, 0, 304, 240))


display = Display()
14 changes: 9 additions & 5 deletions src/krux/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,18 @@ def enter_event(self):

def page_event(self):
"""Intermediary method to pull button PAGE event"""
event_val = False
if self.page is not None:
return self.page.event()
return False
event_val = self.page.event()
if board.config["type"] == "yahboom":
event_val = event_val or self.page_prev_event(check_yahboom=True)
return event_val

def page_prev_event(self):
def page_prev_event(self, check_yahboom=False):
"""Intermediary method to pull button PAGE_PREV event"""
if self.page_prev is not None:
return self.page_prev.event()
if board.config["type"] != "yahboom" or check_yahboom:
if self.page_prev is not None:
return self.page_prev.event()
return False

def touch_event(self):
Expand Down
1 change: 1 addition & 0 deletions src/krux/pages/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,7 @@ def _clicked_item(self, selected_item_index):
if status != MENU_CONTINUE:
return status
except Exception as e:
self.ctx.display.to_portrait()
self.ctx.display.clear()
self.ctx.display.draw_centered_text(
t("Error:") + "\n%s" % repr(e), theme.error_color
Expand Down
39 changes: 13 additions & 26 deletions src/krux/pages/capture_entropy.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.

import lcd
import board
import math
from ..display import FONT_HEIGHT, BOTTOM_LINE, BOTTOM_PROMPT_LINE
Expand All @@ -41,22 +40,6 @@ def __init__(self, ctx):
super().__init__(ctx, None)
self.ctx = ctx

def display_image(self, img):
"""Displays the image based on the board type."""
board_type = board.config["type"]

if board_type == "m5stickv":
img.lens_corr(strength=1.0, zoom=0.56)
lcd.display(img, oft=(0, 0), roi=(68, 52, 185, 135))
elif board_type == "amigo":
# Offset x = 480 - 320 - 40 = 120 if not flipped
oft_x = 40 if self.ctx.display.flipped_x_coordinates else 120
lcd.display(img, oft=(oft_x, 40))
elif board_type == "cube":
lcd.display(img, oft=(0, 0), roi=(0, 0, 220, 240))
else:
lcd.display(img, oft=(0, 0), roi=(0, 0, 304, 240))

def _callback(self):
"""
Returns PROCEED if user pressed ENTER or touched the screen,
Expand Down Expand Up @@ -90,25 +73,35 @@ def capture(self, show_entropy_details=True):
self.ctx.display.clear()
self.ctx.display.draw_centered_text(t("TOUCH or ENTER to capture"))
self.ctx.display.to_landscape()
self.ctx.camera.initialize_sensor()
sensor.run(1)
self.ctx.camera.initialize_run()
self.ctx.display.clear()

command = 0
y_label_offset = BOTTOM_LINE
if board.config["type"] == "amigo":
y_label_offset = BOTTOM_PROMPT_LINE

# Flush events ocurred while loading camera
self.ctx.input.reset_ios_state()
while True:
wdt.feed()

self.ctx.display.to_landscape()
img = sensor.snapshot()
self.ctx.display.render_image(img)

stdev_index = self.rms_value(
[
img.get_statistics().l_stdev(),
img.get_statistics().a_stdev(),
img.get_statistics().b_stdev(),
]
)

command = self._callback()
if command != NOT_PRESSED:
break

self.ctx.display.to_portrait()
self.ctx.display.fill_rectangle(
0,
Expand All @@ -129,12 +122,6 @@ def capture(self, show_entropy_details=True):
self.ctx.display.draw_hcentered_text(
t("Insufficient entropy"), y_label_offset, theme.error_color
)
self.ctx.display.to_landscape()
command = self._callback()
if command != NOT_PRESSED:
break

self.display_image(img)

self.ctx.display.to_portrait()
gc.collect()
Expand All @@ -145,7 +132,7 @@ def capture(self, show_entropy_details=True):
self.flash_text(t("Capture cancelled"))
return None

self.ctx.display.draw_centered_text(t("Calculating Shannon's entropy"))
self.ctx.display.draw_centered_text(t("Processing ..."))

img_bytes = img.to_bytes()
img_pixels = img.width() * img.height()
Expand Down
Loading

0 comments on commit b9e840f

Please sign in to comment.