Skip to content

Commit 67ee3be

Browse files
committed
Added custom function handling
1 parent 2a9f943 commit 67ee3be

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

www/js/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ function process_socket_response(msg) {
694694
if (msg.startsWith("X:")) {
695695
process_Position(msg);
696696
}
697-
if (msg.startsWith("esp3d:")) {
697+
if (msg.startsWith("[esp3d]")) {
698698
process_Custom(msg); // handles custom messages sent via M118
699699
}
700700
if (msg.startsWith("ok")) {

www/js/custom.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,29 @@
22
// In gcode file, M118 can be used to send messages on serial.
33
// This allows the microcontroller to communicate with hosts.
44
// Example:
5-
// M118 esp3d:<your message>
5+
// M118 [esp3d]<your message>
66
// will send "esp3d:<your message>" over serial, which can be picked up by host
77
// to trigger certain actions.
8+
// M118 [esp3d]<function call>
9+
// will call the function, as long as a handler has been predefined to identify
10+
// the call.
811

912
function process_Custom(response) {
1013
var freq = 440; // beep frequency on end of print
1114
var dur = 100; // beep duration on end of print
12-
if (response.startsWith("esp3d:eop")) {
15+
response = response.replace("[esp3d]","");
16+
if (response.startsWith("eop")) {
17+
// Example 1
1318
// Sound to play on end of print
1419
// Triggered by message on serial terminal
15-
// ESP3D:eop
16-
//
17-
// This message can be sent via M118.
20+
// [ESP3D]eop
1821
beep(dur, freq);
19-
}
20-
}
22+
}
23+
if (response.startsWith("beep(")) {
24+
// Example 2
25+
// Call a function within webUI, in this case beep()
26+
// Triggered by message on serial terminal
27+
// [ESP3D]beep(100, 261)
28+
eval(response);
29+
}
30+
}

0 commit comments

Comments
 (0)