factored out python2/3 differences on raw_input
1 parent de0e8ed commit 2e2dfb3e07b759301fd32541a13afbcf1d24ca85
@David Whale David Whale authored on 16 May 2016
Showing 1 changed file
View
11
src/legacy.py
 
# delay in seconds between each application switch message
APP_DELAY = 1
 
try:
readin = raw_input # python 2
except NameError:
readin = input # python 3
 
 
#----- TEST APPLICATION -------------------------------------------------------
 
# Prebuild all possible message up front, to make switching code faster
 
 
def get_yes_no():
"""Get a simple yes or no answer"""
answer = raw_input() # python2
answer = readin()
if answer.upper() in ['Y', 'YES']:
return True
return False
 
print("Learn switch %d?" % switch_no)
y = get_yes_no()
if y:
print("Press the LEARN button on any switch %d for 5 secs until LED flashes" % switch_no)
raw_input("press ENTER when LED is flashing")
readin("press ENTER when LED is flashing")
 
print("ON")
radio.transmit(ON_MSGS[switch_no], OUTER_TIMES, INNER_TIMES)
time.sleep(APP_DELAY)
 
def pattern_test():
"""Test all patterns"""
while True:
p = raw_input("number 0..F")
p = readin("number 0..F")
p = int(p, 16)
msg = encoder.build_test_message(p)
print("pattern %s payload %s" % (str(hex(p)), encoder.ashex(msg)))
radio.send_payload(msg, OUTER_TIMES, INNER_TIMES)