ink

package module
v0.0.0-...-a8a15d6 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 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.

Build a CLI app

Standard Go compiler should be able to cross-compile the binary for the device (no need for SDK):

GOOS=linux GOARCH=arm GOARM=5 go build main.go

Note that some additional workarounds are necessary if you want to access a network from your app. In this case you may still need SDK.

Although this binary will run on the device, you will need a third-party application to actually see an output of you program (like pbterm).

The second option is to wrap the program into RunCLI - it will emulate terminal output and write it to device display.

Preparation - Build or pull the Docker Image

You can pull a docker images from dockerhub:

docker pull 5keeve/pocketbook-go-sdk:6.3.0-b288-v1

To build this image on your own, feel free to use docker-compose.yaml.

docker-compose build

This will create a pb-go service which can be used to compile a go program.

Adjust the source path in docker-compose.yaml to your needs.

With the current settings you can compile the test programs.

E.g.:

docker-compose run --rm pb-go build ./sqlitetst.dir/sqlitetst.go

Note In order to see some output for this, you need to run in using something like pbterm. If you just start it without pbterm you can verify successful execution by attaching your device to your computer and check for the presence of the file sqlite-database.db.

docker-compose run --rm pb-go build ./devinfo/main.go

Alternatively, after building the image, docker can be used to compile without adjusting the file.

Build an app with UI

To build your app or any example, run (requires Docker):

cd ./examples/sqlitetst.dir/
docker run --rm -v $PWD:/app dennwc/pocketbook-go-sdk build -o sqlitetst.app
cd ./examples/devinfo/
docker run --rm -v $PWD:/app dennwc/pocketbook-go-sdk
mv app devinfo.app

You may also need to mount GOPATH to container to build your app:

docker run --rm -v $PWD:/app -v $GOPATH:/gopath dennwc/pocketbook-go-sdk

To run an binary, copy it into applications/app-name.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

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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