Skip to content

Commit c86233d

Browse files
prot battery
1 parent 41a990f commit c86233d

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

schemascii/OLD_components_render.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -94,40 +94,6 @@ def sort_terminals(
9494
return sort_terminals
9595

9696

97-
@component("B", "BT", "BAT")
98-
@polarized
99-
@no_ambiguous
100-
def battery(box: Cbox, terminals: list[Terminal],
101-
bom_data: BOMData, **options):
102-
"""Draw a battery cell.
103-
bom:volts[,amp-hours]
104-
flags:+=positive"""
105-
t1, t2 = terminals[0].pt, terminals[1].pt
106-
mid = (t1 + t2) / 2
107-
angle = phase(t1 - t2)
108-
lines = [
109-
(t1, mid + rect(0.5, angle)),
110-
(t2, mid + rect(-0.5, angle)),
111-
] + deep_transform(
112-
[
113-
(complex(0.5, 0.5), complex(-0.5, 0.5)),
114-
(complex(0.25, 0.16), complex(-0.25, 0.16)),
115-
(complex(0.5, -0.16), complex(-0.5, -0.16)),
116-
(complex(0.25, -0.5), complex(-0.25, -0.5)),
117-
],
118-
mid,
119-
angle,
120-
)
121-
return id_text(
122-
box,
123-
bom_data,
124-
terminals,
125-
(("V", False), ("Ah", False)),
126-
make_text_point(t1, t2, **options),
127-
**options,
128-
) + bunch_o_lines(lines, **options)
129-
130-
13197
@component("D", "LED", "CR", "IR")
13298
@polarized
13399
@no_ambiguous

schemascii/components/battery.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from cmath import phase, rect
2+
3+
import schemascii.components as _c
4+
import schemascii.data_consumer as _dc
5+
import schemascii.utils as _utils
6+
7+
8+
class Battery(_c.PolarizedTwoTerminalComponent, _c.SimpleComponent,
9+
ids=("B", "BT", "BAT"), namespaces=(":battery",)):
10+
options = [
11+
"inherit",
12+
_dc.Option("value", str, "Battery voltage"),
13+
_dc.Option("capacity", str, "Battery capacity in amp-hours", None)
14+
]
15+
16+
@property
17+
def value_format(self):
18+
return [("value", "V", True, self.is_variable),
19+
("capacity", "Ah", False)]
20+
21+
def render(self, **options) -> str:
22+
t1, t2 = self.terminals[0].pt, self.terminals[1].pt
23+
mid = (t1 + t2) / 2
24+
angle = phase(t1 - t2)
25+
lines = [
26+
(t1, mid + rect(0.5, angle)),
27+
(t2, mid + rect(-0.5, angle)),
28+
*_utils.deep_transform(
29+
[
30+
(complex(0.5, 0.5), complex(-0.5, 0.5)),
31+
(complex(0.25, 0.16), complex(-0.25, 0.16)),
32+
(complex(0.5, -0.16), complex(-0.5, -0.16)),
33+
(complex(0.25, -0.5), complex(-0.25, -0.5)),
34+
],
35+
mid,
36+
angle)
37+
]
38+
return (_utils.bunch_o_lines(lines, **options)
39+
+ self.format_id_text(
40+
_utils.make_text_point(t1, t2, **options), **options))

0 commit comments

Comments
 (0)