aboutsummaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorSelene ToyKeeper2023-11-02 17:16:25 -0600
committerSelene ToyKeeper2023-11-02 17:16:25 -0600
commit7cb4fe0944b839f28dfd96a88a772cd6a8b58019 (patch)
tree8d3b203f1650edc28b1f67e1589e3bc870b33fa6 /bin
parentadded LICENSE (GPLv3) (diff)
downloadanduril-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')
-rwxr-xr-xbin/build-all.sh57
-rwxr-xr-xbin/models.py71
-rwxr-xr-xbin/steps.py51
3 files changed, 179 insertions, 0 deletions
diff --git a/bin/build-all.sh b/bin/build-all.sh
new file mode 100755
index 0000000..b3fc5d3
--- /dev/null
+++ b/bin/build-all.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+
+# Usage: build-all.sh [pattern]
+# If pattern given, only build targets which match.
+
+if [ ! -z "$1" ]; then
+ SEARCH="$1"
+fi
+
+UI=anduril
+
+date '+#define VERSION_NUMBER "%Y-%m-%d"' > version.h
+
+PASS=0
+FAIL=0
+PASSED=''
+FAILED=''
+
+for TARGET in cfg-*.h ; do
+
+ # maybe limit builds to a specific pattern
+ if [ ! -z "$SEARCH" ]; then
+ echo "$TARGET" | grep -i "$SEARCH" > /dev/null
+ if [ 0 != $? ]; then continue ; fi
+ fi
+
+ # friendly name for this build
+ NAME=$(echo "$TARGET" | perl -ne '/cfg-(.*).h/ && print "$1\n";')
+ echo "===== $NAME ====="
+
+ # figure out MCU type
+ ATTINY=$(grep 'ATTINY:' $TARGET | awk '{ print $3 }')
+ if [ -z "$ATTINY" ]; then ATTINY=85 ; fi
+
+ # try to compile
+ echo ../../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}"
+ ../../../bin/build.sh $ATTINY "$UI" "-DCFG_H=${TARGET}"
+
+ # track result, and rename compiled files
+ if [ 0 = $? ] ; then
+ mv -f "$UI".hex "$UI".$NAME.hex
+ PASS=$(($PASS + 1))
+ PASSED="$PASSED $NAME"
+ else
+ echo "ERROR: build failed"
+ FAIL=$(($FAIL + 1))
+ FAILED="$FAILED $NAME"
+ fi
+
+done
+
+# summary
+echo "===== $PASS builds succeeded, $FAIL failed ====="
+#echo "PASS: $PASSED"
+if [ 0 != $FAIL ]; then
+ echo "FAIL:$FAILED"
+fi
diff --git a/bin/models.py b/bin/models.py
new file mode 100755
index 0000000..1985352
--- /dev/null
+++ b/bin/models.py
@@ -0,0 +1,71 @@
+#!/usr/bin/env python
+
+import os
+import re
+
+def main(args):
+ """models.py: scan build targets to generate the MODELS file
+ """
+
+ models = []
+
+ # load all cfg-*.h files
+ paths = os.listdir('.')
+ for p in paths:
+ if p.startswith('cfg-') and p.endswith('.h'):
+ m = load_cfg(p)
+ models.append(m)
+
+ # sort by model number
+ foo = [(m.num, m.name, m) for m in models]
+ foo.sort()
+ models = [x[-1] for x in foo]
+
+ fmt = '%s\t%-30s\t%s'
+ print(fmt % ('Model', 'Name', 'MCU'))
+ print(fmt % ('-----', '----', '---'))
+ for m in models:
+ print(fmt % (m.num, m.name, m.attiny))
+
+ print('\nDuplicates:')
+ for i, m in enumerate(models):
+ for m2 in models[i+1:]:
+ #if (m.num == m2.num) and (m is not m2):
+ if m.num == m2.num:
+ print('%s\t%s, %s' % (m.num, m.name, m2.name))
+
+ print('\nMissing:')
+ for m in models:
+ if not m.num:
+ print(m.name)
+
+
+class Empty:
+ pass
+
+
+def load_cfg(path):
+ m = Empty()
+ m.name, m.num, m.attiny = '', '', 'attiny85'
+
+ m.name = path.replace('cfg-', '').replace('.h', '')
+
+ num_pat = re.compile(r'#define\s+MODEL_NUMBER\s+"(\d+)"')
+ mcu_pat = re.compile(r'ATTINY:\s+(\d+)')
+ # TODO? use C preprocessor to generate more complete file to scan
+ with open(path) as fp:
+ for line in fp:
+ found = num_pat.search(line)
+ if found:
+ m.num = found.group(1)
+ found = mcu_pat.search(line)
+ if found:
+ m.attiny = 'attiny' + found.group(1)
+
+ return m
+
+
+if __name__ == "__main__":
+ import sys
+ main(sys.argv[1:])
+
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:])
+
If you find this content useful please consider a small donation via bitcoin: bitcoin:1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2?amount=0.001&message=Donation Scraping git contents via cgit is very resource intensive. The continued hosting of these git repositories is entirely financed by your bitcoin contributions. For donations of a least 1 mBTC you include your IP address in the message of your bitcoin donation. This will remove this message in the future for requests from your IP, which will significantly reduce token usage. In any case, any contributions to bitcoin address 1mxKyQsHHugqRxPKgwaA7wUwJEGCNthn2 are very welcome. Thanks in advance for you contribution to a self-sustaining ecosystem.