inkview

package module
v0.0.0-...-055c458 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 29, 2021 License: MIT Imports: 14 Imported by: 0

README

Go SDK for Pocketbook

Unofficial Go SDK for Pocketbook based on libinkview.

Supports graphical user interfaces and CLI apps.

Forked from github.com/dennwc/inkview

Submit tickets to todo.sr.ht/~ghost08/inkview, or via mail ~ghost08/inkview@todo.sr.ht.

Submit patches to lists.sr.ht/~ghost08/inkview, or via mail ~ghost08/inkview@lists.sr.ht.

Install

For your convenience there is a docker-compose.yaml.

git clone https://git.sr.ht/~ghost08/inkview
cd inkview
docker-compose build

will create a container (it will take a while), which can be used to compile a go program.

Build an app with UI

Example code (myawesomeapp.go):

package main

import (
	"context"
	"fmt"
	"io"

	ink "git.sr.ht/~ghost08/inkview"
)

func main() {
	ink.RunCLI(func(ctx context.Context, w io.Writer) error {
		fmt.Fprintln(w, "Device:")
		fmt.Fprintln(w, ink.DeviceModel())
		fmt.Fprintln(w, ink.SoftwareVersion())
		fmt.Fprintln(w, ink.HwAddress())
		fmt.Fprintln(w)

		for _, name := range ink.Connections() {
			fmt.Fprintf(w, "conn: %q", name)
		}
		return nil
	}, nil)
}

(also use the go mod init and go mod tidy stuff)

To build your app run (requires Docker):

docker run --rm -v $PWD:/app ghost08/pocketbook-go-sdk build -o myawesomeapp.app

To run an binary, copy it into applications/myawesomeapp.app folder on the device and it should appear in the applications list.

Notes on networking

By default, device will try to shutdown network interface to save battery, thus you will need to call SDK functions to keep device online (see KeepNetwork).

Also note that establishing TLS will require Go to read system certificate pool that might take up to 30 sec on some devices and will lead to TLS handshake timeouts. You will need to call InitCerts first to fix the problem.

IPv6 is not enabled on some devices, thus a patch to Go DNS lib is required to skip lookup on IPv6 address (SDK already includes the patch). Similar problems may arise when trying to dial IPv6 directly.

Notes on workdir

Application will have a working directory set to FS root, and not to a parent directory. To use relative paths properly change local dir to a binary's parent directory: os.Chdir(filepath.Dir(os.Args[0])).

Documentation

Index

Constants

View Source
const (
	KeyStateDown    = KeyState(C.EVT_KEYDOWN)
	KeyStatePress   = KeyState(C.EVT_KEYPRESS)
	KeyStateUp      = KeyState(C.EVT_KEYUP)
	KeyStateRelease = KeyState(C.EVT_KEYRELEASE)
	KeyStateRepeat  = KeyState(C.EVT_KEYREPEAT)
)
View Source
const (
	PointerUp   = PointerState(C.EVT_POINTERUP)
	PointerDown = PointerState(C.EVT_POINTERDOWN)
	PointerMove = PointerState(C.EVT_POINTERMOVE)
	PointerLong = PointerState(C.EVT_POINTERLONG)
	PointerHold = PointerState(C.EVT_POINTERHOLD)
)
View Source
const (
	TouchUp   = TouchState(C.EVT_TOUCHUP)
	TouchDown = TouchState(C.EVT_TOUCHDOWN)
	TouchMove = TouchState(C.EVT_TOUCHMOVE)
)
View Source
const (
	KeyBack   = Key(C.KEY_BACK)
	KeyDelete = Key(C.KEY_DELETE)
	KeyOk     = Key(C.KEY_OK)
	KeyUp     = Key(C.KEY_UP)
	KeyDown   = Key(C.KEY_DOWN)
	KeyLeft   = Key(C.KEY_LEFT)
	KeyRight  = Key(C.KEY_RIGHT)
	KeyMinus  = Key(C.KEY_MINUS)
	KeyPlus   = Key(C.KEY_PLUS)
	KeyMenu   = Key(C.KEY_MENU)
	KeyMusic  = Key(C.KEY_MUSIC)
	KeyPower  = Key(C.KEY_POWER)
	KeyPrev   = Key(C.KEY_PREV)
	KeyNext   = Key(C.KEY_NEXT)
	KeyPrev2  = Key(C.KEY_PREV2)
	KeyNext2  = Key(C.KEY_NEXT2)
)
View Source
const (
	Orientation0   = Orientation(C.ROTATE0)
	Orientation90  = Orientation(C.ROTATE90)
	Orientation180 = Orientation(C.ROTATE180)
	Orientation270 = Orientation(C.ROTATE270)
)
View Source
const (
	DefaultFont           = string(C.DEFAULTFONT)
	DefaultFontBold       = string(C.DEFAULTFONTB)
	DefaultFontItalic     = string(C.DEFAULTFONTI)
	DefaultFontBoldItalic = string(C.DEFAULTFONTBI)
	DefaultFontMono       = string(C.DEFAULTFONTM)
)
View Source
const (
	Info     = Icon(C.ICON_INFORMATION)
	Question = Icon(C.ICON_QUESTION)
	Warning  = Icon(C.ICON_WARNING)
	Error    = Icon(C.ICON_ERROR)
)

