Management, update arduino, add initial webapp

This commit is contained in:
Piotr Dobrowolski 2017-09-09 23:44:49 +02:00
parent b6f4601972
commit fd6f26f202
7 changed files with 76 additions and 14 deletions

View File

@ -188,23 +188,18 @@ if (win){
}
void logTasks(){
LogSerial.print("tasks: ");
CommandSerial.print("TASKS:");
for(int i=0; i<N_TASKS; i++){
LogSerial.print(i+1);
LogSerial.print(": ");
LogSerial.print(taskLifetimes[i]);
LogSerial.print("\t\t");
CommandSerial.print(i);
CommandSerial.print(":");
if(taskLifetimes[i]) CommandSerial.print(("y")); else CommandSerial.print(("n"));
CommandSerial.print("#");
CommandSerial.print(taskLifetimes[i]);
if (i < N_TASKS-1) CommandSerial.print(",");
}
LogSerial.println();
CommandSerial.println();
}
void setSlide(int n){
CommandSerial.print("SLIDE:");
CommandSerial.println(n);
switch(n){
case 1:
log("signalling slide 1.");
@ -484,7 +479,7 @@ void setup() {
// set the digital pin as output:
pinMode(13, OUTPUT);
LogSerial.begin(115200);
CommandSerial.begin(9600);
CommandSerial.begin(115200);
setupPins();
keypad.addEventListener(keypadEvent);
prevKnobInput = map(analogRead(pin_knob), 0, 1024, 0, 10);

3
raspi/mgmt/autostart Normal file
View File

@ -0,0 +1,3 @@
@xset s noblank
@xset s off
@xset -dpms

7
raspi/mgmt/playbook.yml Normal file
View File

@ -0,0 +1,7 @@
- hosts: raspi
become: True
become_user: root
tasks:
- copy: src=autostart dest=/home/pi/.config/lxsession/LXDE-pi/autostart
- copy: src=sejf.desktop dest=/etc/xdg/autostart
- apt: name=python-flask state=present

7
raspi/mgmt/sejf.desktop Executable file
View File

@ -0,0 +1,7 @@
[Desktop Entry]
Type=Application
Name=sejf
NoDisplay=true
Exec=python /home/pi/sejf/raspi/pySejf.py
Terminal=true
NotShowIn=GNOME;KDE;XFCE;

View File

@ -2,8 +2,10 @@
import os
os.chdir(os.path.dirname(os.path.realpath(__file__)))
import subprocess
subprocess.call('(date; pwd) >> /tmp/log', shell=True)
import serial
import webapp
webapp.init(serial.Serial('/dev/ttyUSB0', 115200))
import random, math, pygame
from pygame.locals import *
@ -176,6 +178,7 @@ def waitForEvents():
global slide
print("waiting for events")
while 1:
time.sleep(0.01)
if GPIO.input(PIN_SET1) == 0 and slide != SLIDE_KEY:
print "Ardu said go to key slide"
slide = SLIDE_KEY

View File

@ -0,0 +1,19 @@
<html>
<body>
<table>
<tr>
<th>Włącz</th>
{% for n in range(10) %}
<td><a href="/set/{{ n }}">{{ n + 1 }}</a></td>
{% endfor %}
</tr>
<tr>
<th>Wyłącz</th>
{% for n in range(10) %}
<td><a href="/clear/{{ n }}">{{ n + 1 }}</a></td>
{% endfor %}
</tr>
</table>
</body>
</html>

28
raspi/webapp.py Normal file
View File

@ -0,0 +1,28 @@
import flask
import string
import threading
app = flask.Flask(__name__)
@app.route('/set/<int:task>')
def set_task(task):
app.port.write(string.uppercase[task])
return flask.redirect('/')
@app.route('/clear/<int:task>')
def clear_task(task):
app.port.write(string.lowercase[task])
return flask.redirect('/')
@app.route('/')
def index():
return flask.render_template('index.html')
def init(ser):
app.port = ser
app.th = threading.Thread(target=app.run, kwargs={
'host': '0.0.0.0'
})
app.th.daemon = True
app.th.start()