Giter VIP home page Giter VIP logo

fbsd_gpio_py's Introduction

fbsd_gpio: cffi-based Python bindings for FreeBSD libgpio

Requirements:

  • Python 2.7 or 3.4
  • cffi

How to install

Python package on FreeBSD 11 have problem when using python source that needed to compile thing, so the easiest way is to use the binary packages uploaded to pypi:

pip install --only-binary freebsd-11 fbsd_gpio

How to use

The fbsd_gpio module expose two classes, GpioController and GpioPin

Use gpio controller unit 0 (/dev/gpioc0) and list all the pins name:

from fbsd_gpio import GpioController

gpioc = GpioController(0)
for pin in gpioc:
    print(pin)

Set pin 127 to output and logical value 1

from fbsd_gpio import GpioController, GPIO_VALUE_HIGH

gpioc = GpioController(0)
gpioc.pin_output(127)
# The two following lines are equivalent
gpioc.pin_set(127, GPIO_VALUE_HIGH)
gpioc.pin_high(127)

Alternativelly you can use the GpioPin class:

from fbsd_gpio import GpioPin, GPIO_VALUE_HIGH

pin = GpioPin(127, unit=0)
pin.ouput = True
# The following lines are equivalent
pin.set(GPIO_VALUE_HIGH)
pin.high()
pin(GPIO_VALUE_HIGH)

Or use the name of the pin directly:

from fbsd_gpio import GpioController, GPIO_VALUE_HIGH

gpioc = GpioController(0)
gpioc.gpioled0.output = True
# The three following lines are equivalent
gpioc.gpioled.set(GPIO_VALUE_HIGH)
gpioc.gpioled0.high()
gpioc.gpioled0(GPIO_VALUE_HIGH)

Get the value of a pin:

from fbsd_gpio import GpioPin

pin = GpioPin(128, unit=0)
if pin.input:
    print('Pin is input mode')
else
    print('Pin is output mode')
# The two following lines are equivalent
    value = pin.get()
    value = pin()

Toggle the value of a pin:

from fbsd_gpio import GpioPin

pin = GpioPin(128, unit=0)
pin.toggle()

Change the name of a pin:

from fbsd_gpio import GpioPin

pin = GpioPin(128, unit=0)
pin.name = 'green_led'

fbsd_gpio_py's People

Contributors

evadot avatar

Watchers

James Cloos avatar David BIEDER avatar

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.