Skip to content

Commit

Permalink
do not show qr code if one is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
bdamokos committed Jan 16, 2025
1 parent b49adcc commit 7f84e1a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
28 changes: 7 additions & 21 deletions weather/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ def get_weather_data(self):

# Constants
MARGIN = 5
QR_SIZE = 52 # QR code size in pixels
qr_code_address = os.getenv("weather_mode_qr_code_address")
if qr_code_address:
QR_SIZE = 52 # QR code size in pixels
else:
QR_SIZE = 0
ICON_PADDING = 2 # Padding around icons

def draw_weather_display(epd, weather_data, last_weather_data=None, set_base_image=False):
Expand Down Expand Up @@ -581,7 +585,7 @@ def draw_weather_display(epd, weather_data, last_weather_data=None, set_base_ima
forecast_text, font=font_medium, fill=BLACK)

# Generate and draw QR code (larger size) or Raspberry Pi logo
qr_code_address = os.getenv("weather_mode_qr_code_address")

if qr_code_address:
qr = qrcode.QRCode(version=1, box_size=2, border=1)
qr.add_data(qr_code_address)
Expand All @@ -594,25 +598,7 @@ def draw_weather_display(epd, weather_data, last_weather_data=None, set_base_ima
qr_x = Himage.width - QR_SIZE - MARGIN
qr_y = MARGIN
Himage.paste(qr_img, (qr_x, qr_y))
else:
# Load and display Raspberry Pi logo instead
try:
logo_path = Path(__file__).parent / "icons" / "Brand raspberrypi.png"
logo_img = Image.open(logo_path)

# Calculate position to center the 46x46 logo in the QR code space
logo_x = Himage.width - QR_SIZE - MARGIN + (QR_SIZE - 46) // 2
logo_y = MARGIN + (QR_SIZE - 46) // 2

# Convert logo to match display mode if needed
if epd.is_bw_display:
logo_img = logo_img.convert('1')
else:
logo_img = logo_img.convert('RGB')

Himage.paste(logo_img, (logo_x, logo_y))
except Exception as e:
logger.error(f"Error loading Raspberry Pi logo: {e}")


# Draw time under QR code
current_time = datetime.now().strftime("%H:%M")
Expand Down
Binary file removed weather/icons/Brand raspberrypi.png
Binary file not shown.

0 comments on commit 7f84e1a

Please sign in to comment.