Fixed unnecessary image load attempts
This commit is contained in:
parent
c35188639d
commit
201ea4ae14
9
main.go
9
main.go
@ -459,10 +459,8 @@ func findPrinter(ctx context.Context) (ble.Advertisement, error) {
|
|||||||
ctxScan, cancel := context.WithTimeout(ctx, scanTimeout)
|
ctxScan, cancel := context.WithTimeout(ctx, scanTimeout)
|
||||||
log.Println("Scanning for printer...")
|
log.Println("Scanning for printer...")
|
||||||
err := ble.Scan(ctxScan, false, func(a ble.Advertisement) {
|
err := ble.Scan(ctxScan, false, func(a ble.Advertisement) {
|
||||||
fmt.Printf("Found advertisement: %s, addr: %s\n", a.LocalName(), a.Addr())
|
|
||||||
if address != "" {
|
if address != "" {
|
||||||
if a.Addr().String() == addr.String() { // Wonder why this works and not direct comparison
|
if a.Addr().String() == addr.String() { // Wonder why this works and not direct comparison
|
||||||
println("Found target printer by address:", a.Addr())
|
|
||||||
adv = a
|
adv = a
|
||||||
cancel()
|
cancel()
|
||||||
}
|
}
|
||||||
@ -477,6 +475,7 @@ func findPrinter(ctx context.Context) (ble.Advertisement, error) {
|
|||||||
if adv == nil {
|
if adv == nil {
|
||||||
return nil, fmt.Errorf("printer not found")
|
return nil, fmt.Errorf("printer not found")
|
||||||
}
|
}
|
||||||
|
log.Println("Found target printer with address:", adv.Addr().String())
|
||||||
return adv, nil
|
return adv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -618,12 +617,14 @@ func main() {
|
|||||||
// Get image path
|
// Get image path
|
||||||
imagePath := flag.Arg(0)
|
imagePath := flag.Arg(0)
|
||||||
|
|
||||||
pixels, height := []byte(nil), int(0)
|
pixels, height, err := []byte(nil), int(0), error(nil)
|
||||||
|
|
||||||
pixels, height, err := loadAndProcessImage(imagePath, printMode, ditherType)
|
if imagePath != "" {
|
||||||
|
pixels, height, err = loadAndProcessImage(imagePath, printMode, ditherType)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Failed to load and process image: %v", err)
|
log.Fatalf("Failed to load and process image: %v", err)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if outputPath != "" {
|
if outputPath != "" {
|
||||||
var previewImg image.Image
|
var previewImg image.Image
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user