- except ValueError:
- pass
-
- logging.info('Enrolling card %s to uid %s (%s)'%(card_id, vstatus.cur_user, vstatus.username))
- set_card_id(vstatus.cur_user, card_id)
- vstatus.mk.set_messages(
- [(center('CARD'), False, 0.5),
- (center('ENROLLED'), False, 0.5)])
-
- # scroll_options(vstatus.username, vstatus.mk)
-
-def return_to_idle(state,event,params,v,vstatus):
- reset_idler(v, vstatus)
-
-def create_state_table(vstatus):
- vstatus.state_table[(STATE_IDLE,TICK,1)] = handle_idle_tick
- vstatus.state_table[(STATE_IDLE,KEY,1)] = handle_idle_key
- vstatus.state_table[(STATE_IDLE,DOOR,1)] = handle_door_event
- vstatus.state_table[(STATE_IDLE,MIFARE,1)] = handle_mifare_event
-
- vstatus.state_table[(STATE_DOOR_OPENING,TICK,1)] = handle_door_idle
- vstatus.state_table[(STATE_DOOR_OPENING,DOOR,1)] = handle_door_event
- vstatus.state_table[(STATE_DOOR_OPENING,KEY,1)] = do_nothing
- vstatus.state_table[(STATE_DOOR_OPENING,MIFARE,1)] = do_nothing
-
- vstatus.state_table[(STATE_DOOR_CLOSING,TICK,1)] = return_to_idle
- vstatus.state_table[(STATE_DOOR_CLOSING,DOOR,1)] = handle_door_event
- vstatus.state_table[(STATE_DOOR_CLOSING,KEY,1)] = do_nothing
- vstatus.state_table[(STATE_DOOR_CLOSING,MIFARE,1)] = do_nothing
-
- vstatus.state_table[(STATE_GETTING_UID,TICK,1)] = handle_getting_uid_idle
- vstatus.state_table[(STATE_GETTING_UID,DOOR,1)] = handle_door_event
- vstatus.state_table[(STATE_GETTING_UID,KEY,1)] = handle_getting_uid_key
- vstatus.state_table[(STATE_GETTING_UID,MIFARE,1)] = handle_mifare_event
-
- vstatus.state_table[(STATE_GETTING_PIN,TICK,1)] = handle_getting_pin_idle
- vstatus.state_table[(STATE_GETTING_PIN,DOOR,1)] = handle_door_event
- vstatus.state_table[(STATE_GETTING_PIN,KEY,1)] = handle_getting_pin_key
- vstatus.state_table[(STATE_GETTING_PIN,MIFARE,1)] = handle_mifare_event
-
- vstatus.state_table[(STATE_GET_SELECTION,TICK,1)] = handle_get_selection_idle
- vstatus.state_table[(STATE_GET_SELECTION,DOOR,1)] = handle_door_event
- vstatus.state_table[(STATE_GET_SELECTION,KEY,1)] = handle_get_selection_key
- vstatus.state_table[(STATE_GET_SELECTION,MIFARE,1)] = handle_mifare_add_user_event
-
- vstatus.state_table[(STATE_GRANDFATHER_CLOCK,TICK,1)] = handle_idle_grandfather_tick
- vstatus.state_table[(STATE_GRANDFATHER_CLOCK,TICK,2)] = handle_grandfather_tick
- vstatus.state_table[(STATE_GRANDFATHER_CLOCK,DOOR,1)] = handle_door_event
- vstatus.state_table[(STATE_GRANDFATHER_CLOCK,DOOR,2)] = handle_door_event
- vstatus.state_table[(STATE_GRANDFATHER_CLOCK,KEY,1)] = do_nothing
- vstatus.state_table[(STATE_GRANDFATHER_CLOCK,KEY,2)] = do_nothing
- vstatus.state_table[(STATE_GRANDFATHER_CLOCK,MIFARE,1)] = handle_mifare_event
-
-def get_state_table_handler(vstatus, state, event, counter):
- return vstatus.state_table[(state,event,counter)]
-
-def time_to_next_update(vstatus):
- idle_update = vstatus.time_of_next_idlestep - time()
- if not vstatus.mk.done() and vstatus.mk.next_update is not None:
- mk_update = vstatus.mk.next_update - time()
- if mk_update < idle_update:
- idle_update = mk_update
- return idle_update
-
-def run_forever(rfh, wfh, options, cf):
- v = VendingMachine(rfh, wfh, USE_MIFARE)
- vstatus = VendState(v)
- create_state_table(vstatus)
-
- logging.debug('PING is ' + str(v.ping()))
-
- if USE_DB: db = DispenseDatabase(v, cf.DBServer, cf.DBName, cf.DBUser, cf.DBPassword)
-
- setup_idlers(v)
- reset_idler(v, vstatus)
-
- # This main loop was hideous and the work of the devil.
- # This has now been fixed (mostly) - mtearle
- #
- #
- # notes for later surgery
- # (event, counter, ' ')
- # V
- # d[ ] = (method)
- #
- # ( return state - not currently implemented )
-
- while True:
- if USE_DB:
- try:
- db.handle_events()
- except DispenseDatabaseException, e:
- logging.error('Database error: '+str(e))