Adapters Run One System, Three Ways

The first boundary that interacts with hardware is an abstraction layer called an adapter. These layers let programmers present one interface and multiple implementations. The goal is to have one program that runs in three places with as little disruption as possible.

If you wanted to, you could add a bit of compiler safety with a behaviour.[43] We’re going to leave the behaviour implementation to you. Because Elixir is a dynamically typed language, all you technically need to do is provide adapter modules that present functions with the same names and arities.

Each of the adapters will handle a different use case. The test layer needs individual bits, the hardware layer needs binaries that work with Circuits.SPI ...

Get Build a Binary Clock with Elixir and Nerves now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.