Skip to content

Commit

Permalink
Add admin to show how to change personality.
Browse files Browse the repository at this point in the history
  • Loading branch information
teh committed Feb 4, 2015
1 parent 6421fb4 commit f51beb0
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
2 changes: 1 addition & 1 deletion sirius/coding/encoders.py
Expand Up @@ -126,7 +126,7 @@ def make(extra):

return make({
'binary_payload': base64.b64encode(_encode_printer_message(
0x2, payload, command_id)),
0x0102, payload, command_id)),
'device_address': command.device_address,
'type': 'DeviceCommand',
})
Expand Down
44 changes: 44 additions & 0 deletions sirius/web/admin.py
@@ -0,0 +1,44 @@
import io
from PIL import Image
import flask
from flask.ext import login

from sirius.protocol import protocol_loop
from sirius.protocol import messages
from sirius.coding import image_encoding


blueprint = flask.Blueprint('admin', __name__)


@blueprint.route('/admin/randomly-change-personality', methods=['GET', 'POST'])
def randomly_change_personality():
# Restrict to debug for now until we have a proper user management
# system.
assert flask.current_app.config['DEBUG'], "Debug not enabled"

im = image_encoding.threshold(Image.open('./tests/normalface.png'))

if flask.request.method == 'POST':
msg = messages.SetPersonality(
device_address='000d6f000273ce0b',
face_pixels=im,
nothing_to_print_pixels=im,
cannot_see_bridge_pixels=im,
cannot_see_internet_pixels=im,
)
success, next_print_id = protocol_loop.send_message(
'000d6f000273ce0b', msg)

if success:
flask.flash('Sent your message to the printer!')
else:
flask.flash(("Could not send message because the "
"printer {} is offline.").format('000d6f000273ce0b'),
'error')

return flask.redirect(flask.request.path)

return flask.render_template(
'admin.html',
)
6 changes: 5 additions & 1 deletion sirius/web/templates/admin.html
Expand Up @@ -4,4 +4,8 @@

{% block page_content %}
<h1>Admin!</h1>
{% endblock %}

<form method="post">
<button>change personality randomly</button>
</form>
{% endblock %}
1 change: 1 addition & 0 deletions sirius/web/templates/printer_overview.html
Expand Up @@ -11,6 +11,7 @@ <h1>Printer {{ printer.name }}</h1>
printer_id=printer.id) }}">
Print a thing
</a>

<h2>Messages</h2>
{% for m in messages %}
<div>
Expand Down
2 changes: 2 additions & 0 deletions sirius/web/webapp.py
Expand Up @@ -25,6 +25,7 @@
from sirius.web import landing
from sirius.web import twitter
from sirius.web import login
from sirius.web import admin
from sirius.web import printer_print
from sirius.web import printer_overview

Expand Down Expand Up @@ -52,6 +53,7 @@ def create_app(config_name):
app.register_blueprint(twitter.blueprint)
app.register_blueprint(printer_overview.blueprint)
app.register_blueprint(printer_print.blueprint)
app.register_blueprint(admin.blueprint)

# Live interactions.
gevent.spawn(protocol_loop.mark_dead_loop)
Expand Down
Binary file added tests/normalface.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit f51beb0

Please sign in to comment.