optionally set SDL video driver to KMS, set GPIO thread to daemon mode
This commit is contained in:
parent
bccc8bb6f0
commit
51165f5af9
|
@ -14,3 +14,4 @@ include/
|
||||||
lib/python3.9/
|
lib/python3.9/
|
||||||
pyvenv.cfg
|
pyvenv.cfg
|
||||||
lib/python*
|
lib/python*
|
||||||
|
stat/
|
||||||
|
|
22
NS.py
22
NS.py
|
@ -27,7 +27,6 @@ from pygame.mixer import Sound
|
||||||
from pygame.image import load, fromstring
|
from pygame.image import load, fromstring
|
||||||
from pygame.transform import rotate, flip, scale, smoothscale
|
from pygame.transform import rotate, flip, scale, smoothscale
|
||||||
from pygame.time import get_ticks
|
from pygame.time import get_ticks
|
||||||
from pygame.font import Font
|
|
||||||
from pygame.draw import aalines, lines
|
from pygame.draw import aalines, lines
|
||||||
from pygame.gfxdraw import aapolygon, arc, polygon, aaellipse, ellipse, filled_ellipse, filled_circle
|
from pygame.gfxdraw import aapolygon, arc, polygon, aaellipse, ellipse, filled_ellipse, filled_circle
|
||||||
from pygame.locals import *
|
from pygame.locals import *
|
||||||
|
@ -191,7 +190,7 @@ class NS(Game, Animation):
|
||||||
},
|
},
|
||||||
"input":
|
"input":
|
||||||
{
|
{
|
||||||
"bool": "serial"
|
"bool": ["serial", "pi"]
|
||||||
},
|
},
|
||||||
"display":
|
"display":
|
||||||
{
|
{
|
||||||
|
@ -243,9 +242,10 @@ class NS(Game, Animation):
|
||||||
# Initialize GPIO interface
|
# Initialize GPIO interface
|
||||||
gpio.initialize_gpio()
|
gpio.initialize_gpio()
|
||||||
|
|
||||||
# Launch a separate thread for reading the GPIO (and allowing its custom delays/sleeps)
|
# Launch a separate thread for reading the GPIO (and allowing its custom delays/sleeps). Use the daemon flag to force
|
||||||
|
# exit when the main thread is killed (by a sigterm from systemctl stop) (?).
|
||||||
self.gpio_kill = False
|
self.gpio_kill = False
|
||||||
self.gpio_thread = Thread(target=self.read_gpio)
|
self.gpio_thread = Thread(target=self.read_gpio, daemon=True)
|
||||||
self.gpio_thread.start()
|
self.gpio_thread.start()
|
||||||
|
|
||||||
# init Arduino
|
# init Arduino
|
||||||
|
@ -1114,7 +1114,7 @@ class Title(Animation):
|
||||||
if ii == 0 or ii == 8:
|
if ii == 0 or ii == 8:
|
||||||
y = 20
|
y = 20
|
||||||
|
|
||||||
font = Font(self.get_resource(Dialogue.FONT_PATH), 18)
|
font = pygame.font.Font(self.get_resource(Dialogue.FONT_PATH), 18)
|
||||||
|
|
||||||
# Parse both strings and score objects
|
# Parse both strings and score objects
|
||||||
if isinstance(entry, NS.Score):
|
if isinstance(entry, NS.Score):
|
||||||
|
@ -1269,7 +1269,7 @@ class Dialogue(Animation):
|
||||||
self.avatar.location.center = self.avatar_box.location.center
|
self.avatar.location.center = self.avatar_box.location.center
|
||||||
|
|
||||||
def set_name(self, text):
|
def set_name(self, text):
|
||||||
font = Font(self.get_resource(self.FONT_PATH), self.FONT_SIZE)
|
font = pygame.font.Font(self.get_resource(self.FONT_PATH), self.FONT_SIZE)
|
||||||
self.name = Sprite(self)
|
self.name = Sprite(self)
|
||||||
self.name.add_frame(font.render(text, True, self.TEXT_COLOR).convert_alpha())
|
self.name.add_frame(font.render(text, True, self.TEXT_COLOR).convert_alpha())
|
||||||
self.name.location.midleft = self.name_box.location.left + 5, self.name_box.location.centery
|
self.name.location.midleft = self.name_box.location.left + 5, self.name_box.location.centery
|
||||||
|
@ -1298,7 +1298,7 @@ class Dialogue(Animation):
|
||||||
self.name_box.update()
|
self.name_box.update()
|
||||||
self.name.update()
|
self.name.update()
|
||||||
self.text_box.update()
|
self.text_box.update()
|
||||||
font = Font(self.get_resource(self.FONT_PATH), self.FONT_SIZE)
|
font = pygame.font.Font(self.get_resource(self.FONT_PATH), self.FONT_SIZE)
|
||||||
message = Sprite(self)
|
message = Sprite(self)
|
||||||
lines = self.full_text[:self.text_index].split("\n")
|
lines = self.full_text[:self.text_index].split("\n")
|
||||||
frame = Surface((self.text_box.location.w - 10, 30 * len(lines)), SRCALPHA)
|
frame = Surface((self.text_box.location.w - 10, 30 * len(lines)), SRCALPHA)
|
||||||
|
@ -1330,7 +1330,7 @@ class SkipPrompt(GameChild):
|
||||||
self.buttons[-1].location.centery)
|
self.buttons[-1].location.centery)
|
||||||
left += self.buttons[-1].location.width + AdvancePrompt.BUTTON_SPACING
|
left += self.buttons[-1].location.width + AdvancePrompt.BUTTON_SPACING
|
||||||
self.text = Sprite(self)
|
self.text = Sprite(self)
|
||||||
font = Font(self.get_resource(Dialogue.FONT_PATH), 18)
|
font = pygame.font.Font(self.get_resource(Dialogue.FONT_PATH), 18)
|
||||||
self.text.add_frame(font.render("TO SKIP", True, (0, 0, 0)).convert_alpha())
|
self.text.add_frame(font.render("TO SKIP", True, (0, 0, 0)).convert_alpha())
|
||||||
self.text.location.midleft = (
|
self.text.location.midleft = (
|
||||||
self.buttons[2].location.right + 5,
|
self.buttons[2].location.right + 5,
|
||||||
|
@ -2807,7 +2807,7 @@ class Countdown(GameChild):
|
||||||
def __init__(self, parent):
|
def __init__(self, parent):
|
||||||
GameChild.__init__(self, parent)
|
GameChild.__init__(self, parent)
|
||||||
dsr = self.get_display_surface().get_rect()
|
dsr = self.get_display_surface().get_rect()
|
||||||
font = Font(self.get_resource(Dialogue.FONT_PATH), 76)
|
font = pygame.font.Font(self.get_resource(Dialogue.FONT_PATH), 76)
|
||||||
self.heading = Sprite(self)
|
self.heading = Sprite(self)
|
||||||
self.heading.add_frame(font.render("CONTINUE?", True, (0, 0, 0), (255, 255, 255)).convert_alpha())
|
self.heading.add_frame(font.render("CONTINUE?", True, (0, 0, 0), (255, 255, 255)).convert_alpha())
|
||||||
self.heading.location.midtop = dsr.centerx, 50
|
self.heading.location.midtop = dsr.centerx, 50
|
||||||
|
@ -3141,8 +3141,8 @@ class Ending(Animation):
|
||||||
Animation.__init__(self, parent)
|
Animation.__init__(self, parent)
|
||||||
self.slime_bag = Chemtrails(self)
|
self.slime_bag = Chemtrails(self)
|
||||||
self.tony_avatar = load(self.get_resource("Introduction_tony_avatar.png")).convert()
|
self.tony_avatar = load(self.get_resource("Introduction_tony_avatar.png")).convert()
|
||||||
self.time_font = Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 64)
|
self.time_font = pygame.font.Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 64)
|
||||||
self.rank_font = Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 26)
|
self.rank_font = pygame.font.Font(self.get_resource("rounded-mplus-1m-bold.ttf"), 26)
|
||||||
self.register(self.start, self.start_wipe)
|
self.register(self.start, self.start_wipe)
|
||||||
self.register(self.append_sword, interval=1500)
|
self.register(self.append_sword, interval=1500)
|
||||||
self.swords = []
|
self.swords = []
|
||||||
|
|
|
@ -29,11 +29,16 @@ if "--go-to-dir" in sys.argv:
|
||||||
|
|
||||||
# Use the framebuffer display (for Raspberry Pi). This only works with Pygame 1.9.6 (and SDL 1.2).
|
# Use the framebuffer display (for Raspberry Pi). This only works with Pygame 1.9.6 (and SDL 1.2).
|
||||||
if "--fb" in sys.argv:
|
if "--fb" in sys.argv:
|
||||||
import os
|
|
||||||
os.putenv("SDL_VIDEODRIVER", "fbcon")
|
os.putenv("SDL_VIDEODRIVER", "fbcon")
|
||||||
os.putenv("SDL_FBDEV", "/dev/fb0")
|
os.putenv("SDL_FBDEV", "/dev/fb0")
|
||||||
ignore_sighup()
|
ignore_sighup()
|
||||||
|
|
||||||
|
# Use the KMS video driver. This works for newer versions of Raspberry Pi with the KMS overlay
|
||||||
|
# enabled, SDL 2, and Pygame 2.
|
||||||
|
if "--kms" in sys.argv:
|
||||||
|
os.putenv("SDL_VIDEODRIVER", "kmsdrm")
|
||||||
|
ignore_sighup()
|
||||||
|
|
||||||
from NS import NS
|
from NS import NS
|
||||||
|
|
||||||
NS().run()
|
NS().run()
|
||||||
|
|
8
config
8
config
|
@ -22,7 +22,7 @@ data-exclude = local/, *.pyc, .git*, README, build/, dist/, *.egg-info, *.py, MA
|
||||||
|
|
||||||
[display]
|
[display]
|
||||||
caption = Scrapeboard
|
caption = Scrapeboard
|
||||||
show-framerate = no
|
show-framerate = yes
|
||||||
dimensions = 800, 450
|
dimensions = 800, 450
|
||||||
fullscreen = no
|
fullscreen = no
|
||||||
attract-gif-alpha = 1.0
|
attract-gif-alpha = 1.0
|
||||||
|
@ -60,9 +60,9 @@ volume = 1.0
|
||||||
[input]
|
[input]
|
||||||
buffer = 0
|
buffer = 0
|
||||||
arduino-port = /dev/ttyACM0
|
arduino-port = /dev/ttyACM0
|
||||||
serial = False
|
serial = no
|
||||||
pi = True
|
pi = no
|
||||||
confirm-quit = False
|
confirm-quit = no
|
||||||
|
|
||||||
[time]
|
[time]
|
||||||
timer-max-time = 10000
|
timer-max-time = 10000
|
||||||
|
|
2
gpio.py
2
gpio.py
|
@ -10,6 +10,8 @@
|
||||||
# inputs on the Raspberry Pi for detecting the pads in Scrapeboard.
|
# inputs on the Raspberry Pi for detecting the pads in Scrapeboard.
|
||||||
#
|
#
|
||||||
# When run as a script, it prints connections detected between the input GPIO pins.
|
# When run as a script, it prints connections detected between the input GPIO pins.
|
||||||
|
#
|
||||||
|
# Original algorithm by Dr. Clement Shimizu is translated from Arduino code in serial2.ino
|
||||||
|
|
||||||
import time, itertools, argparse
|
import time, itertools, argparse
|
||||||
import RPi.GPIO as GPIO
|
import RPi.GPIO as GPIO
|
||||||
|
|
Loading…
Reference in New Issue