diff options
| author | Selene ToyKeeper | 2023-11-02 17:16:25 -0600 |
|---|---|---|
| committer | Selene ToyKeeper | 2023-11-02 17:16:25 -0600 |
| commit | 7cb4fe0944b839f28dfd96a88a772cd6a8b58019 (patch) | |
| tree | 8d3b203f1650edc28b1f67e1589e3bc870b33fa6 /bin/steps.py | |
| parent | added LICENSE (GPLv3) (diff) | |
| download | anduril-7cb4fe0944b839f28dfd96a88a772cd6a8b58019.tar.gz anduril-7cb4fe0944b839f28dfd96a88a772cd6a8b58019.tar.bz2 anduril-7cb4fe0944b839f28dfd96a88a772cd6a8b58019.zip | |
reorganized project files (part 1)
(just moved files, didn't change the contents yet,
and nothing will work without updating #includes and build scripts and stuff)
Diffstat (limited to 'bin/steps.py')
| -rwxr-xr-x | bin/steps.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/bin/steps.py b/bin/steps.py new file mode 100755 index 0000000..e19c9a6 --- /dev/null +++ b/bin/steps.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python + +"""steps.py: Calculate the stepped ramp levels used by Anduril. +Usage: steps.py floor ceiling num_steps +For example: + > ./steps.py 1 150 3 + 1: 1 + 2: 75 + 3: 150 +""" + +def main(args): + floor, ceil, steps = [int(x) for x in args[:3]] + for i in range(steps): + guess = floor + (i * (float(ceil-floor)/(steps-1))) + this = nearest_level(guess, floor, ceil, steps) + #print('%i: %i (guess: %i)' % (i+1, this, guess)) + print('%i: %i' % (i+1, this)) + + +def nearest_level(target, floor, ceil, steps): + """Copied/adapted from anduril.c""" + # bounds check + # using int16_t here saves us a bunch of logic elsewhere, + # by allowing us to correct for numbers < 0 or > 255 in one central place + mode_min = floor; + mode_max = ceil; + + if (target < mode_min): return mode_min; + if (target > mode_max): return mode_max; + # the rest isn't relevant for smooth ramping + #if (! ramp_style): return target; + + ramp_range = ceil - floor; + ramp_discrete_step_size = int(ramp_range / (steps-1)); + this_level = floor; + + for i in range(steps): + this_level = floor + (i * int(ramp_range) / (steps-1)); + diff = int(target - this_level); + if (diff < 0): diff = -diff; + if (diff <= (ramp_discrete_step_size>>1)): + return this_level; + + return this_level; + + +if __name__ == "__main__": + import sys + main(sys.argv[1:]) + |
