Skip to content

Commit

Permalink
reinforce tower
Browse files Browse the repository at this point in the history
  • Loading branch information
macdylan committed Aug 11, 2023
1 parent 02e2338 commit d85e7b0
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 35 deletions.
11 changes: 8 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ endif
FLAGS = -ldflags="-w -s $(VERSION)"
CMD = go build -trimpath $(FLAGS)
SRC = $(shell ls *.go | grep -v _test.go)
EXT_FILES = README.md README.zh-cn.md LICENSE

.PHONY: all clean dep darwin-arm64 darwin-amd64 linux-amd64 linux-arm7 linux-arm6 win64 win32

Expand Down Expand Up @@ -35,12 +36,16 @@ win32: $(SRC)
dep: # Get the dependencies
go mod download

all: dep darwin-arm64 darwin-amd64 linux-amd64 linux-arm7 linux-arm6 win64 win32
all: dep darwin-arm64 win64 win32 darwin-amd64 linux-amd64 linux-arm7 linux-arm6
@true

all-zip: all
for p in darwin-arm64 darwin-amd64 linux-amd64 linux-arm7 linux-arm6 win64.exe win32.exe; do \
zip -j $(DIST)$(NAME)-$$p.zip $(DIST)$(NAME)-$$p README.md README.zh-cn.md LICENSE; \
for p in darwin-arm64 win64.exe win32.exe darwin-amd64 linux-amd64 linux-arm7 linux-arm6; do \
if [ "$$p" = "win64.exe" -o "$$p" = "win32.exe" ]; then \
zip -j $(DIST)$(NAME)-$$p.zip $(DIST)$(NAME)-$$p $(EXT_FILES) *.bat; \
else \
zip -j $(DIST)$(NAME)-$$p.zip $(DIST)$(NAME)-$$p $(EXT_FILES); \
fi \
done

clean:
Expand Down
30 changes: 16 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@
A command-line tool for send the gcode file to Snapmaker Printers via WiFi connection.

## Features:
- Support Snapmaker 2 A150/250/350, J1, Artisan
- Auto discover machines (UDP broadcast)
- Auto discover printers (UDP broadcast, same as Snapmaker Luban)
- Upload any type of file does not depend on the head/module limit
- Simulated a OctoPrint server, so that it can be in any slicing software such as Cura/PrusaSlicer/SuperSlicer/OrcaSlicer send gcode to the printer
- Smart pre-heat for switch tools, shutoff nozzles that are no longer in use, and other optimization features for multi-extruders.
- Reinforce the prime tower to avoid it collapse for multi-filament printing
- No need to click Yes button on the touch screen every time for authorization connect
- Support Snapmaker 2 A150/250/350, J1, Artisan
- Support for multiple platforms including win/macOS/Linux/RaspberryPi

