ink

package module
v0.3.14 Latest Latest
Warning

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

Go to latest
Published: May 5, 2025 License: MIT Imports: 17 Imported by: 5

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 (
	FlashDir          = "/mnt/ext1"
	SdCardDir         = "/mnt/ext2"
	UsbDir            = "/mnt/ext3"
	SystemData        = "/ebrmain"
	UserData          = "/mnt/ext1/system"
	UserData2         = "/mnt/ext2/system"
	TempDir           = "/tmp"
	SystemFontDir     = "/ebrmain/fonts"
	UserFontDir       = "/mnt/ext1/system/fonts"
	TempFontPath      = "/tmp/fonts"
	PhotoTempDir      = "/tmp/photo"
	UserProfiles      = "/mnt/ext1/system/profiles"
	UserProfiles2     = "/mnt/ext2/system/profiles"
	CurrentProfile    = "/mnt/ext1/system/profiles/.current"
	LastProfile       = "/mnt/ext1/system/profiles/.last"
	SalvageProfiles   = "/mnt/ext1/system/profiles/.salvage"
	ConfigPath        = "/mnt/ext1/system/config"
	StatePath         = "/mnt/ext1/system/state"
	SystemThemesPath  = "/ebrmain/themes"
	UserThemesPath    = "/mnt/ext1/system/themes"
	GlobalConfigFile  = "/mnt/ext1/system/config/global.cfg"
	NetworkConfigFile = "/mnt/ext1/system/config/network.cfg"
	TsCalData         = "/mnt/ext1/system/config/tsc.dat"
	TsCalData2        = "/tmp/tsc.dat"
	SystemLangPath    = "/ebrmain/language"
	UserLangPath      = "/mnt/ext1/system/language"
	SystemKbdPath     = "/ebrmain/language/keyboard"
	UserKbdPath       = "/mnt/ext1/system/language/keyboard"
	SystemDictPath    = "/ebrmain/dictionaries"
	UserDictPath1     = "/mnt/ext1/system/dictionaries"
	UserDictPath2     = "/mnt/ext2/system/dictionaries"
	SystemLogoPath    = "/ebrmain/logo"
	UserLogoPath      = "/mnt/ext1/system/logo"
	NotesPath         = "/mnt/ext1/notes"
	GamePath          = "/mnt/ext1/applications"
	UserAppDir        = "/mnt/ext1/system/bin"
	CachePath         = "/mnt/ext1/system/cache"
	BackupDir         = "/mnt/ext2/backup"
	UserBookshelf     = "/mnt/ext1/system/bin/bookshelf.app"
	SystemBookshelf   = "/ebrmain/bin/bookshelf.app"
	UserMpd           = "/mnt/ext1/system/bin/mpd.app"
	SystemMpd         = "/ebrmain/bin/mpd.app"
	StateCleaner      = "/ebrmain/bin/cleanstate.sh"
	BackupScript      = "/ebrmain/bin/backup.sh"
	RestoreScript     = "/ebrmain/bin/restore.sh"
	NetAgent          = "/ebrmain/bin/netagent"
	BooklandApp       = "/ebrmain/bin/bookland.app"
	UserMplayer       = "/mnt/ext1/system/bin/mplayer.so"
	UserBookinfo      = "/mnt/ext1/system/bin/bookinfo.so"
	PocketbookSig     = "/mnt/ext1/system/.pocketbook"
	LastOpenBooks     = "/mnt/ext1/system/state/lastopen.txt"
	Favorites         = "/mnt/ext1/system/favorite"
	CurrentBook       = "/tmp/.current"
	BookshelfState    = "/tmp/.bsstate"
	BookshelfStateNv  = "/mnt/ext1/system/state/.bsstate"
	HistoryFile       = "/tmp/history.txt"
	DicKeyboard       = "/tmp/dictionary.kbd"
	PlaylistFile      = "/tmp/playlist.pls"
	NetAgentLog       = "/tmp/netagent.log"
	AdobePath         = "/mnt/ext1/.adobe-digital-editions"
	AdobePath2        = "/mnt/ext2/.adobe-digital-editions"
	HandlersPath      = "/mnt/ext1/system/config/handlers.cfg"
	UrlHistory        = "/mnt/ext1/system/cache/urlhistory.txt"
	WebCache          = "/tmp/webcache"
	WebCacheIndex     = "/tmp/webcache/index"
	WidgetsConfig     = "/mnt/ext1/system/config/widgets"
	WidgetsOpen       = "/mnt/ext1/system/config/widgets/open.cfg"
)
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 AddTranslation

