Snek cleanup, fix win, use systemd now

This commit is contained in:
Piotr Dobrowolski 2017-09-13 16:12:50 +02:00
parent 30d7ea815e
commit b2dc07dc5b
6 changed files with 37 additions and 35 deletions

View File

@ -417,14 +417,12 @@ void setupPins(){
digitalWrite(pin_rpi_pos, HIGH);
//inicjalizacja przerwan PCINT idacych od RPi
/*
pinMode(pin_rpi_win4, INPUT); //nie moze byc pullup, bo podciagalby do 5V - te piny trzyma w stanie wysokim RPi
enableInterrupt(pin_rpi_win4, win4ISR, CHANGE);
pinMode(pin_rpi_win9, INPUT);
enableInterrupt(pin_rpi_win9, win9ISR, CHANGE);
pinMode(pin_rpi_win10, INPUT);
enableInterrupt(pin_rpi_win10, win10ISR, CHANGE);
*/
//piny slajdow
pinMode(pin_rpi_slide1, OUTPUT);

View File

@ -5,8 +5,10 @@
- synchronize: src=../.. dest=/home/pi/sejf
- synchronize: src="custom/{{ inventory_hostname }}" dest=/home/pi/sejf/raspi
ignore_errors: yes
- file: path=/etc/xdg/autostart/pprompt.desktop state=absent
- copy: src=sejf.service dest=/etc/systemd/system/sejf.service
- systemd: name=sejf state=restarted enabled=yes
- 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

View File

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

13
raspi/mgmt/sejf.service Executable file
View File

@ -0,0 +1,13 @@
[Unit]
Description=sejf
After=lightdm.service
[Service]
ExecStart=/usr/bin/python /home/pi/sejf/raspi/pySejf.py
Restart=always
Environment=DISPLAY=:0
User=pi
KillSignal=SIGKILL
[Install]
WantedBy=default.target

View File

@ -97,12 +97,28 @@ class SnakeSlide(Slide):
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):
@ -110,6 +126,8 @@ class SnakeSlide(Slide):
return
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):
@ -129,22 +147,12 @@ 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):
self.finish()
signalWin(4)
self.finish()
return
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()
@ -355,6 +363,7 @@ class ReceiveThread(threading.Thread):
logging.exception('Receiver failed')
time.sleep(0.5)
ser = None
for c in ['/dev/ttyUSB0', '/dev/ttyACM0']:
try:

View File

@ -1,13 +0,0 @@
#!/bin/bash
# Simple SUPERVISOR script to keep pySejf running...
(
flock -n 9 || exit 1
cd $(dirname $(realpath $0))
while true; do
python pySejf.py 2>&1 | tee -a /tmp/pysejf.log
sleep 0.5;
done
) 9>/var/lock/pysejf