Compare commits
No commits in common. "328bfac4594cf572a3a34ab079f45974e69dc6b7" and "8d8918b25a6be6b9b5200a8f995c767b2679150d" have entirely different histories.
328bfac459
...
8d8918b25a
@ -1 +0,0 @@
|
||||
- custom
|
@ -4,8 +4,3 @@ Building and deployment
|
||||
$ cd arduino && pio run && cd ..
|
||||
$ cd raspi/mgmt && ansible-playbook playbook.yml && ansible-playbook
|
||||
arduino.yml
|
||||
|
||||
Customization
|
||||
=============
|
||||
|
||||
`raspi/mgmt/custom/{{ IP }}` is overlaid over default raspi/ code
|
||||
|
@ -331,8 +331,8 @@ void pin_mazeISR() {
|
||||
void openDrawer(){
|
||||
log("The drawer is open.");
|
||||
digitalWrite(pin_drawer_relay, HIGH);
|
||||
// delay(DRAWER_OPEN_DELAY);
|
||||
// digitalWrite(pin_drawer_relay, LOW);
|
||||
delay(DRAWER_OPEN_DELAY);
|
||||
digitalWrite(pin_drawer_relay, LOW);
|
||||
}
|
||||
|
||||
void checkPassword(){
|
||||
|
@ -1,11 +0,0 @@
|
||||
#gameplay
|
||||
#wynik w snake, ktory wygrywa
|
||||
SNAKE_SCORE = 2
|
||||
#predkosc gry w snake - w zakresie od 1 do 10
|
||||
TICK_SNAKE = 10
|
||||
#ilosc segmentow dodanych do snake po zlapaniu jablka
|
||||
SNAKE_ADDSIZE = 10
|
||||
|
||||
#hasla klawiatury ekranowej dla obu zagadek
|
||||
PASSWORD1 = 'one'
|
||||
PASSWORD2 = 'two'
|
@ -1,11 +1,5 @@
|
||||
[raspi-wifi]
|
||||
[raspi]
|
||||
192.168.43.12
|
||||
192.168.43.44
|
||||
192.168.43.219
|
||||
192.168.43.231
|
||||
|
||||
[raspi]
|
||||
10.21.37.150
|
||||
10.21.37.180
|
||||
10.21.37.185
|
||||
10.21.37.226
|
||||
|
@ -3,12 +3,8 @@
|
||||
become_user: root
|
||||
tasks:
|
||||
- synchronize: src=../.. dest=/home/pi/sejf
|
||||
- synchronize: src="custom/{{ inventory_hostname }}" dest=/home/pi/sejf/raspi
|
||||
ignore_errors: yes
|
||||
- copy: src=sejf.service dest=/etc/systemd/system/sejf.service
|
||||
- systemd: name=sejf state=restarted enabled=yes
|
||||
- file: path=/etc/xdg/autostart/pprompt.desktop state=absent
|
||||
- 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
|
||||
- apt: name=avrdude state=present
|
||||
- file: path=/etc/xdg/autostart/pprompt.desktop state=absent
|
||||
- file: path=/etc/xdg/autostart/sejf.desktop state=absent
|
||||
|
7
raspi/mgmt/sejf.desktop
Executable file
7
raspi/mgmt/sejf.desktop
Executable 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;
|
@ -1,13 +0,0 @@
|
||||
[Unit]
|
||||
Description=sejf
|
||||
After=lightdm.service
|
||||
|
||||
[Service]
|
||||
ExecStart=/usr/bin/python -u /home/pi/sejf/raspi/pySejf.py
|
||||
Restart=always
|
||||
Environment=DISPLAY=:0
|
||||
User=pi
|
||||
KillSignal=SIGKILL
|
||||
|
||||
[Install]
|
||||
WantedBy=default.target
|
103
raspi/pySejf.py
103
raspi/pySejf.py
@ -9,7 +9,6 @@ import threading
|
||||
import logging
|
||||
import socket
|
||||
import json
|
||||
import string
|
||||
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
import random, pygame
|
||||
@ -46,10 +45,9 @@ class ImageSlide(Slide):
|
||||
|
||||
class FinalSlide(ImageSlide):
|
||||
def exit(self, next_slide):
|
||||
# Allow change to exit slide
|
||||
return isinstance(next_slide, FinalSlide)
|
||||
return False
|
||||
|
||||
class FinalEverythingSlide(FinalSlide):
|
||||
class FinalEverythingSlide(ImageSlide):
|
||||
def enter(self, prev_slide):
|
||||
global wall_a
|
||||
if(wall_a):
|
||||
@ -60,6 +58,9 @@ class FinalEverythingSlide(FinalSlide):
|
||||
|
||||
return True
|
||||
|
||||
def exit(self, next_slide):
|
||||
return False
|
||||
|
||||
class SnakeSlide(Slide):
|
||||
def enter(self, prev_slide=None):
|
||||
self.xs = [290, 290, 290, 290, 290];
|
||||
@ -73,14 +74,9 @@ class SnakeSlide(Slide):
|
||||
#img.fill((255, 0, 0))
|
||||
self.f = FONT_SNAKE
|
||||
self.clock = pygame.time.Clock()
|
||||
self.finished = False
|
||||
|
||||
return True
|
||||
|
||||
def finish(self):
|
||||
self.finished = True
|
||||
self.finish_time = time.time()
|
||||
|
||||
def handle(self, e):
|
||||
print(e)
|
||||
if e.type == KEYDOWN:
|
||||
@ -89,45 +85,19 @@ class SnakeSlide(Slide):
|
||||
elif e.key == K_LEFT and self.dirs != 1:self.dirs = 3
|
||||
elif e.key == K_RIGHT and self.dirs != 3:self.dirs = 1
|
||||
|
||||
if self.finished and time.time() - self.finish_time > 3:
|
||||
self.enter()
|
||||
|
||||
print(self.dirs)
|
||||
|
||||
def render(self, screen):
|
||||
self.clock.tick(TICK_SNAKE)
|
||||
|
||||
if not self.finished:
|
||||
self.interact()
|
||||
|
||||
#rysuj tlo
|
||||
screen.fill(WHITE)
|
||||
screen.blit(IMG_SNAKE, (0, 0))
|
||||
|
||||
for i in range(0, len(self.xs)):
|
||||
screen.blit(self.img, (self.xs[i], self.ys[i]))
|
||||
|
||||
screen.blit(self.appleimage, self.applepos);
|
||||
t=self.f.render(str(self.score), True, (0, 0, 0));
|
||||
screen.blit(t, (10, 10));
|
||||
|
||||
if self.finished:
|
||||
f=FONT_SNAKE
|
||||
t=f.render(MSG_SNAKE+str(self.score), True, (0, 0, 0))
|
||||
screen.blit(t, (10, 270))
|
||||
return
|
||||
|
||||
def interact(self):
|
||||
# snek collision
|
||||
i = len(self.xs)-1
|
||||
while i >= 2:
|
||||
if collide(self.xs[0], self.xs[i], self.ys[0], self.ys[i], 20, 20, 20, 20):
|
||||
self.finish()
|
||||
return
|
||||
die(screen, self.score)
|
||||
self.score = 0
|
||||
self.enter()
|
||||
|
||||
i-= 1
|
||||
|
||||
# Apple collision
|
||||
if collide(self.xs[0], self.applepos[0], self.ys[0], self.applepos[1], 20, 10, 20, 10):
|
||||
self.score+=1
|
||||
for i in range(0, SNAKE_ADDSIZE):
|
||||
@ -136,8 +106,9 @@ class SnakeSlide(Slide):
|
||||
self.applepos=(random.randint(0,WINSIZEX),random.randint(0,WINSIZEY))
|
||||
|
||||
if self.xs[0] < 0 or self.xs[0] > WINSIZEX or self.ys[0] < 0 or self.ys[0] > WINSIZEY:
|
||||
self.finish()
|
||||
return
|
||||
die(screen, self.score)
|
||||
score = 0
|
||||
self.enter()
|
||||
|
||||
self.xs[1:] = self.xs[:-1]
|
||||
self.ys[1:] = self.ys[:-1]
|
||||
@ -147,16 +118,35 @@ class SnakeSlide(Slide):
|
||||
elif self.dirs==2:self.ys[0] -= 20
|
||||
elif self.dirs==3:self.xs[0] -= 20
|
||||
|
||||
#rysuj tlo
|
||||
screen.fill(WHITE)
|
||||
screen.blit(IMG_SNAKE, (0, 0))
|
||||
print("drawing snake...")
|
||||
if(self.score > SNAKE_SCORE):
|
||||
signalWin(4)
|
||||
self.finish()
|
||||
return
|
||||
die(screen, self.score)
|
||||
self.enter()
|
||||
|
||||
for i in range(0, len(self.xs)):
|
||||
screen.blit(self.img, (self.xs[i], self.ys[i]))
|
||||
|
||||
screen.blit(self.appleimage, self.applepos);
|
||||
t=self.f.render(str(self.score), True, (0, 0, 0));
|
||||
screen.blit(t, (10, 10));
|
||||
|
||||
pygame.init()
|
||||
pygame.mixer.init()
|
||||
|
||||
from gameplayconfig import *
|
||||
#gameplay
|
||||
#wynik w snake, ktory wygrywa
|
||||
SNAKE_SCORE = 2
|
||||
#predkosc gry w snake - w zakresie od 1 do 10
|
||||
TICK_SNAKE = 10
|
||||
#ilosc segmentow dodanych do snake po zlapaniu jablka
|
||||
SNAKE_ADDSIZE = 10
|
||||
|
||||
#hasla klawiatury ekranowej dla obu zagadek
|
||||
password1 = 'one'
|
||||
password2 = 'two'
|
||||
|
||||
#ilosc powtorzen mp3
|
||||
MP3_LOOPS = 4
|
||||
@ -246,9 +236,7 @@ GPIO.setup(PIN_SUC10, GPIO.OUT)
|
||||
GPIO.setup(PIN_RELAY, GPIO.OUT)
|
||||
GPIO.output(PIN_SUC9, 1)
|
||||
GPIO.output(PIN_SUC10, 1)
|
||||
|
||||
# Well, we flipped it...
|
||||
GPIO.output(PIN_RELAY, 0)
|
||||
GPIO.output(PIN_RELAY, 1)
|
||||
|
||||
WINSIZEX, WINSIZEY = 900, 680
|
||||
timeSec = 0
|
||||
@ -256,6 +244,9 @@ UP = 1
|
||||
DOWN = 3
|
||||
RIGHT = 2
|
||||
LEFT = 4
|
||||
lastJoyState = RIGHT
|
||||
score = 0
|
||||
dynamoValSPI = [0,0,0]
|
||||
|
||||
#numery slajdow
|
||||
SLIDE_START = 0
|
||||
@ -297,11 +288,11 @@ def go_to_slide(new_slide):
|
||||
logging.warning('Same slide...')
|
||||
return False
|
||||
|
||||
if slides.get(slide) and not slides[slide].exit(slides.get(new_slide)):
|
||||
if slides.get(slide) and not slides[slide].exit(new_slide):
|
||||
logging.warning('exit rejected')
|
||||
return False
|
||||
|
||||
if slides.get(new_slide) and not slides[new_slide].enter(slides.get(slide)):
|
||||
if slides.get(new_slide) and not slides[new_slide].enter(slide):
|
||||
logging.warning('enter rejected')
|
||||
return False
|
||||
|
||||
@ -339,7 +330,6 @@ class BroadcastThread(threading.Thread):
|
||||
print('sending')
|
||||
cs.sendto(json.dumps({
|
||||
'slide': slide,
|
||||
'name': socket.gethostname(),
|
||||
}), ('255.255.255.255', 54545))
|
||||
time.sleep(1)
|
||||
|
||||
@ -355,6 +345,7 @@ class ReceiveThread(threading.Thread):
|
||||
try:
|
||||
msg, (host, port) = s.recvfrom(1024)
|
||||
self.states[host] = json.loads(msg)
|
||||
print(self.states)
|
||||
|
||||
if all(s['slide'] in [SLIDE_CONGRATS, SLIDE_CONGRATS_EVERYTHING]
|
||||
for s in self.states.values()):
|
||||
@ -363,7 +354,6 @@ class ReceiveThread(threading.Thread):
|
||||
logging.exception('Receiver failed')
|
||||
time.sleep(0.5)
|
||||
|
||||
ser = None
|
||||
|
||||
for c in ['/dev/ttyUSB0', '/dev/ttyACM0']:
|
||||
try:
|
||||
@ -386,12 +376,10 @@ for c in ['/dev/ttyUSB0', '/dev/ttyACM0']:
|
||||
rth.daemon = True
|
||||
rth.start()
|
||||
|
||||
webapp.app.rth = rth
|
||||
|
||||
|
||||
def win():
|
||||
print "GAME OVER - YOU WIN"
|
||||
GPIO.output(PIN_RELAY, 1)
|
||||
GPIO.output(PIN_RELAY, 0)
|
||||
|
||||
def signalWin(success):
|
||||
pin = 0
|
||||
@ -458,6 +446,9 @@ def die(screen, score):
|
||||
screen.blit(t, (10, 270))
|
||||
pygame.display.update()
|
||||
pygame.time.wait(2000)
|
||||
global slide
|
||||
slide = SLIDE_SNAKE_DEAD
|
||||
waitForEvents()
|
||||
|
||||
############# old main
|
||||
######## CONSTANTS
|
||||
@ -555,11 +546,11 @@ def main():
|
||||
# Set the x, y postions of the mouse click
|
||||
x, y = event.pos
|
||||
if enterButton.collidepoint(x, y):
|
||||
if passwordLetter == PASSWORD1:
|
||||
if passwordLetter == password1:
|
||||
print 'password correct for task 9.'
|
||||
signalWin(9)
|
||||
|
||||
if passwordLetter == PASSWORD2:
|
||||
if passwordLetter == password2:
|
||||
print 'password correct for task 10.'
|
||||
signalWin(10)
|
||||
|
||||
|
@ -2,33 +2,18 @@
|
||||
<body>
|
||||
|
||||
<table>
|
||||
<ul>
|
||||
{% for k, v in states %}
|
||||
<li>
|
||||
{% if v['name'] == hostname %}<b>{% endif %}
|
||||
<a href="http://{{ k }}:5000">{{ v['name'] }}</a> ({{ v['slide'] }})
|
||||
{% if v['name'] == hostname %}</b>{% endif %}
|
||||
</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
||||
<tr>
|
||||
<th>Włącz</th>
|
||||
{% for n in range(10) %}
|
||||
<td><a href="/set/{{ n }}">{{ n + 1 }}</a></td>
|
||||
{% endfor %}
|
||||
|
||||
<td><a href="/set/all">Wszystko</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th>Wyłącz</th>
|
||||
{% for n in range(10) %}
|
||||
<td><a href="/clear/{{ n }}">{{ n + 1 }}</a></td>
|
||||
{% endfor %}
|
||||
<td><a href="/clear/all">Wszystko</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<a href="/restart" style="color: red">RESTART</a>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -1,8 +1,6 @@
|
||||
import flask
|
||||
import string
|
||||
import time
|
||||
import threading
|
||||
import socket
|
||||
|
||||
app = flask.Flask(__name__)
|
||||
|
||||
@ -16,41 +14,9 @@ def clear_task(task):
|
||||
app.port.write(string.lowercase[task])
|
||||
return flask.redirect('/')
|
||||
|
||||
@app.route('/set/all')
|
||||
def set_all():
|
||||
app.port.write(string.uppercase)
|
||||
return flask.redirect('/')
|
||||
|
||||
@app.route('/clear/all')
|
||||
def clear_all():
|
||||
app.port.write(string.lowercase)
|
||||
return flask.redirect('/')
|
||||
|
||||
@app.route('/restart')
|
||||
def restart():
|
||||
import thread
|
||||
thread.interrupt_main()
|
||||
return flask.redirect('/') # xD
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
states = app.rth.states.items()
|
||||
states.sort(key=lambda (k, v): v['name'])
|
||||
|
||||
return flask.render_template(
|
||||
'index.html', hostname=socket.gethostname(), states=states)
|
||||
|
||||
@app.route('/arduino/reset')
|
||||
def reset():
|
||||
app.port.dtr = False
|
||||
time.sleep(0.5)
|
||||
app.port.dtr = True
|
||||
time.sleep(0.5)
|
||||
app.port.dtr = False
|
||||
time.sleep(0.5)
|
||||
app.port.dtr = True
|
||||
return flask.redirect('/')
|
||||
|
||||
return flask.render_template('index.html')
|
||||
|
||||
def init(ser):
|
||||
app.port = ser
|
||||
|
Loading…
x
Reference in New Issue
Block a user