Compare commits
5 Commits
cleanup
...
rpi-dev-me
Author | SHA1 | Date | |
---|---|---|---|
|
34d934fb4a | ||
|
7def89db02 | ||
|
d753058352 | ||
|
4aa8af306c | ||
|
195abbc5eb |
@@ -6,8 +6,12 @@ the hardware can be run without the actual hardware.
|
|||||||
# Constants used by RPi.GPIO
|
# Constants used by RPi.GPIO
|
||||||
BOARD = 0
|
BOARD = 0
|
||||||
IN = 0
|
IN = 0
|
||||||
|
OUT = 1
|
||||||
FALLING = 0
|
FALLING = 0
|
||||||
|
|
||||||
|
HIGH = 1
|
||||||
|
LOW = 0
|
||||||
|
|
||||||
|
|
||||||
def setmode(new_mode):
|
def setmode(new_mode):
|
||||||
"""
|
"""
|
||||||
@@ -28,6 +32,16 @@ def setup(channel, mode, initial=None, pull_up_down=None):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def output(channel, set):
|
||||||
|
"""
|
||||||
|
Fake function to set a fake channel output.
|
||||||
|
:param channel:
|
||||||
|
:param set:
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def add_event_detect(channel, edge_type, callback=None, bouncetime=0):
|
def add_event_detect(channel, edge_type, callback=None, bouncetime=0):
|
||||||
"""
|
"""
|
||||||
Fake function to add a non-existent event detect.
|
Fake function to add a non-existent event detect.
|
||||||
@@ -43,7 +57,7 @@ def event_detected(channel):
|
|||||||
"""
|
"""
|
||||||
Fake function to detect an event. Always returns false.
|
Fake function to detect an event. Always returns false.
|
||||||
:param channel:
|
:param channel:
|
||||||
:return:
|
:return: False
|
||||||
"""
|
"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@@ -29,6 +29,15 @@ def run_button_test():
|
|||||||
GPIOHandler.setup()
|
GPIOHandler.setup()
|
||||||
|
|
||||||
|
|
||||||
|
def backlight_test():
|
||||||
|
"""
|
||||||
|
Turns off the backlight for 5 seconds.
|
||||||
|
"""
|
||||||
|
GPIOHandler.turn_off_backlight()
|
||||||
|
time.sleep(5)
|
||||||
|
GPIOHandler.turn_on_backlight()
|
||||||
|
|
||||||
|
|
||||||
def clear_screen():
|
def clear_screen():
|
||||||
"""
|
"""
|
||||||
Clears the screen.
|
Clears the screen.
|
||||||
@@ -55,9 +64,9 @@ def quit_menu():
|
|||||||
|
|
||||||
def quit_with_error():
|
def quit_with_error():
|
||||||
"""
|
"""
|
||||||
Quits the menu with error code 3.
|
Quits the menu with error code 2.
|
||||||
"""
|
"""
|
||||||
exit(3)
|
exit(2)
|
||||||
|
|
||||||
|
|
||||||
def change_menu(new_menu):
|
def change_menu(new_menu):
|
||||||
@@ -96,6 +105,7 @@ def main():
|
|||||||
main_menu = Menu('Pocket Friends Dev Menu')
|
main_menu = Menu('Pocket Friends Dev Menu')
|
||||||
main_menu.add_option(Menu.Option('Start Game', start_game))
|
main_menu.add_option(Menu.Option('Start Game', start_game))
|
||||||
main_menu.add_option(Menu.Option('Button Test', run_button_test))
|
main_menu.add_option(Menu.Option('Button Test', run_button_test))
|
||||||
|
main_menu.add_option(Menu.Option('Backlight Test', backlight_test))
|
||||||
main_menu.add_option(Menu.Option('Restart Dev Menu', quit_with_error))
|
main_menu.add_option(Menu.Option('Restart Dev Menu', quit_with_error))
|
||||||
main_menu.add_option(Menu.Option('Shutdown Pi', change_menu, 'shutdown'))
|
main_menu.add_option(Menu.Option('Shutdown Pi', change_menu, 'shutdown'))
|
||||||
main_menu.add_option(Menu.Option('Restart Pi', change_menu, 'restart'))
|
main_menu.add_option(Menu.Option('Restart Pi', change_menu, 'restart'))
|
||||||
|
@@ -970,7 +970,7 @@ def game(screen_size):
|
|||||||
draw()
|
draw()
|
||||||
|
|
||||||
|
|
||||||
def main(screen_size=320):
|
def main(screen_size=240):
|
||||||
"""
|
"""
|
||||||
Calls the game() function to start the game.
|
Calls the game() function to start the game.
|
||||||
"""
|
"""
|
||||||
|
@@ -24,6 +24,9 @@ class Constants:
|
|||||||
'j_l': 13, # Joystick left
|
'j_l': 13, # Joystick left
|
||||||
'j_r': 16 # Joystick right
|
'j_r': 16 # Joystick right
|
||||||
}
|
}
|
||||||
|
hardware = {
|
||||||
|
'backlight': 37
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class GPIOHandler:
|
class GPIOHandler:
|
||||||
@@ -54,6 +57,8 @@ class GPIOHandler:
|
|||||||
GPIO.add_event_detect(Constants.buttons.get('j_l'), GPIO.FALLING)
|
GPIO.add_event_detect(Constants.buttons.get('j_l'), GPIO.FALLING)
|
||||||
GPIO.add_event_detect(Constants.buttons.get('j_r'), GPIO.FALLING)
|
GPIO.add_event_detect(Constants.buttons.get('j_r'), GPIO.FALLING)
|
||||||
|
|
||||||
|
GPIO.setup(Constants.hardware.get('backlight'), GPIO.OUT, initial=GPIO.HIGH)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def teardown():
|
def teardown():
|
||||||
"""
|
"""
|
||||||
@@ -69,3 +74,17 @@ class GPIOHandler:
|
|||||||
:return: True if the button is has been pressed, False otherwise
|
:return: True if the button is has been pressed, False otherwise
|
||||||
"""
|
"""
|
||||||
return GPIO.event_detected(button)
|
return GPIO.event_detected(button)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def turn_on_backlight():
|
||||||
|
"""
|
||||||
|
Turns on the TFT backlight.
|
||||||
|
"""
|
||||||
|
GPIO.output(Constants.hardware.get('backlight'), GPIO.HIGH)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def turn_off_backlight():
|
||||||
|
"""
|
||||||
|
Turns off the TFT backlight.
|
||||||
|
"""
|
||||||
|
GPIO.output(Constants.hardware.get('backlight'), GPIO.LOW)
|
@@ -4,6 +4,7 @@ import argparse
|
|||||||
import pygame
|
import pygame
|
||||||
import sys
|
import sys
|
||||||
from pocket_friends.game_files.game import main as game_main
|
from pocket_friends.game_files.game import main as game_main
|
||||||
|
from pocket_friends.development.dev_menu import main as dev_main
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -16,7 +17,8 @@ def main():
|
|||||||
|
|
||||||
# Adds parser arguments.
|
# Adds parser arguments.
|
||||||
parser.add_argument('-D', '--delete-save', action='store_true', help='Deletes the save file if it exists.')
|
parser.add_argument('-D', '--delete-save', action='store_true', help='Deletes the save file if it exists.')
|
||||||
parser.add_argument('-s', '--size', type=int, default=320, help='Sets the size of the window.')
|
parser.add_argument('-s', '--size', type=int, default=240, help='Sets the size of the window.')
|
||||||
|
parser.add_argument('--dev', action='store_true', help='Deletes the save file if it exists.')
|
||||||
|
|
||||||
# Parse the arguments given
|
# Parse the arguments given
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
@@ -34,8 +36,10 @@ def main():
|
|||||||
# Set the screen size
|
# Set the screen size
|
||||||
screen_size = int(args.size)
|
screen_size = int(args.size)
|
||||||
|
|
||||||
# Start the game
|
if not args.dev:
|
||||||
game_main(screen_size)
|
game_main(screen_size)
|
||||||
|
else:
|
||||||
|
dev_main()
|
||||||
|
|
||||||
# Cleanup
|
# Cleanup
|
||||||
pygame.quit()
|
pygame.quit()
|
||||||
|
Reference in New Issue
Block a user