Overview WHOLE CHAPTER IN ONE FILE INTRODUCTION A practical, example-driven guide to building plugins for CrossPoint Reader (https://github.com/crosspoint-reader/crosspoint-reader) e-reader firmware. The official docs (docs/sd-plugins.md, docs/plugin-events.md, docs/webserver-endpoints.md in the firmware repo) are accurate, but they are written for firmware developers. They spread one topic over several files and leave out details you only find in the source. This guide was put together by reading the firmware source (the develop branch). Where the official docs and the code disagree, this guide follows the code and says so. WHAT IS A CROSSPOINT PLUGIN? A plugin is a folder on the SD card. You never rebuild firmware. Copy the folder onto the card and the reader finds it. /plugins/my-plugin/ +-- manifest.json <- name, version, where the web UI shows it (optional) +-- plugin.js <- JavaScript that runs in your BROWSER (optional) +-- device.json <- declarative catalog/events that run ON THE READER (optional) +-- README.md <- help text shown on the reader (optional) +-- ...anything else (icons, config.json, token.json, extra JS) A folder counts as a plugin if it has at least one of manifest.json, plugin.js or device.json. THE MENTAL MODEL: TWO PLACES CODE CAN RUN +------------------------------+ +----------------------------------+ | Your phone / laptop browser | Wi-Fi | The e-reader | | | <------> | | | plugin.js | | device.json (no code, only | | - real JavaScript | | declarative JSON config) | | - any UI, any logic | | - browse a JSON/XML catalog | | - reaches the internet | | - sign in (device code/password)| | THROUGH the reader | | - download books/files to SD | | (/api/relay, /api/fetch) | | - react to events (book closed, | | - only runs while a browser | | going to sleep...) with HTTP | | page is open | | requests | +------------------------------+ +----------------------------------+ ^ ^ +-------- they share files on the SD ------+ (config.json, token.json, sidecars) The most common pattern combines the two: plugin.js is the settings page (enter a server URL, sign in, save a token), and device.json does the daily work on the reader (browse, download, sync). They talk to each other only through files in the plugin folder. WHICH ONE DO I NEED? - Browse a library/catalog and download books on the reader, no phone needed: device.json catalog - Send something to a server when a book is closed / the reader sleeps: device.json events - Fetch a fresh sleep-screen image every night: device.json events -> sleep.enter download - A settings form, sign-in page, or any custom UI: plugin.js - Convert formats (HTML->EPUB), sign requests (OAuth 1.0a), scrape HTML: plugin.js - Tools that work on files already on the SD card (rename, organise): plugin.js with "mount": "files" - Let a script or app on another computer trigger plugin actions: plugin.js + job queue Rule of thumb from the firmware authors: if the service is "log in, list a JSON/XML catalog, download files", put it on the device. If it needs computed request bodies or format conversion, do it in the browser. End of this folder.