diff --git a/arduino/src/main.ino b/arduino/src/main.ino index b0f3c23..b328b9c 100644 --- a/arduino/src/main.ino +++ b/arduino/src/main.ino @@ -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); diff --git a/raspi/mgmt/playbook.yml b/raspi/mgmt/playbook.yml index 08a8bea..d28ff27 100644 --- a/raspi/mgmt/playbook.yml +++ b/raspi/mgmt/playbook.yml @@ -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 diff --git a/raspi/mgmt/sejf.desktop b/raspi/mgmt/sejf.desktop deleted file mode 100755 index 7874fc6..0000000 --- a/raspi/mgmt/sejf.desktop +++ /dev/null @@ -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; diff --git a/raspi/mgmt/sejf.service b/raspi/mgmt/sejf.service new file mode 100755 index 0000000..dc0b6a0 --- /dev/null +++ b/raspi/mgmt/sejf.service @@ -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 diff --git a/raspi/pySejf.py b/raspi/pySejf.py index 0cb5075..e63317d 100644 --- a/raspi/pySejf.py +++ b/raspi/pySejf.py @@ -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: diff --git a/raspi/run.sh b/raspi/run.sh deleted file mode 100755 index fb0f19e..0000000 --- a/raspi/run.sh +++ /dev/null @@ -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