Giter VIP home page Giter VIP logo

i2c_server's Introduction

I2C Server

Hex.pm API docs CI

I2C Server wraps Circuits.I2C reference in a GenServer, creating a separate process per I2C bus. I2C bus processes are identified with a bus name (e.g., "i2c-1").

Installation

Just add i2c_server to your list of dependencies in mix.exs:

def deps do
  [
    {:i2c_server, "~> 0.2"}
  ]
end

Usage

# Get a PID for the device at the address 0x77 on the "i2c-1" bus
iex> {:ok, device} = I2cServer.start_link(bus_name: "i2c-1", bus_address: 0x77)
#PID<0.233.0>

# Write 0xff to the register 0x8A
iex> I2cServer.write(device, [0x8A, <<0xff>>])
:ok

# Read 3 bytes
iex> I2cServer.read(device, 3)
:ok

# Read 3 bytes from the register 0xE1
iex> I2cServer.write_read(device, 0xE1, 3)
{:ok, <<0, 0, 0>>}

# Do multiple operations sequentially blocking the bus worker process
iex> I2cServer.bulk(device, [
...>   {:write, [0xBA]},
...>   {:sleep, 10},
...>   {:write, [0xAC, <<0x33, 0x00>>]},
...>   {Process, :sleep, [10]},
...>   fn(_) -> "something" end
...> ])
[:ok, :ok, :ok, :ok, "something"]

I2C bus processes will be created under I2cServer.I2cBusSupervisor dynamically.

Configuration

You can change settings in your config file such as config/config.exs file.

Registry module

By default, I2C bus processes are stored in Registry, but you can alternatively use :global.

config :i2c_server,
  bus_registry_module: :global

i2c_server's People

Contributors

mnishiguchi avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

layeddie

i2c_server's Issues

Batch multiple commands

Maybe nice to be able to batch multiple commands so that we can ensure they are processed without interruption.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.