add scroll up/down flipper zero
This commit is contained in:
@@ -5,9 +5,12 @@ from dataclasses import dataclass
|
||||
from enum import Enum
|
||||
import socket
|
||||
import os
|
||||
import logging
|
||||
|
||||
from .protocol import Page, PageType
|
||||
|
||||
_logger = logging.getLogger("obd2_client.pages")
|
||||
|
||||
|
||||
class ActionID(Enum):
|
||||
"""Action identifiers for menu items."""
|
||||
@@ -31,7 +34,7 @@ class PageDefinition:
|
||||
class PageManager:
|
||||
"""Manages page content and navigation."""
|
||||
|
||||
MAX_VISIBLE_LINES = 5 # Flipper display limit
|
||||
MAX_VISIBLE_LINES = 4 # Flipper display limit (5 lines overlap with footer)
|
||||
|
||||
def __init__(self):
|
||||
self._pages: List[PageDefinition] = []
|
||||
@@ -170,16 +173,21 @@ class PageManager:
|
||||
True if scroll occurred
|
||||
"""
|
||||
if self._current_index not in range(len(self._pages)):
|
||||
_logger.debug(f"scroll_up: invalid page index {self._current_index}")
|
||||
return False
|
||||
|
||||
page_def = self._pages[self._current_index]
|
||||
if page_def.page_type != PageType.INFO:
|
||||
_logger.debug(f"scroll_up: page type is {page_def.page_type}, not INFO")
|
||||
return False
|
||||
|
||||
current_offset = self._scroll_offsets.get(self._current_index, 0)
|
||||
_logger.debug(f"scroll_up: current_offset={current_offset}")
|
||||
if current_offset > 0:
|
||||
self._scroll_offsets[self._current_index] = current_offset - 1
|
||||
_logger.debug(f"scroll_up: new offset={current_offset - 1}")
|
||||
return True
|
||||
_logger.debug("scroll_up: already at top")
|
||||
return False
|
||||
|
||||
def scroll_down(self) -> bool:
|
||||
@@ -189,20 +197,27 @@ class PageManager:
|
||||
True if scroll occurred
|
||||
"""
|
||||
if self._current_index not in range(len(self._pages)):
|
||||
_logger.debug(f"scroll_down: invalid page index {self._current_index}")
|
||||
return False
|
||||
|
||||
page_def = self._pages[self._current_index]
|
||||
if page_def.page_type != PageType.INFO:
|
||||
_logger.debug(f"scroll_down: page type is {page_def.page_type}, not INFO")
|
||||
return False
|
||||
|
||||
# Get full page content to know total lines
|
||||
page = page_def.generator(self)
|
||||
max_offset = max(0, len(page.lines) - self.MAX_VISIBLE_LINES)
|
||||
total_lines = len(page.lines)
|
||||
max_offset = max(0, total_lines - self.MAX_VISIBLE_LINES)
|
||||
|
||||
current_offset = self._scroll_offsets.get(self._current_index, 0)
|
||||
_logger.debug(f"scroll_down: total_lines={total_lines}, max_offset={max_offset}, current_offset={current_offset}")
|
||||
|
||||
if current_offset < max_offset:
|
||||
self._scroll_offsets[self._current_index] = current_offset + 1
|
||||
_logger.debug(f"scroll_down: new offset={current_offset + 1}")
|
||||
return True
|
||||
_logger.debug("scroll_down: already at bottom")
|
||||
return False
|
||||
|
||||
def navigate_next(self) -> bool:
|
||||
@@ -318,6 +333,7 @@ class PageManager:
|
||||
if state:
|
||||
# Get all values - returns dict of PID -> PIDValue
|
||||
all_values = state.get_all()
|
||||
_logger.debug(f"Live data: got {len(all_values)} PIDs from state")
|
||||
|
||||
if all_values:
|
||||
# Priority order for display
|
||||
@@ -339,8 +355,9 @@ class PageManager:
|
||||
if not lines:
|
||||
lines = ["Waiting for data...", "", "Polling active"]
|
||||
else:
|
||||
lines = ["No connection", "to OBD2", "", "Use Actions menu", "to reconnect"]
|
||||
lines = ["No OBD2 connection", "", "Use Actions menu", "to reconnect"]
|
||||
|
||||
_logger.debug(f"Live data page: {len(lines)} lines")
|
||||
return Page(PageType.INFO, "Live Data", lines)
|
||||
|
||||
def _generate_stats_page(self, mgr: "PageManager") -> Page:
|
||||
|
||||
Reference in New Issue
Block a user