MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / initialize_variables

Method initialize_variables

shared.py:1123–1195  ·  view source on GitHub ↗

Initialize the variables.

(self)

Source from the content-addressed store, hash-verified

1121 test_img = Image.new('1', (self.width, self.height), 255)
1122 test_buf = self.epd_helper.epd.getbuffer(test_img)
1123 expected_size = int(self.width / 8) * self.height
1124 if len(test_buf) < expected_size:
1125 raise ValueError(f"Buffer size mismatch: got {len(test_buf)}, expected {expected_size}")
1126 except Exception as ve:
1127 logger.warning(f"EPD driver '{epd_type}' buffer validation failed: {ve}, trying auto-detect...")
1128 raise # Fall through to the auto-detect fallback below
1129
1130 logger.info(f"EPD {self.config['epd_type']} initialized with size: {self.width}x{self.height}")
1131 except Exception as e:
1132 logger.error(f"Error initializing EPD display: {e}")
1133 # Try auto-detection as fallback before giving up
1134 logger.info("Attempting auto-detection as fallback...")
1135 try:
1136 result = EPDHelper.auto_detect()
1137 if result:
1138 epd_type = result[0]
1139 logger.info(f"Fallback auto-detected EPD: {epd_type} ({result[1]}x{result[2]})")
1140 self.config['epd_type'] = epd_type
1141 self.apply_display_profile(epd_type)
1142 self.epd_helper = EPDHelper(epd_type)
1143 self.epd_helper.init_full_update()
1144 self.width, self.height = self.epd_helper.epd.width, self.epd_helper.epd.height
1145 self.screen_reversed = normalize_rotation(self.config.get("screen_reversed", 0))
1146 self.web_screen_reversed = 0
1147 self.save_config()
1148 logger.info(f"EPD {epd_type} initialized via fallback with size: {self.width}x{self.height}")
1149 return
1150 except Exception as e2:
1151 logger.error(f"Fallback auto-detection also failed: {e2}")
1152 logger.warning("Continuing without EPD display support")
1153 self.epd_helper = None
1154 fallback_profile = DISPLAY_PROFILES.get(DEFAULT_EPD_TYPE, {"ref_width": 122, "ref_height": 250, "default_flip": False})
1155 epd_type = self.config.get('epd_type') or DEFAULT_EPD_TYPE
1156 profile = DISPLAY_PROFILES.get(epd_type, fallback_profile) or fallback_profile
1157 self.width = self.config.get('ref_width', profile['ref_width'])
1158 self.height = self.config.get('ref_height', profile['ref_height'])
1159 self.screen_reversed = normalize_rotation(self.config.get('screen_reversed', 0))
1160 self.web_screen_reversed = 0
1161
1162 # NOTE: Test image code below was used to verify EPD hardware.
1163 # Commented out to allow normal Ragnar display to show.
1164 # Uncomment if you need to test the display again.
1165 # from PIL import ImageDraw
1166 # test_image = Image.new('1', (self.width, self.height), 255)
1167 # draw = ImageDraw.Draw(test_image)
1168 # draw.text((10, 10), "EPD Test", fill=0)
1169 # if self.config.get("reversed", False):
1170 # test_image = test_image.rotate(180)
1171 # self.epd_helper.epd.display(self.epd_helper.epd.getbuffer(test_image))
1172 # logger.info("Test image displayed on EPD.")
1173
1174 def initialize_variables(self):
1175 """Initialize the variables."""
1176 self.should_exit = False
1177 self.display_should_exit = False
1178 self.orchestrator_should_exit = False
1179 self.webapp_should_exit = False
1180 self.web_portal_active = True # Tracks whether the web portal is currently running

Callers 1

__init__Method · 0.95

Calls 1

_seed_counts_from_dbMethod · 0.95

Tested by

no test coverage detected