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