Merge branch 'master' of github.com:MonadnockSystems/trespassed
This commit is contained in:
commit
073bebf268
|
@ -11,3 +11,9 @@ application = Application("Trespassed")
|
|||
serial_service = SerialService()
|
||||
watchdog_service.setServiceParent(application)
|
||||
serial_service.setServiceParent(application)
|
||||
|
||||
def cleanup():
|
||||
from trespassed.media import MEDIA_CHANNELS
|
||||
MEDIA_CHANNELS.music.stop()
|
||||
|
||||
reactor.addSystemEventTrigger('before', 'shutdown', cleanup)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
from twisted.internet import defer
|
||||
from twisted.internet import defer, reactor
|
||||
from twisted.python import log
|
||||
|
||||
from trespassed.lights import lights, flicker_lights
|
||||
|
@ -14,6 +14,10 @@ OPEN = 1
|
|||
ON = True
|
||||
OFF = False
|
||||
|
||||
class Props:
|
||||
ButtonBox = 0x00
|
||||
Input = 0xaa
|
||||
|
||||
INPUT_MAP = {
|
||||
0x00: {0: "DOLLSWITCH0",
|
||||
1: "DOLLSWITCH1",
|
||||
|
@ -64,6 +68,7 @@ def input_parse(b_id, input_no, transition):
|
|||
if transition:
|
||||
game_off()
|
||||
else:
|
||||
game_off()
|
||||
yield game_init()
|
||||
elif sw is "INNER":
|
||||
if transition is OPEN:
|
||||
|
@ -85,3 +90,5 @@ def input_parse(b_id, input_no, transition):
|
|||
end_sequence()
|
||||
yield delay(10)
|
||||
lights(False)
|
||||
|
||||
reactor.callLater(0, game_init)
|
||||
|
|
|
@ -27,11 +27,16 @@ Controller.available_pins = [ INPUTS.ResetButton,
|
|||
OUTPUTS.MudroomLock, OUTPUTS.Lights, OUTPUTS.DogBox,
|
||||
OUTPUTS.FrontCameraPower ]
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def set_output(pin_no, level):
|
||||
#print(pin_no, level)
|
||||
if not pin_no in PINS:
|
||||
pin = Controller.alloc_pin(pin_no, OUTPUT)
|
||||
PINS[pin_no] = pin
|
||||
try:
|
||||
pin = yield Controller.alloc_pin(pin_no, OUTPUT)
|
||||
PINS[pin_no] = pin
|
||||
except Exception as e:
|
||||
log.msg("Failed to allocate {}: {}".format(pin_no, e))
|
||||
defer.returnValue(None)
|
||||
pin = PINS[pin_no]
|
||||
if level:
|
||||
log.msg("Setting {}".format(pin_no))
|
||||
|
@ -39,3 +44,13 @@ def set_output(pin_no, level):
|
|||
else:
|
||||
log.msg("Clearing {}".format(pin_no))
|
||||
pin.reset()
|
||||
|
||||
skip = True
|
||||
def quit(*args, **kwargs):
|
||||
global skip
|
||||
if not skip:
|
||||
reactor.stop()
|
||||
sys.exit(0)
|
||||
skip = False
|
||||
|
||||
Controller.alloc_pin(INPUTS.ResetButton, INPUT, quit, RISING)
|
||||
|
|
|
@ -43,12 +43,12 @@ class MediaProcessProtocol(protocol.ProcessProtocol):
|
|||
class MediaHandler(object):
|
||||
deferred = attr.ib()
|
||||
transport = attr.ib()
|
||||
stopped = attr.ib(default=False)
|
||||
|
||||
def stop(self):
|
||||
print("Trying to stop {}".format(self.transport.pid))
|
||||
self.deferred.cancel()
|
||||
self.transport.signalProcess('INT')
|
||||
self.stopped = True
|
||||
|
||||
|
||||
def addCallbacks(self, *args, **kwargs):
|
||||
self.deferred.addCallbacks(*args, **kwargs)
|
||||
|
@ -83,7 +83,6 @@ def play_music(path):
|
|||
args = ['mpg123', MEDIA_PATH+path]
|
||||
mh = play_media(args, 'music')
|
||||
def repeat_music(proto):
|
||||
if not MEDIA_CHANNELS.music.stopped:
|
||||
log.msg("Restarting Soundtrack")
|
||||
play_music(path)
|
||||
mh.addCallbacks(repeat_music, email_failure)
|
||||
|
|
|
@ -48,6 +48,9 @@ class NBusProtocol(protocol.Protocol):
|
|||
#log.msg("PACKET: {}".format(hexlify(packet)))
|
||||
p_type = ord(packet[0])
|
||||
b_id = ord(packet[1])
|
||||
if b_id not in INPUT_MAP:
|
||||
log.msg("Packet from unknown device: {}".format(b_id))
|
||||
defer.returnValue(None)
|
||||
data = packet[2:-2]
|
||||
r_crc = packet[-2:]
|
||||
crc16 = crcmod.predefined.Crc('xmodem')
|
||||
|
@ -56,18 +59,17 @@ class NBusProtocol(protocol.Protocol):
|
|||
if crc != r_crc:
|
||||
log.err("CRC Mismatch: {}".format(packet))
|
||||
defer.returnValue(None)
|
||||
WATCHDOG[b_id] = time()
|
||||
if p_type == int(PacketType.Keepalive):
|
||||
WATCHDOG[b_id] = time()
|
||||
pass
|
||||
elif p_type == int(PacketType.Input):
|
||||
WATCHDOG[b_id] = time()
|
||||
yield input_parse(b_id, ord(data[0]), ord(data[1]))
|
||||
elif p_type == int(PacketType.Output):
|
||||
pass
|
||||
elif p_type == int(PacketType.Solved):
|
||||
#log.msg("Solved Puzzle: {}".format(b_id))
|
||||
log.msg("Solved Puzzle: {}".format(b_id))
|
||||
set_output(OUTPUTS.ClosetLock, False)
|
||||
elif p_type == int(PacketType.Failed):
|
||||
WATCHDOG[b_id] = time()
|
||||
yield delay(1)
|
||||
play_sound_effect("fail.mp3")
|
||||
elif p_type == int(PacketType.Log):
|
||||
|
@ -87,7 +89,7 @@ def watchdog():
|
|||
age = time() - WATCHDOG[key]
|
||||
if age > WATCHDOG_TIMEOUT:
|
||||
log.msg("NBus device #{} timed out, reseting bus".format(key, age))
|
||||
WATCHDOG[key] = time()
|
||||
del WATCHDOG[key]
|
||||
yield reset_nbus()
|
||||
|
||||
watchdog_service = TimerService(5, watchdog)
|
||||
|
|
Loading…
Reference in New Issue