willprice / willprice.github.io

Will Price's personal website
0 stars 0 forks source link

Brother HL-5250DN #1

Open mkkot opened 1 year ago

mkkot commented 1 year ago

Hey man! Found your website https://www.willprice.dev/2021/04/16/brother-hl-5250dn-on-raspberry-pi.html while trying to make my printer work on Odroid M1.

I'm happy to report that this printer is working with driver Brother HL-2270DW series, using brlaser v6 (grayscale, 2-sided printing). It's available in https://packages.debian.org/bookworm/printer-driver-brlaser

On the client side I have the openprinting PPD for HL-5250DN with language level 2, but I don't think this matters too much.

What is nice is that I have duplex working with correct parameters, also horizontally and it's fast. Way faster than with using only PPD.

mkkot commented 1 year ago

I also wrote this little service to turn on the printer with Shelly Plug S when there's something to print:

package main

import (
    "log"
    "net/http"
    "net/url"

    "log/slog"
    "github.com/fsnotify/fsnotify"
)

func printerPowerOn() {
  _, err := http.PostForm("http://192.168.1.222/relay/0",
     url.Values{"turn": {"on"}})

     if err != nil {
        slog.Error("can not connect to shelly", err)
     } 
}

func main() {
    // Create new watcher.
    watcher, err := fsnotify.NewWatcher()
    if err != nil {
        log.Fatal(err)
    }
    defer watcher.Close()

    // Start listening for events.
    go func() {
        for {
            select {
            case event, ok := <-watcher.Events:
                if !ok {
                    return
                }
                log.Println("event:", event)
                if event.Has(fsnotify.Create) {
                    log.Println("Created file:", event.Name)
                    printerPowerOn()
                }

            case err, ok := <-watcher.Errors:
                if !ok {
                    return
                }
                log.Println("error:", err)
            }
        }
    }()

    // Add a path.
    err = watcher.Add("/var/spool/cups/tmp/")
    if err != nil {
        log.Fatal(err)
    }

    // Block main goroutine forever.
    <-make(chan struct{})
}