diff --git a/daemon.go b/daemon.go index 5ca86a4..d502299 100644 --- a/daemon.go +++ b/daemon.go @@ -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) } @@ -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 } @@ -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 } @@ -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 } diff --git a/fakejuggler/main.go b/fakejuggler/main.go index 5bd222f..81e20fd 100755 --- a/fakejuggler/main.go +++ b/fakejuggler/main.go @@ -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 { @@ -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") diff --git a/gcodefeeder/feeder.go b/gcodefeeder/feeder.go index 9adc9a6..1ef261e 100644 --- a/gcodefeeder/feeder.go +++ b/gcodefeeder/feeder.go @@ -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", @@ -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 @@ -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 } @@ -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