Variables

View Source
var (
	Black     = color.Black
	White     = color.White
	DarkGray  = color.Gray{0x55}
	LightGray = color.Gray{0xaa}
)
View Source
var DefaultDelay = time.Second
View Source
var DefaultFontHeight = 14
View Source
var (
	ErrNoConnections = errors.New("no connections available")
)

Functions

func BatteryPower

func BatteryPower() int

func CharWidth

func CharWidth(c rune) int

func ClearScreen

func ClearScreen()

ClearScreen fills current canvas with white color.

func Connect

func Connect(name string) error

func Connections

func Connections() []string

Connections returns all available network connections. Name can be used as an argument to Connect.

func DeviceKey

func DeviceKey() string

func DeviceModel

func DeviceModel() string

func DimArea

func DimArea(r image.Rectangle, cl color.Color)

func DisableExitHourglass

func DisableExitHourglass()

func Disconnect

func Disconnect() error

func DrawLine

func DrawLine(p1, p2 image.Point, cl color.Color)

func DrawPixel

func DrawPixel(p image.Point, cl color.Color)

func DrawRect

func DrawRect(r image.Rectangle, cl color.Color)

func DrawSelection

func DrawSelection(r image.Rectangle, cl color.Color)

func DrawString

func DrawString(p image.Point, s string)

func DrawStringR

func DrawStringR(p image.Point, s string)

func Errorf

func Errorf(title, format string, args ...interface{})

func Exit

func Exit()

Exit can be called to exit an application event loop.

func FillArea

func FillArea(r image.Rectangle, cl color.Color)

func FullUpdate

func FullUpdate()

FullUpdate sends content of the whole screen buffer to display driver. Display depth is set to 2 bpp (usually) or 4 bpp if necessary. Function isn't synchronous i.e. it returns faster, than display is redrawn. Update is performed for active app (task) only, if display isn't locked and NO_DISPLAY flag in ivstate.uiflags isn't set.

Usage: Tradeoff between quality and speed. Recommended for text and common UI elements. Not recommended if quality of picture (image) is required, in such case use FullUpdateHQ().

func HardwareType

func HardwareType() string

func HideHourglass

func HideHourglass()

func HwAddress

func HwAddress() string

HwAddress returns device MAC address.

func Infof

func Infof(title, format string, args ...interface{})

func InitCerts

func InitCerts() error

InitCerts will read system certificates pool.

This pool is usually populated by the first call to tls.Dial or similar, but this operation might take up to 30 sec on some devices, leading to handshake timeout.

Calling this function before dialing will fix the problem.

func InvertArea

func InvertArea(r image.Rectangle)

func InvertAreaBW

func InvertAreaBW(r image.Rectangle)

func IsCharging

func IsCharging() bool

func IsPressed

func IsPressed(key Key) bool

func IsSDinserted

func IsSDinserted() bool

func IsUSBconnected

func IsUSBconnected() bool

func KeepNetwork

func KeepNetwork() (func(), error)

KeepNetwork will connect a default network interface on the device and will keep it enabled. Returned function can be called to disconnect an interface.

func Message

func Message(icon Icon, title, text string, dt time.Duration)

func OpenMainMenu

func OpenMainMenu()

func OpenNetworkInfo

func OpenNetworkInfo()

