@@ -7,7 +7,12 @@ import { kbpy } from './pythontemplates/kb'
77import { codepy } from './pythontemplates/code'
88import { bootpy } from './pythontemplates/boot'
99import { pog_serialpy } from './pythontemplates/pog_serial'
10- import { connectedKeyboardPort , pogconfigbuffer , writeKeymapViaSerial , writePogConfViaSerial } from './index'
10+ import {
11+ connectedKeyboardPort ,
12+ pogconfigbuffer ,
13+ writeKeymapViaSerial ,
14+ writePogConfViaSerial
15+ } from './index'
1116// save code.py based on pog.json
1217
1318export const saveConfiguration = ( data : string ) => {
@@ -23,65 +28,70 @@ export const saveConfiguration = (data: string) => {
2328 console . log ( 'pog File written successfully\n' )
2429 } )
2530
26- saveKeyboardConfig ( pogConfig ) // initialize files if they dont exist
31+ saveKeyboardConfig ( pogConfig ) // initialize files if they don't exist
2732 handleKeymapSave ( { pogConfig, serial : false } )
2833 }
2934}
3035export const saveKeyboardConfig = ( pogConfig ) => {
31- const coordmapstring = ( ) => {
32- if ( pogConfig . coordMap . length === 0 ) return ''
33- let str = ' coord_mapping = [\n'
34- pogConfig . coordMap . forEach ( ( row ) => {
35- str += ' ' + row . join ( ',' ) + ',\n'
36- } )
37- str += ' ]'
38- return str . replaceAll ( / s p c , / gi, ' ' )
39- }
36+ // TODO: remove at some point from reference
37+ // this is now all moved to the pog.json file
38+
39+ // const coordmapstring = () => {
40+ // if (pogConfig.coordMap.length === 0) return ''
41+ // let str = ' coord_mapping = [\n'
42+ // pogConfig.coordMap.forEach((row) => {
43+ // str += ' ' + row.join(',') + ',\n'
44+ // })
45+ // str += ' ]'
46+ // return str.replaceAll(/spc,/gi, ' ')
47+ // }
4048
4149 // write kb.py for basic config
42- let pinSetup = ``
43- const renderPin = ( pin ) => {
44- if ( pogConfig . pinPefix === 'board' ) return `board.${ pin } `
45- if ( pogConfig . pinPefix === 'gp' ) return `board.GP${ pin } `
46- if ( pogConfig . pinPefix === 'quickpin' ) return `pins[${ pin } ]`
47- return pin
48- }
49- if ( pogConfig . wiringMethod === 'matrix' ) {
50- pinSetup = `
51- col_pins = (${ pogConfig . colPins . map ( ( a ) => renderPin ( a ) ) . join ( ', ' ) } )
52- row_pins = (${ pogConfig . rowPins . map ( ( a ) => renderPin ( a ) ) . join ( ', ' ) } )
53- diode_orientation = DiodeOrientation.${ pogConfig . diodeDirection }
54- ${ coordmapstring ( ) }
55- `
56- } else {
57- pinSetup = `
58- def __init__(self):
59- # create and register the scanner
60- self.matrix = KeysScanner(
61- # require argument:
62- pins=[${ pogConfig . directPins . map ( ( a ) => 'board.GP' + a ) . join ( ', ' ) } ],
63- # optional arguments with defaults:
64- value_when_pressed=False,
65- pull=True,
66- interval=0.02, # Debounce time in floating point seconds
67- max_events=64
68- )
69- `
70- }
71- const quickpinSupport =
72- pogConfig . pinPrefix === 'quickpin'
73- ? `from kmk.quickpin.pro_micro.nice_nano import pinout as pins `
74- : ''
75- const kbConfig = `# KB base config
76- import board
77- from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard
78- from kmk.scanners import DiodeOrientation
79- from kmk.scanners.keypad import KeysScanner
80-
81- class KMKKeyboard(_KMKKeyboard):
82- ${ pinSetup }
83- `
84- console . log ( quickpinSupport )
50+ // let pinSetup = ``
51+ // const renderPin = (pin) => {
52+ // if (pogConfig.pinPefix === 'board') return `board.${pin}`
53+ // if (pogConfig.pinPefix === 'gp') return `board.GP${pin}`
54+ // if (pogConfig.pinPefix === 'quickpin') return `pins[${pin}]`
55+ // return pin
56+ // }
57+ // if (pogConfig.wiringMethod === 'matrix') {
58+ // pinSetup = `
59+ // col_pins = (${pogConfig.colPins.map((a) => renderPin(a)).join(', ')})
60+ // row_pins = (${pogConfig.rowPins.map((a) => renderPin(a)).join(', ')})
61+ // diode_orientation = DiodeOrientation.${pogConfig.diodeDirection}
62+ // ${coordmapstring()}
63+ // `
64+ // } else {
65+ // pinSetup = `
66+ // def __init__(self):
67+ // # create and register the scanner
68+ // self.matrix = KeysScanner(
69+ // # require argument:
70+ // pins=[${pogConfig.directPins.map((a) => 'board.GP' + a).join(', ')}],
71+ // # optional arguments with defaults:
72+ // value_when_pressed=False,
73+ // pull=True,
74+ // interval=0.02, # Debounce time in floating point seconds
75+ // max_events=64
76+ // )
77+ // `
78+ // }
79+ // const quickpinSupport =
80+ // pogConfig.pinPrefix === 'quickpin'
81+ // ? `from kmk.quickpin.pro_micro.nice_nano import pinout as pins `
82+ // : ''
83+ // const kbConfig = `# KB base config
84+ // import board
85+ // from kmk.kmk_keyboard import KMKKeyboard as _KMKKeyboard
86+ // from kmk.scanners import DiodeOrientation
87+ // from kmk.scanners.keypad import KeysScanner
88+ //
89+ // class KMKKeyboard(_KMKKeyboard):
90+ // ${pinSetup}
91+ // `
92+ // console.log(quickpinSupport)
93+
94+ // add option to overwrite files eg. force flash
8595 // add pog helper and keyboard setup
8696
8797 if ( ! fs . existsSync ( currentKeyboard . path + '/kb.py' ) ) {
@@ -124,11 +134,12 @@ class KMKKeyboard(_KMKKeyboard):
124134 }
125135}
126136
127- export const saveCoordMapHelper = ( ) => {
128- fs . writeFile ( currentKeyboard . path + '/coordmaphelper.py' , coordmaphelperpy , ( ) => {
129- console . log ( 'coord map helper File created successfully' )
130- } )
131- }
137+ // is now handled with a flag in pog.json
138+ // export const saveCoordMapHelper = () => {
139+ // fs.writeFile(currentKeyboard.path + '/coordmaphelper.py', coordmaphelperpy, () => {
140+ // console.log('coord map helper File created successfully')
141+ // })
142+ // }
132143
133144export const handleKeymapSave = ( { pogConfig, serial } ) => {
134145 // const codeblockraw = fs.readFileSync(`${keyboardPath}/code.py`, {encoding:'utf8', flag:'r'})
@@ -137,30 +148,18 @@ export const handleKeymapSave = ({ pogConfig, serial }) => {
137148 // console.log(codeblock)
138149 // create basic keymap file
139150 // grab old codeblocks
140- let pythonImports = ''
141- let kmkAddons = ''
142- let codeblock = ''
143- //layers
144- if ( true ) {
145- pythonImports += '\nfrom kmk.modules.layers import Layers\n'
146- kmkAddons += '\nkeyboard.modules.append(Layers())\n'
147- }
148151
149- //media keys
150- if ( true ) {
151- pythonImports += '\nfrom kmk.extensions.media_keys import MediaKeys\n'
152- kmkAddons += '\nkeyboard.extensions.append(MediaKeys())\n'
153- }
154152 // testing encoder enable
155153 if ( pogConfig . encoders && pogConfig . encoders . length !== 0 ) {
156- pythonImports +=
157- '\nfrom kmk.modules.layers import Layers\n' +
158- 'from kmk.modules.encoder import EncoderHandler\n'
159- kmkAddons +=
160- '\nlayers = Layers()\n' +
161- 'encoder_handler = EncoderHandler()\n' +
162- 'keyboard.modules = [layers, encoder_handler]\n'
163-
154+ // pythonImports +=
155+ // '\nfrom kmk.modules.layers import Layers\n' +
156+ // 'from kmk.modules.encoder import EncoderHandler\n'
157+ // kmkAddons +=
158+ // '\nlayers = Layers()\n' +
159+ // 'encoder_handler = EncoderHandler()\n' +
160+ // 'keyboard.modules = [layers, encoder_handler]\n'
161+
162+ // still keeping the option to save the encoder keymap as raw code instead of the lookup
164163 let encoderPins = ''
165164 pogConfig . encoders . forEach ( ( encoder ) => {
166165 encoderPins += `(board.GP${ encoder . pad_a } , board.GP${ encoder . pad_b } , None,),`
@@ -175,42 +174,44 @@ export const handleKeymapSave = ({ pogConfig, serial }) => {
175174 } )
176175 encoderKeymap += '),\n'
177176 } )
178-
179- codeblock +=
180- '# Encoder\n' +
181- 'encoder_handler.pins = (\n' +
182- encoderPins +
183- '\n' +
184- ')\n' +
185- 'encoder_handler.map = [ \n' +
186- encoderKeymap + // layers
187- ']\n'
188177 }
189- const mainConfig = `# Main Keyboard Configuration
190- print("Starting ${ pogConfig . name || 'Keyboard' } ")
191-
192- import board
193- from kb import KMKKeyboard
194- from kmk.modules.tapdance import TapDance
195- ${ pythonImports }
196-
197- keyboard = KMKKeyboard()
198- ${ kmkAddons }
199-
200- tapdance = TapDance()
201- tapdance.tap_time = 200
202- keyboard.modules.append(tapdance)
203-
204- # Keymap
205- from keymap import keymap
206- keyboard.keymap = keymap
207-
208- ${ codeblock }
209-
210- if __name__ == '__main__':
211- keyboard.go()
212- `
213178
179+ // codeblock +=
180+ // '# Encoder\n' +
181+ // 'encoder_handler.pins = (\n' +
182+ // encoderPins +
183+ // '\n' +
184+ // ')\n' +
185+ // 'encoder_handler.map = [ \n' +
186+ // encoderKeymap + // layers
187+ // ']\n'
188+ // }
189+ // const mainConfig = `# Main Keyboard Configuration
190+ // print("Starting ${pogConfig.name || 'Keyboard'}")
191+ //
192+ // import board
193+ // from kb import KMKKeyboard
194+ // from kmk.modules.tapdance import TapDance
195+ // ${pythonImports}
196+ //
197+ // keyboard = KMKKeyboard()
198+ // ${kmkAddons}
199+ //
200+ // tapdance = TapDance()
201+ // tapdance.tap_time = 200
202+ // keyboard.modules.append(tapdance)
203+ //
204+ // # Keymap
205+ // from keymap import keymap
206+ // keyboard.keymap = keymap
207+ //
208+ // ${codeblock}
209+ //
210+ // if __name__ == '__main__':
211+ // keyboard.go()
212+ // `
213+
214+ // we are still writing the keymap file by hand
214215 const keymap = `# Keymap Autogenerated by Pog do not edit
215216from kmk.keys import KC
216217from kmk.handlers.sequences import send_string, simple_key_sequence
@@ -230,13 +231,11 @@ for l, layer in enumerate(pog.config['encoderKeymap']):
230231 layerEncoders.append(tuple(map(eval, encoder)))
231232 encoderKeymap.append(tuple(layerEncoders))
232233`
233- if ( serial ) {
234+ if ( serial ) {
234235 writeKeymapViaSerial ( keymap )
235-
236- } else {
236+ } else {
237237 fs . writeFile ( currentKeyboard . path + '/keymap.py' , keymap , ( ) => {
238238 console . log ( 'keymap File written successfully' )
239239 } )
240240 }
241-
242241}
0 commit comments