commit 26afe4cbd29692c9ee743f21bad5a1f70bdfd6ee Author: Shawn Nock Date: Fri Jan 20 18:38:47 2017 -0500 Initial commit diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..e69de29 diff --git a/main.py b/main.py new file mode 100644 index 0000000..b187881 --- /dev/null +++ b/main.py @@ -0,0 +1,112 @@ +from escapelib import Game, nbus, gpio +from escapelib.io import on_input, on_puzzle +from escapelib.media import play_music, reset_played, stop_music +from escapelib.util import delay, quit_game + +from twisted.application.service import Application + + +class ButtonPanel(nbus.Prop): + button_0 = nbus.Input(0) + button_1 = nbus.Input(1) + button_2 = nbus.Input(2) + button_3 = nbus.Input(3) + button_4 = nbus.Input(4) + button_5 = nbus.Input(5) + +class Portrait(nbus.Prop): + top_left = nbus.Input(0) + top_right = nbus.Input(1) + bottom_left = nbus.Input(2) + bottom_right = nbus.Input(3) + +class Jars(nbus.Prop): + slot_0 = nbus.Analog(0) + slot_1 = nbus.Analog(1) + slot_2 = nbus.Analog(2) + slot_3 = nbus.Analog(3) + slot_4 = nbus.Analog(4) + slot_5 = nbus.Analog(5) + cauldron_light = nbus.Output(0) + +class Puzzle(nbus.Prop): + sensor_0 = nbus.Analog(0) + sensor_1 = nbus.Analog(1) + sensor_2 = nbus.Analog(2) + sensor_3 = nbus.Analog(3) + sensor_4 = nbus.Analog(4) + sensor_5 = nbus.Analog(5) + +class LibraryCabinet(nbus.Prop): + sensor = nbus.Input(0) + lock = nbus.Output(0) + +class InputBoard(nbus.Prop): + announcements = nbus.Input(0) + room_power = nbus.Input(2) + +class BookOfSpells(Game): + + __bus_port__ = '/dev/ttyUSB0' + __bus_baud__ = 1000000 + + reset = gpio.Input(8) + + key_drop = gpio.Output(504) + exit_lock = gpio.Output(506) + exit_lights = gpio.Output(507) + cupboard_lock = gpio.Output(508) + dog_box = gpio.Output(509) + + button_panel = ButtonPanel(0x00) + portrait = Portrait(0x01) + jars = Jars(0x02) + puzzle = Puzzle(0x03) + library_cabinet = LibraryCabinet(0x04) + input_board = InputBoard(0xaa) + + @on_input(reset) + def reset_software(self): + quit_game() + + @on_input(input_board.room_power) + def game_start(self): # type: () -> None + self.key_drop.set(True) + self.exit_lock.set(True) + self.cupboard_lock.set(True) + self.exit_lights.set(True) + reset_played() + play_music("music.mp3") + + @on_input(input_board.room_power, False) + def game_stop(self): # type: () -> None + self.exit_lights.set(False) + self.exit_lock.set(False) + self.cupboard_lock.set(False) + stop_music() + + @on_input(input_board.announcements) + def play_house_announcements(self, state): # type: (bool) -> None + if state is True: + play_sound_effect('button.mp3') + + @on_puzzle(jars) + def win(self): # type: () -> None + self.timer.stop() + self.exit_lock.set(False) + + @on_puzzle(button_panel) + def drop_key(self): # type: () -> None + self.key_drop.set(False) + + @on_puzzle(portrait) + def play_slytherin(self): # type: () -> None + play_sound_effect_once("slytherin.mp3") + + @on_puzzle(puzzle) + def open_cupboard(self): # type: () -> None + self.cupboard_lock.set(False) + +game = BookOfSpells() +application = Application(game.__class__.__name__) +game.register(application) diff --git a/main.pyc b/main.pyc new file mode 100644 index 0000000..fcb2b3a Binary files /dev/null and b/main.pyc differ diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..f4c1803 --- /dev/null +++ b/setup.py @@ -0,0 +1,32 @@ +from setuptools import find_packages, setup +setup( + name='escapelib', + + # Versions should comply with PEP440. For a discussion on single-sourcing + # the version across setup.py and the project code, see + # https://packaging.python.org/en/latest/single_source_version.html + version='0.1.0', + description='Escape Room Controller Library', + url='https://github.com/MonadnockSystems/escapelib', + author='Monadnock Systems', + author_email='shawn@monadnock.ca', + license='APLv2', + classifiers=[ + 'Development Status :: 4 - Beta', + 'Intended Audience :: Developers', + 'License :: OSI Approved :: APLv2', + 'Programming Language :: Python :: 2', + 'Programming Language :: Python :: 2.7', + 'Programming Language :: Python :: 3', + 'Programming Language :: Python :: 3.5', + 'Programming Language :: Python :: 3.6', + ], + keywords='escape room escaperoom', + packages=find_packages(where='src'), + package_dir={"": "src"}, + install_requires=['twisted[tls]', 'klein', 'sysfs-gpio', 'crcmod', + 'pyserial', 'attrs', 'jinja2', 'smbus-cffi'], + extras_require={ + 'test': ['tox'] + }, +) diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..31d40b2 --- /dev/null +++ b/tox.ini @@ -0,0 +1,75 @@ +[tox] +envlist = flake8,linters + +[testenv] +deps = pycryptodome + +[flake8] +ignore = D100,D101,D102,D103,D104,E226 +max-complexity = 14 + +[testenv:flake8] +basepython = python3 +skip_install = true +deps = + flake8 + flake8-docstrings>=0.2.7 + flake8-import-order>=0.9 +commands = + flake8 src setup.py + +[testenv:doc8] +basepython = python3 +skip_install = true +deps = + sphinx + doc8 +commands = + doc8 docs + +[testenv:mypy] +basepython = python3 +skip_install = true +deps = + mypy-lang + typed-ast +setenv = + MYPYPATH=stubs +commands = + mypy --fast-parser src/c3reference + +[bandit] +skips: B311 + +[testenv:bandit] +basepython = python3 +skip_install = true +deps = + bandit +commands = + bandit -r src/c3reference --ini tox.ini + +[testenv:pylint] +basepython = python3 +skip_install = true +deps = + pyflakes + pylint +commands = + pylint --rcfile=pylint.rc src/c3reference + +[testenv:linters] +basepython = python3 +skip_install = true +setenv = + {[testenv:mypy]setenv} +deps = + {[testenv:flake8]deps} + {[testenv:pylint]deps} + {[testenv:bandit]deps} + {[testenv:mypy]deps} +commands = + {[testenv:flake8]commands} + {[testenv:pylint]commands} + {[testenv:bandit]commands} + {[testenv:mypy]commands} \ No newline at end of file