Browse Source

improve shjs ini file support and add blog post about it.

Thomas Buck 1 year ago
parent
commit
e066decf7f

+ 83
- 0
input/blog/2022/2022_06_12_shjs_ini.md View File

@@ -0,0 +1,83 @@
1
+title: Blog
2
+post: Improved syntax highlighting on my website
3
+description: Getting to know SHJS and GNU source-highlight
4
+date: 2022-06-12
5
+comments: true
6
+---
7
+
8
+For another page on this site I wanted to enable syntax highlighting for `.ini` files.
9
+Looking at the language files included in [my SHJS 'distribution'](https://git.xythobuz.de/thomas/website/src/branch/master/static/js/sh) I didn't find an obvious file for 'ini'.
10
+I tried the 'desktop' language, because these seem similar to 'ini' files, but the resulting syntax highlighting didn't look good.
11
+The SHJS docs don't mention 'ini' at all.
12
+
13
+I then took a little dive into how these files work.
14
+Turns out [SHJS](http://shjs.sourceforge.net/doc/documentation.html) uses the language definition files from [GNU source-highlight](http://www.gnu.org/software/src-highlite/).
15
+These are then converted to the js files needed by SHJS.
16
+The source-highlight page mentions they support ini files, but I couldn't find a matching definition file in there.
17
+Looking at my Arch system, I saw that source-highlight is already installed, including the language definitions in `/usr/share/source-highlight`.
18
+So I ran `source-highlight --lang-list` which confirms that the desktop language is indeed the one to use for 'ini' files.
19
+I also downloaded the most recent SHJS source distribution from their Sourceforge.
20
+
21
+Looking at the SHJS source, they include the source-highlight definitions as well, and they seem very similar, with one important difference.
22
+
23
+<pre class="sh_diff">
24
+--- /home/thomas/Projekte/extern/shjs-0.6-src/source-highlight-lang/desktop.lang        2022-06-12 10:37:47.468000842 +0200
25
++++ /usr/share/source-highlight/desktop.lang    2021-12-17 06:57:29.000000000 +0100
26
+@@ -5,3 +5,7 @@
27
+ section start '\[.*\]'
28
+
29
+ (type,paren,normal,symbol) = `([^="\[]+)((?:\[.+\])*)([[:blank:]]*)(=)`
30
++
31
++include "number.lang"
32
++include "symbols.lang"
33
++include "c_string.lang"
34
+</pre>
35
+
36
+They removed the includes at the end for some reason.
37
+So I wanted to convert the language definition from my system distributed source-highlight to the format needed by SHJS, which is done with their `sh2js.pl` script.
38
+
39
+It didn't run however.
40
+
41
+Turns out some time ago Perl distributions disabled loading modules from the current directory.
42
+So I had to add this to the beginning of the script.
43
+
44
+<pre class="sh_perl">
45
+use FindBin 1.51 qw( $RealBin );
46
+use lib $RealBin;
47
+</pre>
48
+
49
+I also had to install some dependencies with CPAN.
50
+
51
+<pre class="sh_sh">
52
+$ perl -MCPAN -e shell
53
+</pre>
54
+
55
+Namely `Parse::RecDescent`.
56
+
57
+<pre class="sh_perl">
58
+install Parse::RecDescent
59
+</pre>
60
+
61
+Then I was able to convert the file.
62
+
63
+<pre class="sh_sh">
64
+$ perl sh2js.pl /usr/share/source-highlight/desktop.lang > desktop_test.lang.js
65
+</pre>
66
+
67
+And minify it, like the SHJS devs are doing in their makefile.
68
+For this, I had to get `yuicompressor` first.
69
+
70
+<pre class="sh_sh">
71
+$ wget https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar
72
+$ mv yuicompressor-2.4.8.jar ~/bin/
73
+</pre>
74
+
75
+And run it on the generated js file.
76
+
77
+<pre class="sh_sh">
78
+$ java -jar ~/bin/yuicompressor-2.4.8.jar desktop_test.lang.js > desktop_test.lang.min.js
79
+</pre>
80
+
81
+That's it, worked flawlessly!
82
+Now I have some nicer ini file syntax highlighting.
83
+And this was a fun little exercise for sunday morning!

+ 218
- 0
input/projects/3d-printing/i3-am8.md View File

@@ -66,6 +66,10 @@ Instead I ran a cable between them, only connecting GND and the UART Rx and Tx l
66 66
 This is the only place where the grounds of the +5V and +24V supply are connected.
67 67
 The mainboard is not fed any external +5V.
68 68
 
69
+As I've re-used 12V fans from my old printer, I had to add a small PCB with a 24V -> 12V converter to power them.
70
+I simply used a small LM2596 module soldered onto a perf-board with some connectors.
71
+The mainboard switches GND for all accessories, so using 12V fans is as simple as connecting the negative lead to the mainboard connector, and the positive lead to +12V instead of the mainboard connector.
72
+
69 73
 ## LCD Connection
70 74
 
71 75
 On a whim, I decided to get a [Fysetc 12864](https://wiki.fysetc.com/Mini12864_Panel/) clone.
@@ -112,6 +116,7 @@ lightgallery([
112 116
 %-->
113 117
 
114 118
 TODO problems with encoder, kill button pullups?!
119
+TODO display no longer showing anything
115 120
 
116 121
 TODO photo(s) of cabling
117 122
 
@@ -120,3 +125,216 @@ lightgallery([
120 125
     [ "img/am8_lcd_assy.jpg", "LCD mounted on printer" ],
121 126
 ])
122 127
 %-->
128
+
129
+## Klipper Firmware
130
+
131
+After hearing many good things about Klipper from Tobias and others, I really had to try it out myself.
132
+And I have to admit, even though I didn't believe it at first, it's much better than Marlin in many areas, even for non-fancy printers like mine.
133
+
134
+I'm using [MainsailOS](https://docs.mainsail.xyz/setup/mainsail-os) on a Raspberry Pi 3B.
135
+Installation and Configuration was really straight-forward with the configuration guides of [Klipper](https://www.klipper3d.org/Config_Reference.html) and [Mainsail](https://docs.mainsail.xyz/setup/mainsailos/first-boot).
136
+
137
+Here is my current printer config file.
138
+
139
+<pre class="sh_desktop">
140
+[include mainsail.cfg]
141
+
142
+##########################################
143
+################# System #################
144
+##########################################
145
+
146
+[printer]
147
+kinematics: corexz
148
+max_velocity: 200
149
+max_accel: 2000
150
+max_z_velocity: 200
151
+max_z_accel: 500
152
+
153
+[board_pins]
154
+aliases:
155
+    # EXP1 header
156
+    EXP1_1=PB5,   EXP1_3=PA9,   EXP1_5=PA10, EXP1_7=PB8, EXP1_9=<GND>,
157
+    EXP1_2=PA15,  EXP1_4=<RST>, EXP1_6=PB9,  EXP1_8=PD6, EXP1_10=<5V>,
158
+    # I/O header
159
+    IO_1=PD0, IO_2=PD2, IO_3=PD3, IO_4=PD4, IO_5=PD5,
160
+    # PWR-DET header
161
+    PWR_DET=PC12,
162
+    # Unused pin
163
+    UNUSED=PA6
164
+
165
+[mcu]
166
+#serial: /dev/ttyAMA0
167
+serial: /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_A100OZQ1-if00-port0
168
+restart_method: command
169
+
170
+##########################################
171
+################# Motors #################
172
+##########################################
173
+
174
+# The stepper_x section is used to describe the X axis as well as the
175
+# stepper controlling the X+Z movement.
176
+[stepper_x]
177
+step_pin: PB13
178
+dir_pin: PB12
179
+enable_pin: !PB14
180
+microsteps: 16 # set by driver
181
+full_steps_per_rotation: 200 # motor specific
182
+gear_ratio: 36:20 # CoreXZ gearbox
183
+rotation_distance: 40 # 20 teeth * 2mm belt
184
+endstop_pin: ^!PC0
185
+position_endstop: 0.0
186
+position_max: 235
187
+homing_speed: 30
188
+
189
+# The stepper_y section is used to describe the stepper controlling
190
+# the Y axis.
191
+[stepper_y]
192
+step_pin: PB10
193
+dir_pin: !PB2
194
+enable_pin: !PB11
195
+microsteps: 16 # set by driver
196
+full_steps_per_rotation: 200 # motor specific
197
+gear_ratio: 1:1 # driven directly
198
+rotation_distance: 40 # 20 teeth * 2mm belt
199
+endstop_pin: ^!PC1
200
+position_endstop: 0.0
201
+position_max: 235
202
+homing_speed: 30
203
+
204
+# The stepper_z section is used to describe the Z axis as well as the
205
+# stepper controlling the X-Z movement.
206
+[stepper_z]
207
+step_pin: PB0
208
+dir_pin: !PC5
209
+enable_pin: !PB1
210
+microsteps: 16 # set by driver
211
+full_steps_per_rotation: 200 # motor specific
212
+gear_ratio: 36:20 # CoreXZ gearbox
213
+rotation_distance: 40 # 20 teeth * 2mm belt
214
+endstop_pin: ^!PC2
215
+position_endstop: 0.0
216
+position_max: 250
217
+homing_speed: 20
218
+
219
+[extruder]
220
+step_pin: PB3
221
+dir_pin: !PB4
222
+enable_pin: !PD1
223
+rotation_distance: 22.67895
224
+gear_ratio: 50:8
225
+microsteps: 16
226
+full_steps_per_rotation: 200
227
+nozzle_diameter: 0.400
228
+filament_diameter: 1.750
229
+heater_pin: PC8
230
+sensor_type: ATC Semitec 104GT-2
231
+sensor_pin: PA0
232
+control: pid
233
+pid_Kp: 21.527
234
+pid_Ki: 1.063
235
+pid_Kd: 108.982
236
+min_temp: 0
237
+max_temp: 250
238
+max_extrude_only_distance: 1400.0
239
+max_extrude_only_velocity: 75.0
240
+max_extrude_only_accel: 1500
241
+
242
+###########################################
243
+################# TMC2209 #################
244
+###########################################
245
+
246
+[tmc2209 stepper_x]
247
+uart_pin: PC11
248
+tx_pin: PC10
249
+uart_address: 0
250
+#stealthchop_threshold: 999999
251
+run_current: 0.5
252
+
253
+[tmc2209 stepper_y]
254
+uart_pin: PC11
255
+tx_pin: PC10
256
+uart_address: 2
257
+#stealthchop_threshold: 999999
258
+run_current: 0.3
259
+
260
+[tmc2209 stepper_z]
261
+uart_pin: PC11
262
+tx_pin: PC10
263
+uart_address: 1
264
+#stealthchop_threshold: 999999
265
+run_current: 0.5
266
+
267
+[tmc2209 extruder]
268
+uart_pin: PC11
269
+tx_pin: PC10
270
+uart_address: 3
271
+stealthchop_threshold: 999999
272
+#interpolate: True
273
+run_current: 0.3
274
+
275
+###########################################
276
+############### Accessories ###############
277
+###########################################
278
+
279
+[fan]
280
+pin: PC6 # fan 0
281
+
282
+[heater_fan nozzle_cooling_fan]
283
+pin: PC7 # fan 1
284
+
285
+[heater_fan controller_fan]
286
+pin: PB15 # fan 2
287
+
288
+###########################################
289
+########### LCD / Encoder / LED ###########
290
+###########################################
291
+
292
+[display]
293
+lcd_type: uc1701
294
+cs_pin: EXP1_2
295
+a0_pin: EXP1_3
296
+rst_pin: EXP1_5
297
+contrast: 63
298
+encoder_pins: ^IO_2, ^IO_3
299
+click_pin: ^!EXP1_1
300
+kill_pin: ^IO_1
301
+spi_software_miso_pin: UNUSED
302
+spi_software_mosi_pin: IO_5
303
+spi_software_sclk_pin: IO_4
304
+
305
+# index 1 is lcd backlight
306
+# index 2 is left encoder led
307
+# index 3 is right encoder led
308
+[neopixel lcd]
309
+pin: EXP1_6
310
+chain_count: 3
311
+color_order: RGB
312
+initial_RED: 0.3
313
+initial_GREEN: 0.3
314
+initial_BLUE: 0.3
315
+
316
+##########################################
317
+################# Beeper #################
318
+##########################################
319
+
320
+# M300 : Play tone. Usage:
321
+#   M300 [P<ms>] [S<Hz>]
322
+#   P is the tone duration, S the tone frequency.
323
+
324
+[output_pin beeper]
325
+pin: PWR_DET
326
+pwm: True
327
+value: 0 # Silent at power on, set to 1 if active low.
328
+shutdown_value: 0 # Disable at emergency shutdown (no PWM would be available anyway).
329
+cycle_time: 0.001
330
+
331
+[gcode_macro M300]
332
+gcode:
333
+    # Use a default 1kHz tone if S is omitted.
334
+    {&#37; set S = params.S|default(1000)|int &#37;}
335
+    # Use a 10ms duration is P is omitted.
336
+    {&#37; set P = params.P|default(100)|int &#37;}
337
+    SET_PIN PIN=beeper VALUE=0.5 CYCLE_TIME={ 1.0/S if S > 0 else 1 }
338
+    G4 P{P}
339
+    SET_PIN PIN=beeper VALUE=0
340
+</pre>

+ 1
- 1
static/js/sh/sh_desktop.min.js View File

@@ -1 +1 @@
1
-if(!this.sh_languages){this.sh_languages={}}sh_languages.desktop=[[[/#/g,"sh_comment",1],[/\[.*\]/g,"sh_section",1],[/([^="\[]+)((?:\[.+\])*)([ \t]*)(=)/g,["sh_type","sh_paren","sh_normal","sh_symbol"],-1]],[[/$/g,null,-2]]];
1
+if(!this.sh_languages){this.sh_languages={}}sh_languages.desktop=[[[/#/g,"sh_comment",1],[/\[.*\]/g,"sh_section",1],[/([^="\[]+)((?:\[.+\])*)([ \t]*)(=)/g,["sh_type","sh_paren","sh_normal","sh_symbol"],-1],[/\b[+-]?(?:(?:0x[A-Fa-f0-9]+)|(?:(?:[\d]*\.)?[\d]+(?:[eE][+-]?[\d]+)?))u?(?:(?:int(?:8|16|32|64))|L)?\b/g,"sh_number",-1],[/~|!|%|\^|\*|\(|\)|-|\+|=|\[|\]|\\|:|;|,|\.|\/|\?|&|<|>|\|/g,"sh_symbol",-1],[/"/g,"sh_string",2],[/'/g,"sh_string",3]],[[/$/g,null,-2]],[[/"/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]],[[/'/g,"sh_string",-2],[/\\./g,"sh_specialchar",-1]]];

Loading…
Cancel
Save