-
Notifications
You must be signed in to change notification settings - Fork 39
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
Make Button Interface \sys
Device Based
#121
Comments
I don't see a problem with doing things this way. You should update http://www.ev3dev.org/docs/tutorials/using-ev3-buttons/ to explain how to accomplish the same thing without using an ioctl. |
Wait a minute. I thought you were saying that there was already a way to do this from |
By the way, proper use of the LCD screen requires ioctls as well. |
Well, the LCD needs IOCTLs now, but maybe we can fix that :-) Right now the Python API has a nice ButtonBase class that is extended to handle the remote control. So I'm talking about fixing the EVIO Button class which is just the EV3 front panel. The other way to do it is to write a little platform (or device) specific daemon than handles the ioctls that we care about through a I'm just throwing ideas out here - but the |
The linux input framework is really meant to be event based, which is why there is only an ioctl for this. You can read Another option is to use ev3dev kit. Since is uses gobject introspection, it is designed to be used by pretty much any language (except maybe bash). |
I am trying to make things as easy as possible for people getting into coding that don't think about event based frameworks as easily as "just give me a function call that returns the buttons that are pressed now" :-) Is a platform specific daemon a reasonable approach for languages that don't support blocking file reads and multithreading? The goal is to be able to read a file and get a list of buttons that are pressed. |
You have a bit of conflict of interests here I think. To get something in How many (reasonable) languages actually can't actually bind to C code or make syscalls? For example, a quick web search shows 2 different options that should work for Lua. I'm totally with you that we need something simpler, but we are dealing with the most ancient parts of the linux kernel, so it is not making it easy for us. |
Here's an idea. I was considering making a configfs sensor driver for userspace sensor drivers (I was mainly thinking of doing this for mindsensors.com BT sense android app). Basically you have to have a userspace program that sets up the driver via This could be used for the EV3 buttons. We just create a program that listens to the "EV3 Buttons" input/event device and pushes the information to the "sensor". The users can read the buttons just like a touch sensor. The What do you think? |
Yes, something like that could work - seems a bit roundabout but it's doable. Another option is to have a kernel module specifically for the EV3 buttons that does not interfere with the existing event driven button I/O. It creates a I know this is counter to the Linux input event handler, so I'm not suggesting we get rid of that - this is just another, hopefully easy way for button states to be read in a non-event capable language. |
I still don't like the idea of doing something "specifically for the EV3 buttons". If we are going to put the effort into it, I think we should do something that works for all linux input devices. If you are absolutely set on having something in sysfs, I think the most practical (and least amount of work) would be to add a If you want something that is only for EV3, then copy the But, I like the pythonic principal that there should only be one obvious way to do a thing. All of the raspberry pi blogs out there are going to tell you to read input events from |
One point for some universal solution (and against making a kernel module just for EV3 buttons): anything with a USB port may have a USB keyboard connected. It would be nice to be able to work with such keyboards in a generic way. I am aware that our current python API only provides interface to EV3 buttons, but as I understand, the buttons use generic event interface that could work with any kind of input devices. |
I was doing some reading and I think that a userland program that uses |
I mean libevdev :-) |
@dlech, I am coming around to the comment you made here - except that the sensor device should probably return a list of pressed button names instead of one button per This userland program that runs in the background might also be a handy way to manage the display interface, but that's for later... |
This comment asks the reasonable question of how many languages cannot bind to a C library - my goal is to require NO language specific C library bindings. At worst, a userspace program can be launched to provide what I might call a "universal" translation layer for the devices that need it. What I have now is a userspace program that uses Seems roundabout, but it really helps when your minimal scripting language has no support for doing event driven programming. |
I still think using configfs is the way to do this (as in #121 (comment)). You setup the virtual sensor using configfs then in |
I think we are in violent agreement :-) |
violent? 😆 |
OK, so how about I work on the configfs stuff and you handle the userspace program. |
Sure - if that works for you ... I have the userspace side roughed out (testing on my desktop). Basically the program accepts a device name that is scanned here:
In this case I'm concerned about the sensor values being one per button, can we have a sensor return a string of all pressed buttons (it would make our button class handler a lot easier) |
The current lego-sensor class does not know about strings. In other words, The way I was envisioning it is that if you want to read the value of one button, you read |
So does my userland driver write the total button state table to |
It will write the table to |
Each |
@dlech - one thing we could do is pass to the generic userland program a file that tells it which input device name or path to look for, what the configfs entry will be, and a proposed event/value mapping. Or three parameters:
If |
Minor point: Since the device path is I'm thinking that the configfs path will be the basename of http://www.freedesktop.org/software/systemd/man/udev.html lists the variables available from udev. I'm thinking |
I think we are converging on the right solution! |
Mapping file is optional - without it we need to scan this many events to see if the device handles them:
|
Have a look at |
Nice pointer - I knew there had to be a better way! So on the EV3:
correspond nicely with the values here. That gives us 4 64-bit values - and the rightmost bit of the rightmost value is 0 in the value field of the event type. |
OK, now that I'm looking at the actual current |
One more idea - what about a The Or we could allow text data from the |
I'll have to do some thinking on how these would fit in with the 40+ other sensor drivers we already have. |
Or we could make a pure - I know we really don't want to add yet another class to the system, but this might avoid making changes to the sensor class. |
This is sort of the direction I've been going. As I've been working on the, it has become clear that we need another device node in addition the the lego-sensor-class device. So, I'm making |
For future reference, this is how we callback from the kernel to userspace, for example if we need to implement more than one mode. |
Essentially data transfer via the |
I've pushed initial support for this in ev3dev/lego-linux-drivers@af71025. Let's see how far you can get with it the way it is before adding any new attributes. |
Is there currently a way to read button states without the need to poll for events in the userland program? BTW: On the EV3 |
There is an ioctl for that. |
While I appreciate the ability to use the standad Linux GPIO interface fo reading buttons, it is a total pain that there is not also a
/sys
interface to get button state.Currently, we require an
ioctl
to read the button state from user space, which is fine for scripting languages like Python that have anioctl
library. But it does not help that the only peripheral on the EV3 that requiresioctl
calls is the buttons, and for languages likeLua
or evenbash
andawk
we need to write a Language binding forioctl
and add it to the binding package.I can write a button class for
/sys
that works pretty much like the attribute system we have today, where querying the state simply returns a list of all the pressed buttons.Comments? Any reason why this is a particularly bad idea?
The text was updated successfully, but these errors were encountered: