From 89fc9d86c727aa8dc80232b461a7903a3c16d10e Mon Sep 17 00:00:00 2001 From: Přemysl Janouch
Date: Fri, 12 Apr 2019 23:10:42 +0200 Subject: Cleanup, improve communication while printing --- label-exp/main.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) (limited to 'label-exp') diff --git a/label-exp/main.go b/label-exp/main.go index e15f71c..dd4f8c2 100644 --- a/label-exp/main.go +++ b/label-exp/main.go @@ -182,7 +182,6 @@ func getStatus(printer *ql.Printer) error { if err := printer.UpdateStatus(); err != nil { return err } - log.Printf("status\n%s", printer.LastStatus) return nil } @@ -192,17 +191,23 @@ func handle(w http.ResponseWriter, r *http.Request) { return } - var initErr error + var ( + initErr error + mediaInfo *ql.MediaInfo + ) printer, printerErr := getPrinter() if printerErr == nil { defer printer.Close() - initErr = getStatus(printer) - } + printer.StatusNotify = func(status *ql.Status) { + log.Printf("\x1b[1mreceived status\x1b[m\n%s", status) + } - var mediaInfo *ql.MediaInfo - if printer.LastStatus != nil { - mediaInfo = ql.GetMediaInfo(printer.LastStatus.MediaWidthMM(), - printer.LastStatus.MediaLengthMM()) + if initErr = getStatus(printer); initErr == nil { + mediaInfo = ql.GetMediaInfo( + printer.LastStatus.MediaWidthMM(), + printer.LastStatus.MediaLengthMM(), + ) + } } var params = struct { @@ -269,7 +274,7 @@ func main() { log.Fatalln(err) } - log.Println("Starting server") + log.Println("starting server") http.HandleFunc("/", handle) log.Fatal(http.ListenAndServe(":8080", nil)) } -- cgit v1.2.3-70-g09d2