aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2022-03-08 17:14:22 +0100
committerlonkaars <loek@pipeframe.xyz>2022-03-08 17:14:22 +0100
commit8a0a64ab90fb853c3cb235316081f3b423785cae (patch)
treecece85a81453f31f3ca49f1dbd6ee8619bad18bc /scripts
parentff222422cdef41f96f6a2d2508c033a7cc7a91e9 (diff)
more schematics
Diffstat (limited to 'scripts')
-rw-r--r--scripts/resistorcalc/available177
-rw-r--r--scripts/resistorcalc/input21
-rw-r--r--scripts/resistorcalc/output21
-rwxr-xr-xscripts/resistorcalc/resistorcalc.py56
4 files changed, 275 insertions, 0 deletions
diff --git a/scripts/resistorcalc/available b/scripts/resistorcalc/available
new file mode 100644
index 0000000..f0106f2
--- /dev/null
+++ b/scripts/resistorcalc/available
@@ -0,0 +1,177 @@
+1.0
+10
+100
+1.0K
+10K
+100K
+1.0M
+10M
+1.1
+11
+110
+1.1K
+11K
+110K
+1.1M
+11M
+1.2
+12
+120
+1.2K
+12K
+120K
+1.2M
+12M
+1.3
+13
+130
+1.3K
+13K
+130K
+1.3M
+13M
+1.5
+15
+150
+1.5K
+15K
+150K
+1.5M
+15M
+1.6
+16
+160
+1.6K
+16K
+160K
+1.6M
+16M
+1.8
+18
+180
+1.8K
+18K
+180K
+1.8M
+18M
+2.0
+20
+200
+2.0K
+20K
+200K
+2.0M
+20M
+2.2
+22
+220
+2.2K
+22K
+220K
+2.2M
+22M
+2.4
+24
+240
+2.4K
+24K
+240K
+2.4M
+2.7
+27
+270
+2.7K
+27K
+270K
+2.7M
+3.0
+30
+300
+3.0K
+30K
+300K
+3.0M
+3.3
+33
+330
+3.3K
+33K
+330K
+3.3M
+3.6
+36
+360
+3.6K
+36K
+360K
+3.6M
+3.9
+39
+390
+3.9K
+39K
+390K
+3.9M
+4.3
+43
+430
+4.3K
+43K
+430K
+4.3M
+4.7
+47
+470
+4.7K
+47K
+470K
+4.7M
+5.1
+51
+510
+5.1K
+51K
+510K
+5.1M
+5.6
+56
+560
+5.6K
+56K
+560K
+5.6M
+6.2
+62
+620
+6.2K
+62K
+620K
+6.2M
+6.8
+68
+680
+6.8K
+68K
+680K
+6.8M
+7.5
+75
+750
+7.5K
+75K
+750K
+7.5M
+8.2
+82
+820
+8.2K
+82K
+820K
+8.2M
+9.1
+91
+910
+9.1K
+91K
+910K
+9.1M
diff --git a/scripts/resistorcalc/input b/scripts/resistorcalc/input
new file mode 100644
index 0000000..7fa8766
--- /dev/null
+++ b/scripts/resistorcalc/input
@@ -0,0 +1,21 @@
+10140
+570
+1120
+600
+790
+1000
+730
+1030
+1110
+1300
+1410
+1370
+1580
+1790
+1800
+1920
+2160
+2240
+2230
+2860
+12250
diff --git a/scripts/resistorcalc/output b/scripts/resistorcalc/output
new file mode 100644
index 0000000..f8c3608
--- /dev/null
+++ b/scripts/resistorcalc/output
@@ -0,0 +1,21 @@
+10.0k + 130.0 = 10130.0 Ohm --> off by -10.0
+560.0 + 10.0 = 570.0 Ohm --> off by 0.0
+1.1k + 20.0 = 1120.0 Ohm --> off by 0.0
+560.0 + 39.0 = 599.0 Ohm --> off by -1.0
+750.0 + 39.0 = 789.0 Ohm --> off by -1.0
+1.0k = 1000.0 Ohm --> off by 0.0
+680.0 + 47.0 = 727.0 Ohm --> off by -3.0
+1.0k + 30.0 = 1030.0 Ohm --> off by 0.0
+1.1k + 10.0 = 1110.0 Ohm --> off by 0.0
+1.3k = 1300.0 Ohm --> off by 0.0
+1.3k + 110.0 = 1410.0 Ohm --> off by 0.0
+1.3k + 68.0 = 1368.0 Ohm --> off by -2.0
+1.5k + 75.0 = 1575.0 Ohm --> off by -5.0
+1.6k + 180.0 = 1780.0 Ohm --> off by -10.0
+1.8k = 1800.0 Ohm --> off by 0.0
+1.8k + 120.0 = 1920.0 Ohm --> off by 0.0
+2.0k + 160.0 = 2160.0 Ohm --> off by 0.0
+2.2k + 39.0 = 2239.0 Ohm --> off by -1.0
+2.2k + 30.0 = 2230.0 Ohm --> off by 0.0
+2.7k + 160.0 = 2860.0 Ohm --> off by 0.0
+12.0k + 240.0 = 12240.0 Ohm --> off by -10.0
diff --git a/scripts/resistorcalc/resistorcalc.py b/scripts/resistorcalc/resistorcalc.py
new file mode 100755
index 0000000..630720e
--- /dev/null
+++ b/scripts/resistorcalc/resistorcalc.py
@@ -0,0 +1,56 @@
+#!/bin/python3
+
+from sys import stdin
+from math import log, floor
+
+MAX_RESISTORS = 2
+
+def expand(input):
+ input = input.lower()
+ result = 0.0
+ multiplier = 1
+ multipliers = {
+ 'k': 1e3,
+ 'm': 1e6
+ }
+ if not input[-1].isdigit():
+ multiplier = multipliers.get(input[-1]) or 1
+ input = input[:-1]
+ result = float(input)
+ return result * multiplier
+
+def get_available():
+ with open("./available", 'r') as file:
+ content = file.readlines()
+ return [expand(line.strip()) for line in content]
+
+def calc_resistors(target, available):
+ resistors = []
+ for x in range(MAX_RESISTORS):
+ for resistor in available:
+ if resistor > target: continue
+ target -= resistor
+ resistors.append(resistor)
+ break
+ return resistors
+
+def format_resistor_value(num):
+ multipliers = ['', 'k', 'm']
+ multiplier = floor(log(num, 1e3))
+ return f"{(num / (1e3 ** multiplier)):.1f}{multipliers[multiplier]}"
+
+def pretty_print(values, target):
+ pretty_values = [format_resistor_value(res) for res in values]
+ print(f"{' + '.join(pretty_values)} = {sum(values):.1f} Ohm --> off by {(sum(values) - target):.1f}")
+
+def main():
+ available = get_available()
+ available.sort(reverse=True)
+ for line in stdin:
+ if line == '': break
+ line = line.strip()
+ resistors = calc_resistors(float(line), available)
+ pretty_print(resistors, float(line))
+
+if __name__ == "__main__":
+ main()