7
7
from pathlib import Path
8
8
9
9
import pcbnew
10
- from jinja2 import Template
11
10
from kbplacer .defaults import DEFAULT_DIODE_POSITION , ZERO_POSITION
12
11
from kbplacer .element_position import ElementInfo , PositionOption
12
+ from kbplacer .kle_serial import get_keyboard
13
13
from kbplacer .key_placer import KeyPlacer
14
14
from kbplacer .template_copier import TemplateCopier
15
15
from kinet2pcb import kinet2pcb
21
21
__all__ = ["new_pcb" ]
22
22
23
23
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
-
67
24
def run_element_placement (pcb_path , layout , settings ):
68
25
diode = ElementInfo ("D{}" , PositionOption .DEFAULT , DEFAULT_DIODE_POSITION , "" )
69
26
route_switches_with_diodes = settings ["routing" ] == "Full"
@@ -240,8 +197,6 @@ def new_pcb(task_id, task_request, update_state_callback):
240
197
layout = task_request ["layout" ]
241
198
settings = task_request ["settings" ]
242
199
243
- switch_library = settings ["switchLibrary" ]
244
-
245
200
project_name = layout ["meta" ]["name" ]
246
201
project_name = "keyboard" if project_name == "" else project_name
247
202
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):
253
208
configure_loggers (log_path )
254
209
255
210
update_state_callback (10 )
256
- prepare_project (project_full_path , project_name , switch_library )
257
-
258
211
sanitize_keys (layout ["keys" ])
259
212
260
213
pcb_file = f"{ project_full_path } /{ project_name } .kicad_pcb"
@@ -275,14 +228,12 @@ def new_pcb(task_id, task_request, update_state_callback):
275
228
generate_netlist (netlist_file )
276
229
277
230
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 )
286
237
287
238
update_state_callback (40 )
288
239
run_element_placement (pcb_file , layout , settings )
0 commit comments