Skip to content

Commit 17daeed

Browse files
committed
Stop bundling switch library with project archive
From now on, produced zip package will not contain keyboard switches footprints library. There are following reasons: - footprints are cached in kicad_pcb file - user can easily install required library itself using KiCad plugin manager (which was not available when this project started) - final package size will be much smaller - there is no need to generate `fp-lib-table` file Also stop generating kicad_pro file because it will be automatically added by `board.SaveBoard` function.
1 parent f055b79 commit 17daeed

File tree

6 files changed

+19
-135
lines changed

6 files changed

+19
-135
lines changed

docs/src/guide.md

+5-12
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Recommended workflow contains following steps:
1616
- Go to [keyboard-tools's](http://keyboard-tools.xyz/) KiCad Project Generator
1717
tab (1), choose project options (2) and upload keyboard layout (3).
1818

19-
In this example I decided to use *Cherry MX* footprints and I enabled
19+
In this example I decided to use *Cherry MX* footprints and I enabled
2020
routing. Because I did not used key annotations (see
2121
[this](features#matrix-position-assignment)) I used *Automatic* matrix option.
2222

@@ -25,17 +25,10 @@ Recommended workflow contains following steps:
2525

2626
![frontend](./assets/guide/frontend.png)
2727

28-
- Download and unzip project. Open project located in `keyboard` directory.
29-
It should contain following structure:
28+
- Download and unzip project. There will be two directories. One for `logs`
29+
and the other for KiCad files.
3030

31-
![kicad-project](./assets/guide/kicad-project.png)
32-
33-
::: tip
34-
Generated project has entire selected switch library bundled in.
35-
This makes footprint replacement easy.
36-
:::
37-
38-
`keyboard.kicad_pcb` file should have switches and diodes placed according
31+
`*.kicad_pcb` file should have switches and diodes placed according
3932
to provided layout like this:
4033

4134
![pcb](./assets/guide/pcb.png)
@@ -81,7 +74,7 @@ Recommended workflow contains following steps:
8174
otherwise key matrix netlist will be overwritten (by default, KiCad names
8275
netlist same as project).
8376

84-
- Open `keyboard.kicad_pcb` and load microcontroller netlist.
77+
- Open `*.kicad_pcb` and load microcontroller netlist.
8578

8679
![load-netlist](./assets/guide/load-netlist.png)
8780

kicad-api/Dockerfile

+7-4
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ FROM admwscki/kicad-kbplacer:0.8
22

33
ENV PATH="/kicad/.local/bin:${PATH}"
44

5-
RUN mkdir switch-libs \
6-
&& cd switch-libs \
7-
&& mkdir keyswitch-kicad-library && cd keyswitch-kicad-library \
5+
# simulate installation with KiCad's PCM (we care only about footprints):
6+
RUN cd /kicad/.local/share/kicad/7.0/3rdparty \
7+
&& mkdir -p footprints \
8+
&& mkdir tmp && cd tmp \
89
&& wget https://github.com/kiswitch/keyswitch-kicad-library/releases/download/v2.4/keyswitch-kicad-library.zip \
910
&& echo "b38d56323acb91ad660567340ca938c5b4a83a27eea52308ef14aa7857b0071b keyswitch-kicad-library.zip" | sha256sum -c \
1011
&& unzip keyswitch-kicad-library.zip \
11-
&& rm keyswitch-kicad-library.zip
12+
&& rm keyswitch-kicad-library.zip \
13+
&& mv footprints ../footprints/com_github_perigoso_keyswitch-kicad-library \
14+
&& cd .. && rm -rf tmp
1215

1316
RUN mkdir templates \
1417
&& cd templates \

kicad-api/requirements.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
celery==5.3.6
2-
flask==3.0.0
32
git+https://github.com/adamws/kinet2pcb@1fc8a4b67e9fbb25beade950c80d3cdc8d868c23
43
minio==7.1.16
54
PcbDraw==1.1.2

kicad-api/src/keyboard.kicad_pro.template

-61
This file was deleted.

kicad-api/src/kicad.py

+7-56
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
from pathlib import Path
88

99
import pcbnew
10-
from jinja2 import Template
1110
from kbplacer.defaults import DEFAULT_DIODE_POSITION, ZERO_POSITION
1211
from kbplacer.element_position import ElementInfo, PositionOption
12+
from kbplacer.kle_serial import get_keyboard
1313
from kbplacer.key_placer import KeyPlacer
1414
from kbplacer.template_copier import TemplateCopier
1515
from kinet2pcb import kinet2pcb
@@ -21,49 +21,6 @@
2121
__all__ = ["new_pcb"]
2222

2323

24-
def prepare_project(project_full_path, project_name, switch_library):
25-
tm = Template(
26-
"(sym_lib_table\n{% for sym_lib in sym_libs -%}{{ sym_lib }}\n{% endfor %})"
27-
)
28-
sym_lib_table = tm.render(sym_libs=[])
29-
with open(f"{project_full_path}/sym-lib-table", "w") as f:
30-
f.write(sym_lib_table)
31-
32-
tm = Template(
33-
"(fp_lib_table\n{% for fp_lib in fp_libs -%}{{ fp_lib }}\n{% endfor %})"
34-
)
35-
if switch_library == "kiswitch/keyswitch-kicad-library":
36-
prefix = "${KIPRJMOD}/libs/keyswitch-kicad-library/footprints"
37-
fp_lib_table = tm.render(
38-
fp_libs=[
39-
f'(lib (name Switch_Keyboard_Cherry_MX)(type KiCad)(uri {prefix}/Switch_Keyboard_Cherry_MX.pretty)(options "")(descr ""))',
40-
f'(lib (name Switch_Keyboard_Alps_Matias)(type KiCad)(uri {prefix}/Switch_Keyboard_Alps_Matias.pretty)(options "")(descr ""))',
41-
f'(lib (name Switch_Keyboard_Hybrid)(type KiCad)(uri {prefix}/Switch_Keyboard_Hybrid.pretty)(options "")(descr ""))',
42-
f'(lib (name Mounting_Keyboard_Stabilizer)(type KiCad)(uri {prefix}/Mounting_Keyboard_Stabilizer.pretty)(options "")(descr ""))',
43-
]
44-
)
45-
shutil.copytree(
46-
"switch-libs/keyswitch-kicad-library",
47-
f"{project_full_path}/libs/keyswitch-kicad-library",
48-
)
49-
else:
50-
msg = "Unsupported switch library"
51-
raise Exception(msg)
52-
53-
with open(f"{project_full_path}/fp-lib-table", "w") as f:
54-
f.write(fp_lib_table)
55-
56-
with open(f"{project_full_path}/{project_name}.kicad_pcb", "w") as f:
57-
f.write('(kicad_pcb (version 4) (host kicad "dummy file") )')
58-
59-
file_path = os.path.dirname(os.path.realpath(__file__))
60-
with open(f"{file_path}/keyboard.kicad_pro.template") as f:
61-
template = Template(f.read())
62-
result = template.render(project_name=project_name)
63-
with open(f"{project_full_path}/{project_name}.kicad_pro", "w") as f:
64-
f.write(result)
65-
66-
6724
def run_element_placement(pcb_path, layout, settings):
6825
diode = ElementInfo("D{}", PositionOption.DEFAULT, DEFAULT_DIODE_POSITION, "")
6926
route_switches_with_diodes = settings["routing"] == "Full"
@@ -240,8 +197,6 @@ def new_pcb(task_id, task_request, update_state_callback):
240197
layout = task_request["layout"]
241198
settings = task_request["settings"]
242199

243-
switch_library = settings["switchLibrary"]
244-
245200
project_name = layout["meta"]["name"]
246201
project_name = "keyboard" if project_name == "" else project_name
247202
project_full_path = str(Path(task_id).joinpath(project_name).absolute())
@@ -253,8 +208,6 @@ def new_pcb(task_id, task_request, update_state_callback):
253208
configure_loggers(log_path)
254209

255210
update_state_callback(10)
256-
prepare_project(project_full_path, project_name, switch_library)
257-
258211
sanitize_keys(layout["keys"])
259212

260213
pcb_file = f"{project_full_path}/{project_name}.kicad_pcb"
@@ -275,14 +228,12 @@ def new_pcb(task_id, task_request, update_state_callback):
275228
generate_netlist(netlist_file)
276229

277230
update_state_callback(30)
278-
kinet2pcb(
279-
netlist_file,
280-
pcb_file,
281-
[
282-
"/usr/share/kicad/footprints",
283-
f"{project_full_path}/libs/keyswitch-kicad-library/footprints",
284-
],
285-
)
231+
libraries = ["/usr/share/kicad/footprints"]
232+
footprints = Path(f"{Path.home()}/.local/share/kicad/7.0/3rdparty/footprints")
233+
for path in footprints.iterdir():
234+
if path.is_dir():
235+
libraries.append(str(path))
236+
kinet2pcb(netlist_file, pcb_file, libraries)
286237

287238
update_state_callback(40)
288239
run_element_placement(pcb_file, layout, settings)

tests/e2e-tests/test_layout_uploads.py

-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ def assert_zip_content(zipfile):
2020
files_in_zip = zipfile.namelist()
2121
assert "logs/build.log" in files_in_zip
2222
expected_in_keyboard_dir = [
23-
"sym-lib-table",
2423
"keyboard.net",
2524
"keyboard.kicad_pro",
2625
"keyboard.kicad_pcb",

0 commit comments

Comments
 (0)