Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feeder] support Prusa mk4 #18

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ func (daemon *Daemon) StartHandler(w http.ResponseWriter, _ *http.Request) {
}

errS := fmt.Sprintf("Ignore buttonpress in '%v' status", daemon.job.Status)
log.Infof(errS)
log.Info(errS)
http.Error(w, errS, http.StatusBadRequest)
}

Expand All @@ -264,7 +264,7 @@ func (daemon *Daemon) RescheduleHandler(w http.ResponseWriter, _ *http.Request)

if daemon.job.Status != juggler.StatusWaitingButton {
errS := fmt.Sprintf("Ignore reschedule in '%v' status", daemon.job.Status)
log.Infof(errS)
log.Info(errS)
http.Error(w, errS, http.StatusBadRequest)
return
}
Expand All @@ -281,7 +281,7 @@ func (daemon *Daemon) CancelHandler(w http.ResponseWriter, _ *http.Request) {

if daemon.job.ID == 0 {
errS := "Ignore cancel, no job scheduled"
log.Infof(errS)
log.Info(errS)
http.Error(w, errS, http.StatusBadRequest)
return
}
Expand All @@ -302,7 +302,7 @@ func (daemon *Daemon) PauseHandler(w http.ResponseWriter, _ *http.Request) {

if daemon.job.Status != juggler.StatusPrinting {
errS := "Ignore pause, not printing"
log.Infof(errS)
log.Info(errS)
http.Error(w, errS, http.StatusBadRequest)
return
}
Expand Down
12 changes: 6 additions & 6 deletions fakejuggler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,25 @@ func main() {
}
j := FakeJuggler{Job: &job}

http.HandleFunc("/cancel", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/cancel", func(w http.ResponseWriter, _ *http.Request) {
juggler.SetHeaders(w)
log.Println("cancel")
j.cancel()
})

http.HandleFunc("/start", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/start", func(w http.ResponseWriter, _ *http.Request) {
juggler.SetHeaders(w)
log.Println("start")
j.start()
})

http.HandleFunc("/reschedule", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/reschedule", func(w http.ResponseWriter, _ *http.Request) {
juggler.SetHeaders(w)
log.Println("reschedule")
j.reschedule()
})

http.HandleFunc("/info", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/info", func(w http.ResponseWriter, _ *http.Request) {
juggler.SetHeaders(w)
b, err := json.Marshal(j.Job)
if err != nil {
Expand All @@ -131,13 +131,13 @@ func main() {
}
})

http.HandleFunc("/pause", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/pause", func(w http.ResponseWriter, _ *http.Request) {
juggler.SetHeaders(w)
log.Println("pause")
j.pause()
})

http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) {
http.HandleFunc("/version", func(w http.ResponseWriter, _ *http.Request) {
juggler.SetHeaders(w)
log.Println("version")
fmt.Fprintf(w, "12345")
Expand Down
20 changes: 11 additions & 9 deletions gcodefeeder/feeder.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func (f *Feeder) Cancel() {
f.Lock()
defer f.Unlock()
log.Debug("Feeder: Cancel is called")
f.cancelFunc()
// Feed, read and write function will terminate when context is cancelled
defer f.cancelFunc()
instructions := []string{
// turn off temperature
"M104 S0\n",
Expand Down Expand Up @@ -162,14 +163,11 @@ func (f *Feeder) read(ctx context.Context) {
continue
}
f.status = MMUBusy
} else if strings.Contains(bufStr, "start") {
// Often "start" comes from MMU, filament sensor etc:
// msg="READING:MMU => 'start'"
// msg="READING:fsensor_oq_meassure_start"
// But the "important" initial start always comes with nothing extra.
// Though sometimes it has an old junk (thanks buffered I/O):
// msg="READING:\x1bstart"
// But still as "Suffix"
} else if strings.Contains(bufStr, "start") || strings.Contains(bufStr, "facebook") {
// When serial connection is established:
// Prusa MK3 returns "start"
// Prusa MK4 (Firmware Buddy) returns "facebook"
// We consider this event as "ready to print"
//
// If the first "start" is given - it says printer is ready
// If the second "start" is given - somebody reset the printer
Expand All @@ -178,6 +176,8 @@ func (f *Feeder) read(ctx context.Context) {
seenStart = true
f.printerAck <- true
} else if seenStart && strings.HasSuffix(bufStr, "start") {
// This is most likely a reset button press
// TODO: figure out what happens with mk4
log.Warning("Feeder: Second 'start' sequence")
return
}
Expand Down Expand Up @@ -229,6 +229,8 @@ func (f *Feeder) Feed() error {

// Flush whatever junk is in write buffer
_, _ = f.writer.Write([]byte("\n"))
// Issue a "firmware buddy" specific command to differentiate between mk3 and mk4
_, _ = f.writer.Write([]byte("M118 facebook\n"))
_ = f.writer.Flush()
// Be sure we receive initial reset from printer
<-f.printerAck
Expand Down
Loading