diff --git a/scripts/language.sh b/scripts/language.sh index c56b7847..cf653f50 100755 --- a/scripts/language.sh +++ b/scripts/language.sh @@ -55,6 +55,7 @@ function update_lang() { msgmerge --update "$LOCALE_DIR/$1/LC_MESSAGES/voice.po" "$LOCALE_DIR/voice.pot" } + case "$1" in add) add_lang "$2" diff --git a/scripts/preview.py b/scripts/preview.py new file mode 100755 index 00000000..47afd7d3 --- /dev/null +++ b/scripts/preview.py @@ -0,0 +1,157 @@ +#!/usr/bin/env python3 + +import sys +import os +import time +import argparse +import random +from http.server import HTTPServer +import shutil +import yaml +sys.path.insert(0, + os.path.join(os.path.dirname(os.path.realpath(__file__)), + '../sdcard/rootfs/root/pwnagotchi/scripts/')) + +from pwnagotchi.ui.view import View +from pwnagotchi.ui.display import Display, VideoHandler +import core + +class CustomDisplay(Display): + + def _http_serve(self): + if self._video_address is not None: + self._httpd = HTTPServer((self._video_address, self._video_port), + CustomVideoHandler) + core.log("ui available at http://%s:%d/" % (self._video_address, + self._video_port)) + self._httpd.serve_forever() + else: + core.log("could not get ip of usb0, video server not starting") + + + def _on_view_rendered(self, img): + CustomVideoHandler.render(img) + + if self._enabled: + self.canvas = (img if self._rotation == 0 else img.rotate(self._rotation)) + if self._render_cb is not None: + self._render_cb() + + +class CustomVideoHandler(VideoHandler): + + @staticmethod + def render(img): + with CustomVideoHandler._lock: + img.save("/tmp/pwnagotchi-{rand}.png".format(rand=id(CustomVideoHandler)), format='PNG') + + def do_GET(self): + if self.path == '/': + self.send_response(200) + self.send_header('Content-type', 'text/html') + self.end_headers() + try: + self.wfile.write( + bytes( + self._index % + ('localhost', 1000), "utf8")) + except BaseException: + pass + + elif self.path.startswith('/ui'): + with self._lock: + self.send_response(200) + self.send_header('Content-type', 'image/png') + self.end_headers() + try: + with open("/tmp/pwnagotchi-{rand}.png".format(rand=id(CustomVideoHandler)), 'rb') as fp: + shutil.copyfileobj(fp, self.wfile) + except BaseException: + pass + else: + self.send_response(404) + + +class DummyPeer: + @staticmethod + def name(): + return "beta" + + +def main(): + parser = argparse.ArgumentParser(description="This program emulates\ + the pwnagotchi display") + parser.add_argument('--display', help="Which display to use.", + default="waveshare_2") + parser.add_argument('--port', help="Which port to use", + default=8080) + parser.add_argument('--sleep', type=int, help="Time between emotions", + default=2) + parser.add_argument('--lang', help="Language to use", + default="en") + args = parser.parse_args() + + CONFIG = yaml.load(''' + main: + lang: {lang} + ui: + fps: 0.3 + display: + enabled: false + rotation: 180 + color: black + refresh: 30 + type: {display} + video: + enabled: true + address: "127.0.0.1" + port: {port} + '''.format(display=args.display, + port=args.port, + lang=args.lang), + Loader=yaml.FullLoader) + + DISPLAY = CustomDisplay(config=CONFIG, state={'name': '%s>' % 'preview'}) + + while True: + DISPLAY.on_starting() + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_ai_ready() + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_normal() + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_new_peer(DummyPeer()) + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_lost_peer(DummyPeer()) + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_free_channel('6') + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.wait(args.sleep) + DISPLAY.update() + DISPLAY.on_bored() + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_sad() + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_motivated(1) + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_demotivated(-1) + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_excited() + DISPLAY.update() + time.sleep(args.sleep) + DISPLAY.on_deauth({'mac': 'DE:AD:BE:EF:CA:FE'}) + DISPLAY.update() + + +if __name__ == '__main__': + SystemExit(main())