func Pad

func Pad(r image.Rectangle, n int) image.Rectangle

func PartialUpdate

func PartialUpdate(r image.Rectangle)

PartialUpdate sends content of the given rectangle in screen buffer to display driver. Function is smart and tries to perform the most suitable update possible: black and white update is performed if all pixels in given rectangle are black and white. Otherwise grayscale update is performed. If whole screen is specified, then grayscale update is performed.

func PowerOff

func PowerOff()

func Questionf

func Questionf(title, format string, args ...interface{})

func Repaint

func Repaint()

Repaint puts Draw event into app's events queue. Eventually Draw method will be called on app object.

Usage: Call Repaint to make app (eventually) redraw itself on the screen.

func Run

func Run(app App) error

Run starts main event loop. It should be called before calling any other function.

func RunCLI

func RunCLI(fnc RunFunc, c *RunConfig) error

RunCLI starts a command-line application that can write to device display. Context will be cancelled when application is closed. Provided callback can use any SDK functions.

func Screen

func Screen() image.Rectangle

func ScreenSize

func ScreenSize() image.Point

func SerialNumber

func SerialNumber() string

func SetAutoPowerOff

func SetAutoPowerOff(on bool)

func SetClip

func SetClip(r image.Rectangle)

func SetErr

func SetErr(err error)

func SetSleepMode

func SetSleepMode(on bool)

func SetTextStrength

func SetTextStrength(n int)

func ShowHourglass

func ShowHourglass()

func ShowHourglassAt

func ShowHourglassAt(p image.Point)

func Sleep

func Sleep(dt time.Duration, deep bool)

func SleepMode

func SleepMode() bool

func SoftUpdate

func SoftUpdate()

SoftUpdate is an alternative to FullUpdate. It's effect is (almost) PartialUpdate for the whole screen.

func SoftwareVersion

func SoftwareVersion() string

func StringWidth

func StringWidth(s string) int

func Temperature

func Temperature() int

func Warningf

func Warningf(title, format string, args ...interface{})

func WirelessNetworks

func WirelessNetworks() []string

Types

type App

type App interface {
	// Init is called when application is started.
	Init() error
	// Close is called before exiting an application.
	Close() error

	// Draw is called each time an application view should be updated.
	// Can be queued by Repaint.
	Draw()

	// Key is called on each key-related event.
	Key(e KeyEvent) bool
	// Pointer is called on each pointer-related event.
	Pointer(e PointerEvent) bool
	// Touch is called on each touch-related event.
	Touch(e TouchEvent) bool
	// Orientation is called each time an orientation of device changes.
	Orientation(o Orientation) bool
}

type Font

type Font struct {
	// contains filtered or unexported fields
}

func OpenFont

func OpenFont(name string, size int, aa bool) *Font

func (*Font) Close

func (f *Font) Close()

func (*Font) SetActive

func (f *Font) SetActive(cl color.Color)

type Icon

type Icon int

type Key

type Key int

Key is a key code for buttons.

type KeyEvent

type KeyEvent struct {
	Key   Key
	State KeyState
}

type KeyState

type KeyState int

type Log

type Log struct {
	Spacing int // line spacing
	// contains filtered or unexported fields
}

func NewLog

func NewLog(r image.Rectangle, sz int) *Log

func (*Log) Close

func (l *Log) Close()

func (*Log) Draw

func (l *Log) Draw()

func (*Log) Printf

func (l *Log) Printf(format string, args ...interface{}) error

func (*Log) Println

func (l *Log) Println(args ...interface{}) error

func (*Log) Write

func (l *Log) Write(p []byte) (int, error)

func (*Log) WriteString

func (l *Log) WriteString(s string) error

type NetError

type NetError struct {
	Code int
	Text string
}

func (NetError) Error

func (e NetError) Error() string

type Orientation

type Orientation int

type PointerEvent

type PointerEvent struct {
	image.Point
	State PointerState
}

type PointerState

type PointerState int

type RunConfig

type RunConfig struct {
	Certs   bool // initialize certificate pool
	Network bool // keep networking enabled while app is running
}

type RunFunc

type RunFunc func(ctx context.Context, w io.Writer) error

type TouchEvent

type TouchEvent struct {
	image.Point
	State TouchState
}

type TouchState

type TouchState int

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL