Skip to content

Commit a31e80e

Browse files
authored
Merge pull request #28 from Finomnis/support_small_values
Add support for smaller values; add pre-rendered versions
2 parents 1f6a9aa + 37ac115 commit a31e80e

5 files changed

Lines changed: 73 additions & 59 deletions

File tree

CommonValuesAvery5260.pdf

210 KB
Binary file not shown.

CommonValuesAveryL7157.pdf

218 KB
Binary file not shown.

Example.pdf

-60.5 KB
Binary file not shown.

LabelGenerator.py

Lines changed: 70 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from typing import Tuple, Union, Optional, List, Mapping
1414

15-
ResistorList = List[Union[Optional[float], List[Optional[float]]]]
15+
ResistorList = Union[List[float], List[Union[Optional[float], List[Optional[float]]]]]
1616

1717

1818
def load_font(font_name: str) -> None:
@@ -333,7 +333,20 @@ def draw_resistor_colorcode(
333333
tolerance_value: Optional[float],
334334
) -> None:
335335

336-
if value.ohms_exp < num_codes - 4:
336+
resistance_values: List[int] = []
337+
for i in range(num_codes-1):
338+
stripe_value = value.ohms_val
339+
for _ in range(2-i):
340+
stripe_value //= 10
341+
stripe_value %= 10
342+
resistance_values.append(stripe_value)
343+
exp_value = value.ohms_exp + 2 - num_codes
344+
345+
while exp_value < -2 and resistance_values[-1] == 0:
346+
exp_value += 1
347+
resistance_values = [0] + resistance_values[:-1]
348+
349+
if exp_value < -2:
337350
return
338351

339352
border = height/6
@@ -357,16 +370,7 @@ def draw_resistor_colorcode(
357370
height - 2 * border,
358371
0)
359372
else:
360-
for i in range(num_codes):
361-
362-
if i == num_codes - 1:
363-
stripe_value = value.ohms_exp + 2 - num_codes
364-
else:
365-
stripe_value = value.ohms_val
366-
for _ in range(2-i):
367-
stripe_value //= 10
368-
stripe_value %= 10
369-
373+
for i, stripe_value in enumerate(resistance_values + [exp_value]):
370374
draw_resistor_stripe(c,
371375
x + border + corner + stripe_width / 2 + 2 * stripe_width * i,
372376
y + border,
@@ -446,34 +450,35 @@ def get_4digit_code(value: ResistorValue) -> str:
446450
return ""
447451

448452

449-
def get_eia98_code(value: ResistorValue) -> str:
450-
eia98_coding_table = {
451-
100: "01", 178: "25", 316: "49", 562: "73",
452-
102: "02", 182: "26", 324: "50", 576: "74",
453-
105: "03", 187: "27", 332: "51", 590: "75",
454-
107: "04", 191: "28", 340: "52", 604: "76",
455-
110: "05", 196: "29", 348: "53", 619: "77",
456-
113: "06", 200: "30", 357: "54", 634: "78",
457-
115: "07", 205: "31", 365: "55", 649: "79",
458-
118: "08", 210: "32", 374: "56", 665: "80",
459-
121: "09", 215: "33", 383: "57", 681: "81",
460-
124: "10", 221: "34", 392: "58", 698: "82",
461-
127: "11", 226: "35", 402: "59", 715: "83",
462-
130: "12", 232: "36", 412: "60", 732: "84",
463-
133: "13", 237: "37", 422: "61", 750: "85",
464-
137: "14", 243: "38", 432: "62", 768: "86",
465-
140: "15", 249: "39", 442: "63", 787: "87",
466-
143: "16", 255: "40", 453: "64", 806: "88",
467-
147: "17", 261: "41", 464: "65", 825: "89",
468-
150: "18", 267: "42", 475: "66", 845: "90",
469-
154: "19", 274: "43", 487: "67", 866: "91",
470-
158: "20", 280: "44", 499: "68", 887: "92",
471-
162: "21", 287: "45", 511: "69", 909: "93",
472-
165: "22", 294: "46", 523: "70", 931: "94",
473-
169: "23", 301: "47", 536: "71", 953: "95",
474-
174: "24", 309: "48", 549: "72", 976: "96",
475-
}
453+
eia98_coding_table = {
454+
100: "01", 178: "25", 316: "49", 562: "73",
455+
102: "02", 182: "26", 324: "50", 576: "74",
456+
105: "03", 187: "27", 332: "51", 590: "75",
457+
107: "04", 191: "28", 340: "52", 604: "76",
458+
110: "05", 196: "29", 348: "53", 619: "77",
459+
113: "06", 200: "30", 357: "54", 634: "78",
460+
115: "07", 205: "31", 365: "55", 649: "79",
461+
118: "08", 210: "32", 374: "56", 665: "80",
462+
121: "09", 215: "33", 383: "57", 681: "81",
463+
124: "10", 221: "34", 392: "58", 698: "82",
464+
127: "11", 226: "35", 402: "59", 715: "83",
465+
130: "12", 232: "36", 412: "60", 732: "84",
466+
133: "13", 237: "37", 422: "61", 750: "85",
467+
137: "14", 243: "38", 432: "62", 768: "86",
468+
140: "15", 249: "39", 442: "63", 787: "87",
469+
143: "16", 255: "40", 453: "64", 806: "88",
470+
147: "17", 261: "41", 464: "65", 825: "89",
471+
150: "18", 267: "42", 475: "66", 845: "90",
472+
154: "19", 274: "43", 487: "67", 866: "91",
473+
158: "20", 280: "44", 499: "68", 887: "92",
474+
162: "21", 287: "45", 511: "69", 909: "93",
475+
165: "22", 294: "46", 523: "70", 931: "94",
476+
169: "23", 301: "47", 536: "71", 953: "95",
477+
174: "24", 309: "48", 549: "72", 976: "96",
478+
}
476479

480+
481+
def get_eia98_code(value: ResistorValue) -> str:
477482
if value.ohms_val not in eia98_coding_table:
478483
return ""
479484

@@ -627,11 +632,12 @@ def render_outlines(c: Canvas, layout: PaperConfig) -> None:
627632
#
628633
# The list constants below can be used with the generate_values function to quickly create sets of
629634
# common resistor values.
630-
E12_VALUES = [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2]
631-
E24_COMMON_VALUES = [1.0, 1.2, 1.5, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0,
632-
3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1]
633-
E24_ALL_VALUES = [1.0, 1.1, 1.2, 1.3, 1.5, 1.6, 1.8, 2.0, 2.2, 2.4, 2.7, 3.0,
634-
3.3, 3.6, 3.9, 4.3, 4.7, 5.1, 5.6, 6.2, 6.8, 7.5, 8.2, 9.1]
635+
E12_VALUES = [100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680, 820]
636+
E24_COMMON_VALUES = [100, 120, 150, 180, 200, 220, 240, 270, 300,
637+
330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, 910]
638+
E24_ALL_VALUES = [100, 110, 120, 130, 150, 160, 180, 200, 220, 240, 270, 300,
639+
330, 360, 390, 430, 470, 510, 560, 620, 680, 750, 820, 910]
640+
EIA98_SMD_VALUES = [value for value in eia98_coding_table]
635641

636642

637643
# Scales a list of values by a power of 10. The list may be one of the E constants above, or your
@@ -664,11 +670,15 @@ def scale_values(
664670
# [ 100, 120, 150, 180, 220, 270, 330, 390, 470, 560, 680, 820 ] # 10 ** 2 -> x100
665671
# ]
666672
def generate_values(
667-
series: List[float], # the base series of resistor values
673+
series: List[int], # the base series of resistor values
668674
first_power: int, # the first power of 10 to scale the series by
669675
last_power: int # the last power of 10 to scale the series by
670-
) -> List[List[float]]:
671-
return [scale_values(series, x) for x in range(first_power, last_power)]
676+
) -> List[float]:
677+
return [
678+
value
679+
for x in range(first_power, last_power)
680+
for value in scale_values(list(map(lambda v: v/100, sorted(list(set(series))))), x)
681+
]
672682

673683

674684
def main() -> None:
@@ -687,24 +697,25 @@ def main() -> None:
687697
#
688698
# Add "None" if no label should get generated at a specific position.
689699
# ############################################################################
690-
resistor_values: ResistorList = [
691-
[0, 0.02, .1],
692-
[1, 12, 13],
693-
[210, 220, 330],
694-
[3100, 3200, 3300],
695-
[41000, 42000, 43000],
696-
[510000, None, 530000],
697-
[6100000, 6200000, 6300000],
698-
[71000000, 72000000, 73000000],
699-
[810000000, 820000000, 830000000],
700-
[9100000000, 9200000000, 3300000000],
701-
]
700+
# resistor_values: ResistorList = [
701+
# [0, 0.02, .1],
702+
# [1, 12, 13],
703+
# [210, 220, 330],
704+
# [3100, 3200, 3300],
705+
# [41000, 42000, 43000],
706+
# [510000, None, 530000],
707+
# [6100000, 6200000, 6300000],
708+
# [71000000, 72000000, 73000000],
709+
# [810000000, 820000000, 830000000],
710+
# [9100000000, 9200000000, 3300000000],
711+
# ]
702712

703713
# ############################################################################
704714
# Alternatively, a set of common resistor values can be generated by the
705715
# generate_values function.
706716
# ############################################################################
707717
# resistor_values: ResistorList = [ 0, 0.01 ] + generate_values(E24_COMMON_VALUES, 0, 6)
718+
resistor_values: ResistorList = [0, 0.01, 0.02, 0.03] + generate_values(E12_VALUES+E24_ALL_VALUES, -1, 6) + [1_000_000]
708719

709720
# ############################################################################
710721
# Resistor tolerance.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ The generated labels include:
2323

2424
It will now generate a `ResistorLabels.pdf` that can be used to print onto AVERY 5260/L7157.
2525

26+
For all the non-programmers, there are also pre-generated versions with all
27+
common resistor values for [Avery 5260](./CommonValuesAvery5260.pdf) and [Avery L7157](./CommonValuesAveryL7157.pdf).
28+
2629
# More Details
2730

2831
This is based on an idea from Zach Poff.

0 commit comments

Comments
 (0)