shermp / go-fbink-v2

Go FBInk wrapper, Vers. 2
GNU Affero General Public License v3.0
13 stars 2 forks source link

PrintRBGA issue #16

Closed takov751 closed 7 months ago

takov751 commented 7 months ago

Greetings,

I am trying to use this library PrintRBGA function with a function that returns *image.RGBA . Any ideas ? running on kobo Glo HD. returns error:

[FBInk] mmap: No such device!
[FBInk] Failed to display image data on screen!
func GetImg(url string) (m *image.RGBA) {
    http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{InsecureSkipVerify: true}
    resp, err := http.Get(url)
    if err != nil {
        log.Fatal(err)
    }
    defer resp.Body.Close()
    if resp.StatusCode != 200 {
        log.Fatal("no image downloaded", resp.StatusCode)
    }
    img, _, err := image.Decode(resp.Body)
    if err != nil {
        log.Fatal(err)
    }
    b := img.Bounds()
    m = image.NewRGBA(image.Rect(0, 0, b.Dx(), b.Dy()))
    draw.Draw(m, m.Bounds(), img, b.Min, draw.Src)
    return m
}
    fb.PrintRBGA(0, 0, GetImg(url), &fbinkOpts)
shermp commented 7 months ago

Hi, so it's been a long time since I've worked on this so my memory is rather hazy...

Did you make sure to call fb.Init() before attempting to print anything?

takov751 commented 7 months ago

Thanks for the quick reply.

Yes i did called init(), but in function main. So do i need to call init in this function as well? So is it init, open and close fb in this function every time it is called or there's a more efficient way?

shermp commented 7 months ago

Nah, I think Init() only needs to be called once. Again, memory is hazy, apologies. @NiLuJe might have an idea, although this library is now using a very old version of FBink so...

takov751 commented 7 months ago

After i include init in function it's working now, however i will have to find some solution to not mess with memory. So it seems i need to start doing some asynchronous stuff. I am watching kobo input events and trying to trigger printing based on touch and network events.

I am trying to turn my kobo reader into a streamdeck/ dashboard unit maybe use it for some home assistant stuff

takov751 commented 7 months ago

Solved by running fbink module as a goroutine and i have prepared 2 channels for text and image url to be watched continuously. So now it's working . Thanks for your work and time and for @NiLuJe for all the extreme effort that makes repurposing these devices way more easier.

So project kobodeck/kobodash incoming

NiLuJe commented 7 months ago

Assuming Init maps to fbink_init, you do need to call it at least once. In C, The FBInkConfig struct that it takes can then be duplicated if you need multiple sets of configs, but I couldn't say whether that's doable with the Go wrappers of that ;).

Regardless, it's safe to Init multiple times anyway (it certainly is in C, again, assuming there's nothing internal/opaque being done in the Go objects there). (e.g., some config fields require an init to "take", so calling it multiple times needs to be safe ;)).