Skip to content

Commit

Permalink
Display is now correctly updated with fixed fps.
Browse files Browse the repository at this point in the history
  • Loading branch information
MKesenheimer authored and MKesenheimer committed Apr 6, 2023
1 parent 544314b commit 92534f8
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions pwnagotchi/ui/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def __init__(self, config, impl, state=None):
self._config = config
self._canvas = None
self._frozen = False
self._lasttime = time.time()
self._lock = Lock()
self._voice = Voice(lang=config['main']['lang'])
self._implementation = impl
Expand Down Expand Up @@ -360,6 +361,15 @@ def on_custom(self, text):
self.set('status', self._voice.custom(text))
self.update()

def check_display_update(self):
now = time.time()
timedif = now - self._lasttime
delay = 1.0 / self._config['ui']['fps']
if timedif < delay:
return False
self._lasttime = now
return True

def update(self, force=False, new_data={}):
for key, val in new_data.items():
self.set(key, val)
Expand All @@ -381,7 +391,8 @@ def update(self, force=False, new_data={}):

web.update_frame(self._canvas)

for cb in self._render_cbs:
cb(self._canvas)
if self.check_display_update():
for cb in self._render_cbs:
cb(self._canvas)

self._state.reset()

0 comments on commit 92534f8

Please sign in to comment.