First commit

This commit is contained in:
MassiveBox 2024-09-10 22:45:30 +02:00
commit 46926935fb
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
14 changed files with 1089 additions and 0 deletions

28
examples/00-knownMac.go Normal file
View file

@ -0,0 +1,28 @@
package main
import "git.massivebox.net/massivebox/go-catprinter"
func main() {
const mac = "41:c2:6f:0f:90:c7"
c, err := catprinter.NewClient()
if err != nil {
panic(err)
}
c.Debug.Log = true
opts := catprinter.NewOptions()
defer c.Stop()
if err = c.Connect(mac); err != nil {
panic(err)
}
err = c.PrintFile("../demo.jpg", opts)
if err != nil {
panic(err)
}
}

44
examples/01-unknownMac.go Normal file
View file

@ -0,0 +1,44 @@
package main
import (
"git.massivebox.net/massivebox/go-catprinter"
"log"
)
func main() {
const name = "x6h"
c, err := catprinter.NewClient()
if err != nil {
panic(err)
}
c.Debug.Log = true
opts := catprinter.NewOptions()
defer c.Stop()
// let's find the MAC from the device name
var mac string
devices, err := c.ScanDevices(name)
if err != nil {
panic(err)
}
for deviceMac, deviceName := range devices {
// you should ask the user to choose the device here, we will pretend they selected the first
log.Println("Connecting to", deviceName, "with MAC", deviceMac)
mac = deviceMac
break
}
if err = c.Connect(mac); err != nil {
panic(err)
}
err = c.PrintFile("../demo.jpg", opts)
if err != nil {
panic(err)
}
}

46
examples/02-options.go Normal file
View file

@ -0,0 +1,46 @@
package main
import (
"git.massivebox.net/massivebox/go-catprinter"
"image/jpeg"
"os"
)
func main() {
const mac = "41:c2:6f:0f:90:c7"
c, err := catprinter.NewClient()
if err != nil {
panic(err)
}
c.Debug.Log = true
defer c.Stop()
if err = c.Connect(mac); err != nil {
panic(err)
}
// note that for this we need to open the image as image.Image manually!
file, _ := os.Open("../demo.jpg")
defer file.Close()
img, _ := jpeg.Decode(file)
// for now, we will use default options
opts := catprinter.NewOptions()
fmtImg := c.FormatImage(img, opts)
// now you should display your image to the user and ask for what they want to change
// in this example, we will pretend they want to disable dithering
opts = opts.SetDither(false)
fmtImg = c.FormatImage(img, opts)
// you can show the image again and make all the adjustments you see fit with opts.SetXYZ
// when the user decides to print, we can use
err = c.Print(fmtImg, opts, true) // NOTE THE TRUE HERE! It means the image is already formatted
if err != nil {
panic(err)
}
}