Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pingo.jl #1

Open
s-celles opened this issue Apr 25, 2016 · 3 comments
Open

Pingo.jl #1

s-celles opened this issue Apr 25, 2016 · 3 comments

Comments

@s-celles
Copy link
Member

s-celles commented Apr 25, 2016

Pingo.jl

An input/output library based on https://github.com/aviks/PiGPIO.jl (for RaspberryPi)
but that could be use for other board also

inspired by https://github.com/pingo-io/pingo-py

and https://github.com/RPi-Distro/python-gpiozero/

A possible "parts" (just led) API usage might be

using Pingo

board = Board()  # or Board('rpi')
pin = Pin(board, 17)  # should we use BCM or BOARD numbering ? probably BCM
# pin = Pin(board, BCM(17))
led = Led(pin)
while true
    on(led)  # or switch_on(led)
    sleep(1)
    off(led)  # or switch_off(led)
    sleep(1)
end

pin might be an integer or a DigitalPin
board shouldn't be necessary (if no board is given we should use a DefaultBoard object)

An example with led and button

board = Board()
led = Led(board, 17)
button = Button(board, 3)

while true
    if ispressed(button)
        on(led)
    else
        off(led)
    end
    sleep(0.01)
end

an other (maybe harder to implement) might be

board = Board()
led = Led(board, 17)
button = Button(board, 3)

# make_callback(when_pressed, button, led, on)  # or make_callback(button, when_pressed, led, on) 
# make_callback(when_released, button, led, off)

# connect(button, when_pressed, led, on)
# connect(button, when_released, led, off)

button.when_pressed = () -> on(led)
button.when_released = () -> off(led)

wait_events()

with

function wait_events(; delay=0.01)
    while true
        sleep(delay)
    end
end

keywords: callback ; event driven programming ; signal slot ; publish subscribe ; pattern ; dispatch module ; observer pattern ; message ; messaging ; dispatching

@s-celles
Copy link
Member Author

s-celles commented Apr 25, 2016

These "parts" API will be on top of an intermediate level API (to define)

board = Board()
led_pin = Pin(board, 13)
mode(led_pin, OUTPUT::MODE)  # OUTPUT::MODE being an Enum

while true
    hi(led_pin)
    sleep(1)
    lo(led_pin)
    sleep(1)
end

JuliaBerry/PiGPIO.jl#2 (comment)

@s-celles
Copy link
Member Author

s-celles commented Apr 26, 2016

https://gist.github.com/scls19fr/0e95131dc3ec6cd061da11377445215d

see also about pingo (Python IO for several board) and https://github.com/RPi-Distro/python-gpiozero/

https://github.com/pingo-io/pingo-py/issues/110#issuecomment-199737920

@s-celles
Copy link
Member Author

s-celles commented May 14, 2017

(Auto)Conversion of parameters (for an easier approach)
https://discourse.julialang.org/t/conversion-of-parameters-in-function-call/3693/4

struct Pin  # struct (v>=0.6)
    number::Int
end

struct State  # struct (v>=0.6)
    val::Int
end

function set(pin::Pin, state::State)
    println(pin)
end

function set(pin, state)
    pin = convert(Pin, pin)
    state = convert(State, state)
    set(pin, state)
end

convert(::Type{Pin}, pin::Int) = Pin(pin)
convert(::Type{Pin}, pin::Pin) = pin

#function convert(::Type{State}, state::Int)
#    if state in [0, 1]
#        State(state)
#    else
#        error("state must be 0 or 1")
#    end
#end
#
convert(::Type{State}, state::Int) = state in [0, 1] ? State(state) : error("state must be 0 or 1")
convert(::Type{State}, state::State) = state

pin = Pin(10)
state = State(0)
set(pin, state)


set(10, 0)

#set(10, 100)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant