configbutton Plugin Development guide?


hmc

Active Member
Joined
Dec 19, 2011
Messages
787
Location
Bavaria, Germany
Hi guys,


somewhere on these boards there was a short tutorial, that explained, how to write a plugin for sleashjag's configbutton utility.


I'd like to write a Plugin for fast keyboard layout switching, that uses the existing kblayout PND used by the keyboard layout switcher in the settings menu.


Thank you,


Daniel
 
It's really really easy. Just look at the github source of the existing ones, or my USBHost plugin code. You literally implement two functions IIRC
 
I know that it's easy. However, I still lack some basics. ;-) Where do I find that source code of your USBHost Plugin? How do I compile such code, so that it becomes an object file rather than an executable (IIRC the Plugins are .so files?), and where do I need to put that object file?
 
Ah, sorry.


Well, I use Sebt3's VM, so it's just a simple compile from there (I use Code::Blocks). You want to compile it as a dynamic library (.so). I can't remember the exact destination atm, I'll look it up.


I've attached my mass storage module code, should show you how to make menus with submenus.


Edit: .so's need to be copied to /usr/share/configbutton; IIRC you need to sudo when you copy
 

Attachments

  • usbmass.txt
    1.4 KB · Views: 214
Last edited by a moderator:
I am just writing a new Configbutton Plugin for controlling my LED keyboard illumination.

It's almost finished. But there is one problem:

From the Plugin I issue the command

sprintf(cmdline, "echo %d > /sys/class/leds/pandora::keypad_bl/brightness", brightness);
system(cmdline);
but when I click on the Plugin's config button menu item, this results in (on the console)
Code:
sh: can't create /sys/class/leds/pandora::keypad_bl/brightness: Permission denied
Why does it want to create "brightness"? It exists already. I suspect it has to do with the two colons in the path. Do I have to escape them in the Plugin code in some way?Or is there another reason I cannot see currently?

Thanks a lot!
 
Last edited by a moderator:
I tried now:


sprintf(cmdline, "sudo echo %d > /sys/class/leds/pandora::keypad_bl/brightness", brightness);
and
Code:
sprintf(cmdline, "echo %d > /sys/class/leds/pandora\\:\\:keypad_bl/brightness", brightness);
with the same results.What's wrong here? %-)
 
This is what I tried first.

Code:
sprintf(cmdline, "echo %d > /sys/class/leds/pandora\:\:keypad_bl/brightness", brightness);
However, this gives the same result as the other attempts, when using the Plugin, and when compiling, I get
Code:
kblight.c:29:20: warning: unknown escape sequence '\:'
kblight.c:29:20: warning: unknown escape sequence '\:'
kblight.c:38:20: warning: unknown escape sequence '\:'
kblight.c:38:20: warning: unknown escape sequence '\:'
 
update:

If I start configbutton with sudo, i.e.


sudo configbutton
my Plugin works!But if I don't start it with sudo and instead put sudo into the cmdline variable as shown above, it does not work.

Any hints? I'm stuck here. :-(

Thank you!
 
I don't think echo's in the sudoers file of commands you can run as root without needing to enter your password.

This is the issue, sudo will ask for a password. Either you need to add a script that you run, and also add it to sudoers file. Or, you use gksudo in your plugin, which will pop up a dialog asking for your password.
 
You could also modify the permissions (udev?).

Note that you can't use echo that way if you are working with sudo and its GUIs. The redirection is done by the shell, so it will not be written with sudo rights. Instead pipe the output from echo to tee with sudo, e.g. like this:


sprintf(cmdline, "echo %d | gksudo tee /sys/class/leds/pandora::keypad_bl/brightness", brightness);


If root rights wouldn't be needed you could still just directly write it into the file, no need to do shell-fu.
 
Last edited by a moderator:
HA!<br />It works.<br />Thank you so much!<br />&nbsp;<br />Not with gksudo, though, but with sudo. With gksudo I don't get any reaction from the code, no gksudo password entry field, no LED switching, no error message.<br />However, this works flawlessly, without the need to enter the password (which would be a bad thing here anyway):<pre class="_prettyXprint _lang-auto _linenums:0">

sprintf(cmdline, "echo %d | sudo tee /sys/class/leds/pandora::keypad_bl/brightness", brightness);

</pre>Question:<br />Why does sudo work here without the need to enter a password?<br />

(what the heck happened with the formatting of this post? I used the BBCode mode editor as almost always.)
 
Last edited by a moderator:
:-(

after reboot it doesn't work anymore.

and now I also know why I did not need to enter the password with sudo.

Rebooted, let the system start configbutton regularly, tried the Plugin... no reaction.

Opened a terminal, killall configbutton, then started configbutton manually from the terminal to see the output. Used the Plugin... now sudo asks for a password! If I give it, the LEDs are turned on.

So in my last post it worked, because the password / permissions were still cached.

Too bad.
 
You need sudo to open configbutton? or just sudo on some code you call from your plugin?

There's a config file in the system (I can never remember where, will look it up if it's what you're after) that let's you sudo without requiring a password

If it's your plugin, you could take that code into a seperate app, and just change the config button to "sudo myledapp", and add the "myledapp" into the list.

Hope that helps
 
Back
Top