func AddTranslation(label, trans string)

Add translation text that will later be used in getLangText

func BatteryPower

func BatteryPower() int

func CharWidth

func CharWidth(c rune) int

func ClearScreen

func ClearScreen()

ClearScreen fills current canvas with white color.

func CloseKeyboard

func CloseKeyboard()

Close keyboard layout

func CloseProgressbar

func CloseProgressbar()

func Connect

func Connect(name string) error

func ConnectDefault

func ConnectDefault() error

Obtained through reverse engineering, automatically connecting to the network and maintaining an active connection requires passing null instead of the network name. If not connected display network select or warning message, return error if connection failed

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 Dialog

func Dialog(icon Icon, title, text, button1, button2 string)

func DimArea

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

func DisableExitHourglass

func DisableExitHourglass()

func Disconnect

func Disconnect() error

func DitherArea

func DitherArea(r image.Rectangle, levels int, method int)

https://en.wikipedia.org/wiki/Dither

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 DrawTopPanel

func DrawTopPanel()

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 GetConfig

func GetConfig() (map[string]string, error)

func GetCurrentLang

func GetCurrentLang() string

func GetLangText

func GetLangText(s string) string

Get text with translation, translation variables can be found only in original pocketbook apps

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 LoadKeyboard

func LoadKeyboard()

Probably changes the keybaord language

func LoadLanguage

func LoadLanguage(lang string)

Probably changes the language the app should run in, translations depend on it

func Message

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

func OpenBook

func OpenBook(path string)

open the book in the default reader. If the .app file, then run the application

func OpenCustomKeyboard

func OpenCustomKeyboard(keyboardFileName, placeholder string, buflen int)

Open keyboard from .kbd file

func OpenKeyboard

func OpenKeyboard(placeholder string, buflen int)

Open default keyboard

func OpenMainMenu

func OpenMainMenu()

func OpenNetworkInfo

func OpenNetworkInfo()

func OpenProgressbar

func OpenProgressbar(icon Icon, title, text string, percent int)

Use dialog handler for callback

func OpenRotateBox

func OpenRotateBox()

func OpenTimeEdit

func OpenTimeEdit(title string, p image.Point, initime time.Time)

func Pad

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

func PageSnapshot

func PageSnapshot()

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 PartialUpdateBW

func PartialUpdateBW(r image.Rectangle)

func PowerOff

func PowerOff()

func QueryNetwork

func QueryNetwork()

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 SetDefaultOrientation

func SetDefaultOrientation(orientation Orientation)

Original pb apps prefer to use setDefaultOrientation on init action (It's an undocumented function, found by reverse engineering)

func SetDialogHandler

func SetDialogHandler(handler DialogHandler)

func SetErr

func SetErr(err error)

func SetGlobalOrientation

func SetGlobalOrientation(orientation Orientation)

func SetKeyboardHandler

func SetKeyboardHandler(kh KeyboardHandler)

func SetMessageDelay

func SetMessageDelay(time time.Duration)

func SetOrientation

func SetOrientation(orientation Orientation)

func SetRotateBoxHandler

func SetRotateBoxHandler(handler RotateBoxHandler)

func SetSleepMode

func SetSleepMode(on bool)

func SetTextStrength

func SetTextStrength(n int)

func SetTimeEditHandler

func SetTimeEditHandler(handler TimeEditHandler)

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 UpdateProgressbar

func UpdateProgressbar(text string, percent 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 DialogHandler

type DialogHandler func(button int)

return 1 for left button, 2 for right button. 1 for progressbar cancel button

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 KeyboardHandler

type KeyboardHandler func(string)

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

func GetGlobalOrientation

func GetGlobalOrientation() Orientation

func GetOrientation

func GetOrientation() Orientation

type PointerEvent

type PointerEvent struct {
	image.Point
	State PointerState
}

type PointerState

type PointerState int

type RotateBoxHandler

type RotateBoxHandler func(Orientation)

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 TimeEditHandler

type TimeEditHandler func(time time.Time)

type TouchEvent

type TouchEvent struct {
	image.Point
	State TouchState
}

type TouchState

type TouchState int

Directories

Path Synopsis
examples
devinfo command

Jump to

Keyboard shortcuts

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