aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSelene ToyKeeper2017-10-14 14:57:38 -0600
committerSelene ToyKeeper2017-10-14 14:57:38 -0600
commitc725c38b36539c223cb84589c4d59452478ef595 (patch)
tree1b87237c856d049a4b218263767272e41ecd4101
parentAdded my firmware thread to the readme. (diff)
downloadanduril-c725c38b36539c223cb84589c4d59452478ef595.tar.gz
anduril-c725c38b36539c223cb84589c4d59452478ef595.tar.bz2
anduril-c725c38b36539c223cb84589c4d59452478ef595.zip
Made level_calc.py support both python2.7 and python3.
Fixed bug when user specified 'FET' instead of 'fet'.
-rwxr-xr-xbin/level_calc.py25
1 files changed, 19 insertions, 6 deletions
diff --git a/bin/level_calc.py b/bin/level_calc.py
index de52998..4dc1356 100755
--- a/bin/level_calc.py
+++ b/bin/level_calc.py
@@ -1,5 +1,7 @@
#!/usr/bin/env python
+from __future__ import print_function
+
import math
interactive = False
@@ -41,6 +43,9 @@ def main(args):
chan = Empty()
chan.pwm_max = 255
ask(questions_per_channel, chan)
+ chan.type = chan.type.upper()
+ if chan.type not in ('7135', 'FET'):
+ raise ValueError('Invalid channel type: %s' % (chan.type,))
channels.append(chan)
# calculate total output of all previous channels
@@ -54,8 +59,8 @@ def main(args):
multi_pwm(answers, channels)
if interactive: # Wait on exit, in case user invoked us by clicking an icon
- print 'Press Enter to exit:'
- raw_input()
+ print('Press Enter to exit:')
+ input_text()
class Empty:
@@ -72,7 +77,7 @@ def multi_pwm(answers, channels):
lm_max = channels[-1].lm_max
else:
# this would be a stupid driver design
- raise ValueError, "FET channel isn't the most powerful?"
+ raise ValueError("FET channel isn't the most powerful?")
visual_min = invpower(lm_min)
visual_max = invpower(lm_max)
@@ -96,7 +101,7 @@ def multi_pwm(answers, channels):
# This shouldn't happen, the FET is assumed to be the highest channel
if channel.type == 'FET':
# this would be a stupid driver design
- raise ValueError, "FET channel isn't the most powerful?"
+ raise ValueError("FET channel isn't the most powerful?")
# Handle FET turbo specially
if (i == (answers.num_levels - 1)) \
@@ -149,8 +154,8 @@ def get_value(text, default, args):
else:
global interactive
interactive = True
- print text, '(%s)' % (default),
- result = raw_input()
+ print(text + ' (%s) ' % (default), end='')
+ result = input_text()
result = result.strip()
return result
@@ -171,6 +176,14 @@ def invpower(x):
#return math.log(x, 2.0)
+def input_text():
+ try:
+ value = raw_input() # python2
+ except NameError:
+ value = input() # python3
+ return value
+
+
if __name__ == "__main__":
import sys
main(sys.argv[1:])