## Usage:
Download [sm2uploader](https://github.com/macdylan/sm2uploader/releases)
- Linux/macOS: `chmod +x sm2uploader`

```
for Windows:
- locate to the sm2uploader folder, and double-click `start-octoprint.bat`
- type a port number for octoprint that you wish to listen
- when `Server started ...` message appears, the startup was successful, do not close the cmd window, and go to the slicer software to setup a OctoPrint printer
- use `http://127.0.0.1:(PORT NUM)` as url, click the Test Connect button, all configuration will be finished if successful.

```bash
## Discover mode
$ sm2uploader /path/to/code-file1 /path/to/code-file2
Discovering ...
Expand All @@ -29,17 +37,12 @@ Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## Directly mode
$ sm2uploader -host 192.168.1.19 /path/to/code-file1 /path/to/code-file2
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
Uploading file 'code-file2' [1.0 MB]...
- SACP sending 100%
Upload finished.

## use printer id
$ sm2uploader -host J1V19 /path/to/code-file1 /path/to/code-file2
## Use printer id
$ sm2uploader -host J1V19 /path/to/code-file1
Discovering ...
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Expand All @@ -48,16 +51,15 @@ Uploading file 'code-file1' [1.2 MB]...
Upload finished.

## OctoPrint server (CTRL-C to stop)
$ sm2uploader -octoprint :8844 -host A350
$ sm2uploader -octoprint 127.0.0.1:8844 -host A350
Printer IP: 192.168.1.20
Printer Model: Snapmaker 2 Model A350
Starting OctoPrint server on :8844 ...
Server started, now you can upload files to http://localhost:8844
Server started, now you can upload files to http://127.0.0.1:8844
Request GET /api/version completed in 6.334µs
- HTTP sending 100.0%
Upload finished: model.gcode [382.2 KB]
Request POST /api/files/local completed in 951.080458ms
...
```

If UDP Discover can not work, use `sm2uploader -host 192.168.1.20 /file.gcode` to directly upload to printer.
Expand Down
25 changes: 13 additions & 12 deletions README.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,25 @@ Luban 和 Cura with SnapmakerPlugin 对于新手很友好,但是我的大部
这个工具提供了一步上传的能力,你可以通过命令行一次上传多个 gcode/cnc/bin固件 等文件。

## 功能
- 支持 Snapmaker 2 A/J1/Artisan 全系列打印机
- 自动发现局域网内所有的 Snapmaker 打印机(和 Luban 相同的协议,使用 UDP 广播)
- 模拟 OctoPrint Server,这样就可以在各种切片软件,比如 Cura/PrusaSlicer/SuperSlicer/OrcaSlicer 中向 Snapmaker 打印机发送文件
- 为多挤出机提供智能预热、关闭不再使用的喷头等优化功能
- 强化擦料塔,避免多材料打印时因不粘合而倒塌,例如在 PETG+PLA 混合打印时
- Snapmaker 2 A-Series 第一次连接时需要授权,之后可以直接一步上传
- 支持 Snapmaker 2 A/J1/Artisan 全系列打印机
- 支持 macOS/Windows/Linux/RaspberryPi 多个平台

## 使用方法
下载适用的[程序文件](https://github.com/macdylan/sm2uploader/releases)
- Linux/macOS 下,可能需要赋予可执行权限 `chmod +x sm2uploader`

```
Windows 使用方法:
- 在解压目录中双击 `start-octoprint.bat` 批处理程序
- 按照提示输入端口号,不输入直接回车则使用默认的 `8899` 端口
- 当出现 `Server started ...` 信息时表示服务启动成功,此时不要关闭命令行窗口
- 打开切片软件,设置物理打印机,输入命令行窗口中提示的 `http://127.0.0.1:端口号`,测试连接成功即可

```bash
## 自动查找模式
$ sm2uploader /path/to/code-file1 /path/to/code-file2
Discovering ...
Expand All @@ -30,17 +37,12 @@ Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
- SACP sending 100%
Upload finished.
## 指定 IP 连接模式
$ sm2uploader -host 192.168.1.19 /path/to/code-file1 /path/to/code-file2
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Uploading file 'code-file1' [1.2 MB]...
Uploading file 'code-file2' [1.0 MB]...
- SACP sending 100%
Upload finished.

## 指定打印机名字进行连接
$ sm2uploader -host J1V19 /path/to/code-file1 /path/to/code-file2
$ sm2uploader -host J1V19 /path/to/code-file1
Discovering ...
Printer IP: 192.168.1.19
Printer Model: Snapmaker J1
Expand All @@ -49,16 +51,15 @@ Uploading file 'code-file1' [1.2 MB]...
Upload finished.

## 模拟 OctoPrint (CTRL-C 终止运行)
$ sm2uploader -octoprint :8844 -host A350
$ sm2uploader -octoprint 127.0.0.1:8844 -host A350
Printer IP: 192.168.1.20
Printer Model: Snapmaker 2 Model A350
Starting OctoPrint server on :8844 ...
Server started, now you can upload files to http://localhost:8844
Server started, now you can upload files to http://127.0.0.1:8844
Request GET /api/version completed in 6.334µs
- HTTP sending 100.0%
Upload finished: model.gcode [382.2 KB]
Request POST /api/files/local completed in 951.080458ms
...
```

打印机的 UDP 应答服务有时会挂掉,通常需要重启打印机来解决。或者你可以直接指定目标IP: `sm2uploader -host 192.168.1.20 /file.gcode`
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.20
require (
github.com/gosuri/uilive v0.0.4
github.com/imroc/req/v3 v3.11.0
github.com/macdylan/SMFix/fix v0.0.0-20230731072358-03b385d0df5a
github.com/macdylan/SMFix/fix v0.0.0-20230811055700-930d31056194
github.com/manifoldco/promptui v0.9.0
gopkg.in/yaml.v3 v3.0.1
)
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/macdylan/SMFix/fix v0.0.0-20230731072358-03b385d0df5a h1:yy0uQ23OaihOPf88+TWqwFPJTdCsPQTfkQBRtYqug44=
github.com/macdylan/SMFix/fix v0.0.0-20230731072358-03b385d0df5a/go.mod h1:dnB1MevhW7tICqBpQ2aHpVClwLdmSBUNmfV7jpRmiWw=
github.com/macdylan/SMFix/fix v0.0.0-20230811055700-930d31056194 h1:BEwsonfRa4+0lJDSFAxh59aRtB4h434mJC2rx6V+2Yk=
github.com/macdylan/SMFix/fix v0.0.0-20230811055700-930d31056194/go.mod h1:dnB1MevhW7tICqBpQ2aHpVClwLdmSBUNmfV7jpRmiWw=
github.com/manifoldco/promptui v0.9.0 h1:3V4HzJk1TtXW1MTZMP7mdlwbBpIinw3HztaIlYthEiA=
github.com/manifoldco/promptui v0.9.0/go.mod h1:ka04sppxSGFAtxX0qhlYQjISsg9mR4GWtQEhdbn6Pgg=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
Expand Down
11 changes: 8 additions & 3 deletions octoprint.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ const (
)

var (
noTrim = false
noShutoff = false
noPreheat = false
noTrim = false
noShutoff = false
noPreheat = false
noReinforceTower = false
)

func LoggingMiddleware(next http.Handler) http.Handler {
Expand Down Expand Up @@ -64,6 +65,7 @@ func startOctoPrintServer(listenAddr string, printer *Printer) error {
noTrim = strings.Contains(apiKey, "notrim")
noPreheat = strings.Contains(apiKey, "nopreheat")
noShutoff = strings.Contains(apiKey, "noshutoff")
noReinforceTower = strings.Contains(apiKey, "noreinforcetower")
msg := make([]string, 0, 3)
if noTrim {
msg = append(msg, "-notrim")
Expand All @@ -74,6 +76,9 @@ func startOctoPrintServer(listenAddr string, printer *Printer) error {
if noShutoff {
msg = append(msg, "-noshutoff")
}
if noReinforceTower {
msg = append(msg, "-noreinforcetower")
}
if len(msg) > 0 {
log.Printf("SMFix with args: %s", strings.Join(msg, " "))
}
Expand Down
30 changes: 30 additions & 0 deletions start-octoprint.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
@echo off
echo Will start the sm2uploader in OctoPrint mode. press Ctrl+C to exit.

rem set host=-host A350
set host=

set /p port=Enter a local port num (default is 8899)
if "%port%"=="" set "port=8899"
if %port% LSS 1024 (
echo Port number must be greater than 1024
pause
exit /b 1
)

set w64=sm2uploader-win64.exe
set w32=sm2uploader-win32.exe
set cmd=

where /q %w64% && set "cmd=%w64%"
where /q %w32% && set "cmd=%w32%"

if "%cmd%"=="" (
echo Can not find %w64% or %w32%
pause
exit /b 1
)

echo %cmd% %host% -octoprint 127.0.0.1:%port%
%cmd% %host% -octoprint 127.0.0.1:%port%
pause
3 changes: 3 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ func postProcess(r io.Reader) (out []byte, err error) {
if !noPreheat {
gcodes = fix.GcodeFixPreheat(gcodes)
}
if !noReinforceTower {
gcodes = fix.GcodeReinforceTower(gcodes)
}
}

out = []byte(strings.Join(gcodes, "\n"))
Expand Down

0 comments on commit d85e7b0

Please sign in to comment.