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

Class RagnarMenu

pager/pager_menu.py:125–429  ·  view source on GitHub ↗

Graphical startup menu for Ragnar on the Pager LCD.

Source from the content-addressed store, hash-verified

123
124
125class RagnarMenu:
126 """Graphical startup menu for Ragnar on the Pager LCD."""
127
128 def __init__(self, interfaces):
129 self.interfaces = interfaces
130 self.scan_prefix = 24
131 try:
132 config_path = os.path.join(PAYLOAD_DIR, 'config', 'shared_config.json')
133 with open(config_path, 'r') as f:
134 cfg = json.load(f)
135 self.scan_prefix = cfg.get('scan_network_prefix', 24)
136 except Exception:
137 pass
138 self.gfx = Pager()
139 self.gfx.init()
140 self.gfx.set_rotation(270) # Landscape 480x222
141 self.gfx.clear_input_events() # Flush stale events from service takeover
142
143 def cleanup(self):
144 if hasattr(self, 'gfx'):
145 try:
146 # Clear screen to black before releasing hardware so the
147 # display doesn't freeze on the last drawn frame while
148 # pineapplepager is restarting.
149 self.gfx.clear(Pager.BLACK)
150 self.gfx.flip()
151 except Exception:
152 pass
153 try:
154 self.gfx.cleanup()
155 except Exception:
156 pass
157
158 def _adjust_brightness(self, direction):
159 """Adjust screen brightness. direction: +1 or -1."""
160 cur = self.gfx.get_brightness()
161 max_br = self.gfx.get_max_brightness()
162 new = max(1, min(max_br, cur + direction))
163 if new != cur:
164 self.gfx.set_brightness(new)
165
166 def _wait_button(self):
167 """Wait for a button press using thread-safe event queue.
168 LEFT/RIGHT adjust brightness and are not returned to callers."""
169 while True:
170 event = self.gfx.get_input_event()
171 if event:
172 button, event_type, timestamp = event
173 if event_type == Pager.EVENT_PRESS:
174 if button == Pager.BTN_LEFT:
175 self._adjust_brightness(-1)
176 continue
177 if button == Pager.BTN_RIGHT:
178 self._adjust_brightness(1)
179 continue
180 if button == Pager.BTN_UP:
181 return 'UP'
182 if button == Pager.BTN_DOWN:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected