november 11, 2015

How to change the button of your rabbit

I wanted to make use of the button of my Karotz, and wondered how to change its actions.
In this post, i'll try to explain how you can assign multiple actions to the button on your rabbits head.

When you press the button on your rabbit, an event is triggered and handled by the bash script /www/cgi-bin/dbus_events. The process responsible for handling these events is dbus-monitor. It will output information about the way the button is pressed.

Lets take a look at the bash script /www/cgi-bin/dbus_events. In this script, you'll find multiple sections for several button actions. You'll also see actions for RFID. Lets create a new simple script just to handle the buttons; you'll see this new simple script below.

The first three lines will include some handy functions to play sounds and change the color of the LED. also has a function to kill running processes like the sound player.

At the moment, we are only interested in the button events, so there are four sections for handling buttons. In the first section, a long press is detected. The second one is for a single click, third one for double click and the last one for tripple click. Each section will play a different sound.

Lets test this script. Rename the original file /www/cgi-bin/dbus_events to /www/cgi-bin/dbus_events.ori. After this, place the new file in the same folder.

Just to be sure, start a telnet session, and enter the commands "chmod 755 /www/cgi-bin/dbus_events" to make the file an executable script, and "dos2unix /www/cgi-bin/dbus_events" to correct linefeeds from Windows to Unix.

After this, reboot your rabbit.

Test the script by holding the button for a while (long press), and then pressing it once, twice and three times. You'll hear different sounds played from the sounds folder of your rabbit.

You can even call another script file this way. For example call /www/cgi-bin/sleep instead of (or after) playing a sound to let your rabbit go to sleep after pressing its button.

After you are finished playing with the button script, delete it and copy the original script back to /www/cgi-bin/dbus_events.

What are your plans with your rabbits button? Let us know!

Leave a message