Skip to content

Commit 02e2338

Browse files
committed
update smfix to v1.8
1 parent a3df08c commit 02e2338

File tree

7 files changed

+61
-15
lines changed

7 files changed

+61
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ A command-line tool for send the gcode file to Snapmaker Printers via WiFi conne
66
## Features:
77
- Support Snapmaker 2 A150/250/350, J1, Artisan
88
- Auto discover machines (UDP broadcast)
9-
- Simulated a OctoPrint server, so that it can be in any slicing software such as Cura/PrusaSlicer/SuperSlicer/ideaMaker send gcode to the printer
9+
- Simulated a OctoPrint server, so that it can be in any slicing software such as Cura/PrusaSlicer/SuperSlicer/OrcaSlicer send gcode to the printer
10+
- Smart pre-heat for switch tools, shutoff nozzles that are no longer in use, and other optimization features for multi-extruders.
1011
- No need to click Yes button on the touch screen every time for authorization connect
1112
- Support for multiple platforms including win/macOS/Linux/RaspberryPi
1213

README.zh-cn.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ Luban 和 Cura with SnapmakerPlugin 对于新手很友好,但是我的大部
77
## 功能
88
- 支持 Snapmaker 2 A/J1/Artisan 全系列打印机
99
- 自动发现局域网内所有的 Snapmaker 打印机(和 Luban 相同的协议,使用 UDP 广播)
10-
- 模拟 OctoPrint Server,这样就可以在各种切片软件,比如 Cura/PrusaSlicer/SuperSlicer/ideaMaker 中向 Snapmaker 打印机发送文件
10+
- 模拟 OctoPrint Server,这样就可以在各种切片软件,比如 Cura/PrusaSlicer/SuperSlicer/OrcaSlicer 中向 Snapmaker 打印机发送文件
11+
- 为多挤出机提供智能预热、关闭不再使用的喷头等优化功能
1112
- Snapmaker 2 A-Series 第一次连接时需要授权,之后可以直接一步上传
1213
- 支持 macOS/Windows/Linux/RaspberryPi 多个平台
1314

connector.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"io"
66
"net"
7+
"runtime"
78
"time"
89
)
910

@@ -32,6 +33,7 @@ func (p *Payload) ReadableSize() string {
3233
}
3334

3435
func (p *Payload) GetContent(fix bool) (cont []byte, err error) {
36+
defer runtime.GC()
3537
if fix {
3638
cont, err = postProcess(p.File)
3739
p.Size = int64(len(cont))

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.20
55
require (
66
github.com/gosuri/uilive v0.0.4
77
github.com/imroc/req/v3 v3.11.0
8-
github.com/macdylan/SMFix/fix v0.0.0-20230711071352-9db26cbcb3a3
8+
github.com/macdylan/SMFix/fix v0.0.0-20230731072358-03b385d0df5a
99
github.com/manifoldco/promptui v0.9.0
1010
gopkg.in/yaml.v3 v3.0.1
1111
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
2121
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
2222
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2323
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
24-
github.com/macdylan/SMFix/fix v0.0.0-20230711071352-9db26cbcb3a3 h1:yHR5HciyfOoZyt5S3m3gBLYv+Q6L4iwXgGaJXRd+N04=
25-
github.com/macdylan/SMFix/fix v0.0.0-20230711071352-9db26cbcb3a3/go.mod h1:dnB1MevhW7tICqBpQ2aHpVClwLdmSBUNmfV7jpRmiWw=
24+
github.com/macdylan/SMFix/fix v0.0.0-20230731072358-03b385d0df5a h1:yy0uQ23OaihOPf88+TWqwFPJTdCsPQTfkQBRtYqug44=
25+
github.com/macdylan/SMFix/fix v0.0.0-20230731072358-03b385d0df5a/go.mod h1:dnB1MevhW7tICqBpQ2aHpVClwLdmSBUNmfV7jpRmiWw=
2626
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
2727
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
2828
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=

octoprint.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ import (
44
"log"
55
"net"
66
"net/http"
7+
"strings"
78
"time"
89
)
910

1011
const (
1112
maxMemory = 64 << 20 // 64MB
1213
)
1314

15+
var (
16+
noTrim = false
17+
noShutoff = false
18+
noPreheat = false
19+
)
20+
1421
func LoggingMiddleware(next http.Handler) http.Handler {
1522
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
1623
start := time.Now()
@@ -51,6 +58,27 @@ func startOctoPrintServer(listenAddr string, printer *Printer) error {
5158
}
5259
defer file.Close()
5360

61+
// read X-Api-Key header
62+
apiKey := r.Header.Get("X-Api-Key")
63+
if len(apiKey) > 5 {
64+
noTrim = strings.Contains(apiKey, "notrim")
65+
noPreheat = strings.Contains(apiKey, "nopreheat")
66+
noShutoff = strings.Contains(apiKey, "noshutoff")
67+
msg := make([]string, 0, 3)
68+
if noTrim {
69+
msg = append(msg, "-notrim")
70+
}
71+
if noPreheat {
72+
msg = append(msg, "-nopreheat")
73+
}
74+
if noShutoff {
75+
msg = append(msg, "-noshutoff")
76+
}
77+
if len(msg) > 0 {
78+
log.Printf("SMFix with args: %s", strings.Join(msg, " "))
79+
}
80+
}
81+
5482
// Send the stream to the printer
5583
payload := NewPayload(file, fd.Filename, fd.Size)
5684
if err := Connector.Upload(printer, payload); err != nil {

utils.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package main
22

33
import (
4+
"bufio"
45
"bytes"
56
"fmt"
67
"io"
78
"os"
89
"regexp"
10+
"strings"
911

1012
"github.com/macdylan/SMFix/fix"
1113
)
@@ -43,20 +45,32 @@ func postProcessFile(file_path string) (out []byte, err error) {
4345
func postProcess(r io.Reader) (out []byte, err error) {
4446
header, errfix := fix.ExtractHeader(r)
4547

46-
out, err = io.ReadAll(r)
47-
if err != nil {
48-
return
48+
if h, ok := r.(io.ReadSeeker); ok {
49+
h.Seek(0, 0)
4950
}
5051

51-
/*
52-
if err == fix.ErrIsFixed || err == fix.ErrInvalidGcode {
53-
return out, nil
54-
}
52+
gcodes := make([]string, 0, fix.Params.TotalLines+len(header)+128)
53+
sc := bufio.NewScanner(r)
54+
for sc.Scan() {
55+
gcodes = append(gcodes, sc.Text())
56+
}
57+
if err = sc.Err(); err != nil {
58+
return nil, err
59+
}
5560

56-
if err != nil {
57-
return out, err
61+
if errfix == nil {
62+
if !noTrim {
63+
gcodes = fix.GcodeTrimLines(gcodes)
5864
}
59-
*/
65+
if !noShutoff {
66+
gcodes = fix.GcodeFixShutoff(gcodes)
67+
}
68+
if !noPreheat {
69+
gcodes = fix.GcodeFixPreheat(gcodes)
70+
}
71+
}
72+
73+
out = []byte(strings.Join(gcodes, "\n"))
6074

6175
if len(header) > 25 {
6276
return append(bytes.Join(header, []byte("\n")), out...), nil

0 commit comments

Comments
 (0)