Skip to main content

Inkshelf, explained

Inkshelf is an app for a PocketBook e-reader that reads comics, books and recipes from your own servers, written in pure Go, and drawing on the e-ink screen by itself, without the vendor's SDK.

This site explains how it works, from the first pixel to the last page. You need to know how to program. You do not need to know anything about e-readers, EPUB or Go's internals: every idea is introduced before it is used.

What Inkshelf does​

An e-reader is a small computer with a screen of e-inkE-ink: A display made of tiny capsules of black and white pigment, moved by electric fields. It keeps its image without power.: paper-like, easy on the eyes, and very slow. The one Inkshelf runs on is a PocketBook InkPad 3: a screen of 1404 × 1872 pixels, 16 shades of gray, a modest ARM processor.

Inkshelf connects that reader to three kinds of serverServer: Where books come from: Komga (comics), Mealie (recipes) or Calibre-Web (EPUB and CBZ). The app sees them through one Go interface. you may run at home:

You pick a book, it downloads, and you read it. Your progress goes back to the server, so another device opens the book where you left it.

A two-minute tour​

These are real screenshots, taken by the emulatorEmulator: A stand-in for the reader in a web page on your computer: the real event loop and screens, with a fake firmware., which runs the app on a computer against fake servers.

InteractiveThe app, screen by screen
Pick a server: The servers listed in config.json, here two fake ones run by the emulator.
1 / 10
Pick a server

The servers listed in config.json, here two fake ones run by the emulator.

Try this: Press Next to walk through the app, or Play to let it run. The black blink between shots is a nod to the e-ink flash.

Why it is interesting​

Most PocketBook apps are written in C against PocketBook's SDK, a library called libinkview that draws, refreshes the screen and reads the buttons for them. Inkshelf uses none of it. It is a plain Go program with no C code at all (no cgocgo: Go's bridge to C code. Inkshelf does not use it, so a plain go build makes the reader's program on any computer.), so one command builds it on any computer:

make build # CGO_ENABLED=0 GOOS=linux GOARCH=arm GOARM=7 go build … -o build/inkshelf.app ./cmd/inkshelf

So everything the SDK did, Inkshelf does itself, and that is what this site shows:

How to read this site​

The site is one path, from the easiest ideas to the hardest. Each part only uses what came before it.

  1. 1The big pictureA book’s whole trip, from the server to your eyes, and how the code is stacked in layers.●●●
  2. 2The screenE-ink, 16 grays, drawing without the vendor’s SDK, the firmware, the event loop, the emulator.●●●
  3. 3BooksWhat is inside an EPUB, how its CSS applies, how text is drawn in gray, how it becomes lines and lines become pages.●●●
  4. 4The appFrom a tap to a screen, one lock for many goroutines, three kinds of server, downloads, and syncing progress.●●●

Along the way:

When you want to read the code itself, A tour of the code gives the files to open for each part, in order, with a test or an emulator run at each stop.

The Reference (in the menu at the top) holds the precise, complete version of each chapter, for when you change the code. Each chapter links to its own.

What you need to know​

Nothing about e-readers. Some programming, in any language: Go code is shown in short snippets, and they read like most C-family languages. When a Go idea matters (a GoroutineGoroutine: Go’s lightweight thread. Inkshelf starts them only from the main thread, with state.Go., a MutexMutex: A lock: only one goroutine at a time may hold it, so they never change the same data at once.), the site explains it.

Start with A book's journey: one book, from the server to your eyes.