new: added clean shutdown button to the web ui (closes #161)
This commit is contained in:
parent
0577972867
commit
4f694ddb83
@ -1,4 +1,8 @@
|
||||
import subprocess
|
||||
import os
|
||||
import logging
|
||||
import time
|
||||
import pwnagotchi.ui.view as view
|
||||
|
||||
version = '1.0.0a'
|
||||
|
||||
@ -46,3 +50,13 @@ def temperature(celsius=True):
|
||||
temp = int(fp.read().strip())
|
||||
c = int(temp / 1000)
|
||||
return c if celsius else ((c * (9 / 5)) + 32)
|
||||
|
||||
|
||||
def shutdown():
|
||||
logging.warning("shutting down ...")
|
||||
if view.ROOT:
|
||||
view.ROOT.on_shutdown()
|
||||
# give it some time to refresh the ui
|
||||
time.sleep(5)
|
||||
os.system("sync")
|
||||
os.system("halt")
|
||||
|
@ -15,11 +15,29 @@ class VideoHandler(BaseHTTPRequestHandler):
|
||||
_lock = Lock()
|
||||
_index = """<html>
|
||||
<head>
|
||||
<title>%s</title>
|
||||
<title>%s</title>
|
||||
<style>
|
||||
.block {
|
||||
-webkit-appearance: button;
|
||||
-moz-appearance: button;
|
||||
appearance: button;
|
||||
|
||||
display: block;
|
||||
cursor: pointer;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<img src="/ui" id="ui"/>
|
||||
|
||||
<div style="position: absolute; top:0; left:0; width:100%%;">
|
||||
<img src="/ui" id="ui" style="width:100%%"/>
|
||||
<br/>
|
||||
<hr/>
|
||||
<form action="/shutdown" onsubmit="return confirm('This will halt the unit, continue?');">
|
||||
<input type="submit" class="block" value="Shutdown"/>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
window.onload = function() {
|
||||
var image = document.getElementById("ui");
|
||||
@ -50,6 +68,9 @@ class VideoHandler(BaseHTTPRequestHandler):
|
||||
except:
|
||||
pass
|
||||
|
||||
elif self.path.startswith('/shutdown'):
|
||||
pwnagotchi.shutdown()
|
||||
|
||||
elif self.path.startswith('/ui'):
|
||||
with self._lock:
|
||||
self.send_response(200)
|
||||
|
@ -15,7 +15,7 @@ from pwnagotchi.ui.state import State
|
||||
|
||||
WHITE = 0xff
|
||||
BLACK = 0x00
|
||||
|
||||
ROOT = None
|
||||
|
||||
def setup_display_specifics(config):
|
||||
width = 0
|
||||
@ -57,9 +57,12 @@ def setup_display_specifics(config):
|
||||
|
||||
class View(object):
|
||||
def __init__(self, config, state={}):
|
||||
global ROOT
|
||||
|
||||
self._render_cbs = []
|
||||
self._config = config
|
||||
self._canvas = None
|
||||
self._frozen = False
|
||||
self._lock = Lock()
|
||||
self._voice = Voice(lang=config['main']['lang'])
|
||||
|
||||
@ -119,6 +122,8 @@ class View(object):
|
||||
logging.warning("ui.fps is 0, the display will only update for major changes")
|
||||
self._ignore_changes = ('uptime', 'name')
|
||||
|
||||
ROOT = self
|
||||
|
||||
def add_element(self, key, elem):
|
||||
self._state.add_element(key, elem)
|
||||
|
||||
@ -261,6 +266,12 @@ class View(object):
|
||||
|
||||
self.on_normal()
|
||||
|
||||
def on_shutdown(self):
|
||||
self.set('face', faces.SLEEP)
|
||||
self.set('status', self._voice.on_shutdown())
|
||||
self.update(force=True)
|
||||
self._frozen = True
|
||||
|
||||
def on_bored(self):
|
||||
self.set('face', faces.BORED)
|
||||
self.set('status', self._voice.on_bored())
|
||||
@ -323,6 +334,9 @@ class View(object):
|
||||
|
||||
def update(self, force=False):
|
||||
with self._lock:
|
||||
if self._frozen:
|
||||
return
|
||||
|
||||
changes = self._state.changes(ignore=self._ignore_changes)
|
||||
if force or len(changes):
|
||||
self._canvas = Image.new('1', (self._width, self._height), WHITE)
|
||||
|
@ -90,6 +90,11 @@ class Voice:
|
||||
self._('Zzzzz'),
|
||||
self._('ZzzZzzz ({secs}s)').format(secs=secs)])
|
||||
|
||||
def on_shutdown(self):
|
||||
return random.choice([
|
||||
self._('Good night.'),
|
||||
self._('Zzz')])
|
||||
|
||||
def on_awakening(self):
|
||||
return random.choice(['...', '!'])
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user