added on_nummernschalter_active event, stop playing the dailtone once it occurs

This commit is contained in:
Frederic 2015-05-19 22:17:36 +02:00
parent 3ceb7fade3
commit e8ab032e89
2 changed files with 28 additions and 6 deletions

View file

@ -38,6 +38,9 @@ class AbstractState(object):
def on_invalid_number(self): def on_invalid_number(self):
raise IllegalEventError() raise IllegalEventError()
def on_nummernschalter_active(self):
raise IllegalEventError()
def on_nummernschalter_input(self, num): def on_nummernschalter_input(self, num):
raise IllegalEventError() raise IllegalEventError()
@ -74,6 +77,9 @@ class IdleState(AbstractState):
def on_gabelschalter_down(self): def on_gabelschalter_down(self):
pass pass
def on_nummernschalter_active(self, x):
pass
def on_nummernschalter_input(self, x): def on_nummernschalter_input(self, x):
pass pass
@ -178,6 +184,10 @@ class DialingState(AbstractState):
self.__on_leave() self.__on_leave()
return IdleState return IdleState
def on_nummernschalter_active(self):
if self.__dial_tone:
self._controller.get_phone().stop_playing()
def on_nummernschalter_input(self, num): def on_nummernschalter_input(self, num):
print('nummernschalter: %d' % (num)) print('nummernschalter: %d' % (num))
if self.__dial_tone: if self.__dial_tone:
@ -257,7 +267,11 @@ def gabelschalter_cb(state):
else: else:
c.queue_event('gabelschalter_down') c.queue_event('gabelschalter_down')
def nummernschalter_cb(digit): def nummernschalter_active_cb():
global c
c.queue_event('nummernschalter_active')
def nummernschalter_done_cb(digit):
global c global c
c.queue_event('nummernschalter_input', digit) c.queue_event('nummernschalter_input', digit)
@ -284,7 +298,8 @@ if __name__ == '__main__':
c = StateMachineController(phone, feap) c = StateMachineController(phone, feap)
feap.add_gabelschalter_callback(gabelschalter_cb) feap.add_gabelschalter_callback(gabelschalter_cb)
feap.add_nummernschalter_callback(nummernschalter_cb) feap.add_nummernschalter_active_callback(nummernschalter_active_cb)
feap.add_nummernschalter_done_callback(nummernschalter_done_cb)
phone.add_event_cb(phone_cb) phone.add_event_cb(phone_cb)
phone.start() phone.start()

View file

@ -38,7 +38,8 @@ class FeApUserInterface(object):
self.__nsi_cnt = 0 self.__nsi_cnt = 0
self.__weckt = False self.__weckt = False
self.__nummernschalter_callbacks = [] self.__nummernschalter_active_callbacks = []
self.__nummernschalter_done_callbacks = []
self.__gabelschalter_callbacks = [] self.__gabelschalter_callbacks = []
def __on_nsa_change(self, pin): def __on_nsa_change(self, pin):
@ -46,8 +47,11 @@ class FeApUserInterface(object):
if nsastate == 0: if nsastate == 0:
#self.__nsa_up_time = time.time() #self.__nsa_up_time = time.time()
self.__nsi_cnt = 0 self.__nsi_cnt = 0
for cb in self.__nummernschalter_active_callbacks:
cb()
else: else:
for cb in self.__nummernschalter_callbacks: for cb in self.__nummernschalter_done_callbacks:
cb(self.__nsi_cnt % 10) cb(self.__nsi_cnt % 10)
def __on_nsi_falling(self, pin): def __on_nsi_falling(self, pin):
@ -82,8 +86,11 @@ class FeApUserInterface(object):
def add_gabelschalter_callback(self, cb): def add_gabelschalter_callback(self, cb):
self.__gabelschalter_callbacks.append(cb) self.__gabelschalter_callbacks.append(cb)
def add_nummernschalter_callback(self, cb): def add_nummernschalter_active_callback(self, cb):
self.__nummernschalter_callbacks.append(cb) self.__nummernschalter_active_callbacks.append(cb)
def add_nummernschalter_done_callback(self, cb):
self.__nummernschalter_done_callbacks.append(cb)
def set_wecker(self, enabled): def set_wecker(self, enabled):
if enabled and not self.__weckt: if enabled and not self.__weckt: