Wiadomość napisana przez Bakul Shah <ba...@bitblocks.com> w dniu 10 maj 2014, o 
godz. 01:21:

> On Fri, 09 May 2014 16:11:00 +0200 Krystian Lewandowski 
> <krystian....@gmail.com> wrote:
>> 
>> I was working on GPIO under Plan9 - very simple thing but also supports
>> edge-raising/falling events. I had simple C code to print what pin
>> triggered an event. I'll try to push this simple test to github during
>> weekend. Though i'm not sure how it can be integrated - is events counting
>> enough?
> 
> I think for a rotary encoder you'd want to know about every
> transition. One idea is to return 1/0 on a up/down transition
> to a blocking read. Let the user re-enable the corresponding
> interrupt by writing 1 to the same fd.
> 
> The user code reads from two pins and figures out which way
> the knob is turning. Similarly you can have user code count
> events if that is what you want.
> 


Hi,
i’ve added a simple edge events listener test. 

The test reads 32 bits from #G/gpio/event where each bit position corresponds 
to „bcm” naming scheme, so bit 17 means GPIO0 (was easier this way).
#G/gpio/event blocks on read, while #G/gpio/GPIO0 does not - just returns 
current value (and there is no need to seek to beginning).

Works with a single button. ;)

https://github.com/elewarr/gpio_test/blob/master/events.c

cpu% ./events
1: pin 17, state changed
        GPIO0 state=0
2: pin 17, state changed
        GPIO0 state=1
3: pin 17, state changed
        GPIO0 state=0
4: pin 17, state changed
        GPIO0 state=1

Cheers,
Krystian

Reply via email to