zaterdag 20 november 2010

Wiimote for controlling Rhythmbox

Last weekend I decided to write a small C program for controlling Rhythmbox with my Wiimote, using libcwiid en D-Bus. I implemented play, pause, previous, next and adjusting the volume. The Wiimote also rumbles when you press a working button and the LED's on the Wiimote show the current volume of Rhythmbox.

The only dependency is libcwiid, so build with the -lcwiid option. Here's the source code:


#include <cwiid.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

/*
* This function reads Rhythmbox's volume and sets the LEDs of the Wiimote
*/
static void update_volume_leds(cwiid_wiimote_t *wiimote);

/*
* Callback function for Wiimote messages
*/
static cwiid_mesg_callback_t callback;

int main(int argc, char **argv)
{
cwiid_wiimote_t *wiimote;

printf("Put Wiimote in discoverable mode now (press 1+2)...\n");

if (!(wiimote = cwiid_open(BDADDR_ANY, 0)))
fprintf(stderr, "Unable to connect to wiimote\n");
if (cwiid_enable(wiimote, CWIID_FLAG_MESG_IFC))
fprintf(stderr, "Error enabling messages\n");
if (cwiid_set_rpt_mode(wiimote, CWIID_RPT_BTN))
fprintf(stderr, "Error setting report mode\n");
if (cwiid_set_mesg_callback(wiimote, callback))
fprintf(stderr, "Unable to set message callback\n");

printf("Connected to Wiimote...\n");

update_volume_leds(wiimote);

while (1) {}
}

static void update_volume_leds(cwiid_wiimote_t *wiimote)
{
FILE *fp;
char volume[128];
unsigned char ledstate = 0;

// Read Rhythmbox' volume
fp = popen("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.getVolume", "r");
while (fgets(volume, 128, fp) != NULL);
pclose(fp);

if (atof(volume) > 0)
ledstate |= CWIID_LED1_ON;
if (atof(volume) > 0.33)
ledstate |= CWIID_LED2_ON;
if (atof(volume) > 0.66)
ledstate |= CWIID_LED3_ON;
if (atof(volume) >= 1)
ledstate |= CWIID_LED4_ON;

cwiid_set_led(wiimote, ledstate);
}

static void callback(cwiid_wiimote_t *wiimote, int mesg_count, union cwiid_mesg mesg[], struct timespec *t)
{
int i;

for (i = 0; i < mesg_count; i++) {
switch (mesg[i].type) {
case CWIID_MESG_BTN:
switch(mesg[i].btn_mesg.buttons) {
case 0: // Ignore button releases
break;
case CWIID_BTN_A:
printf("\"A\" button pressed; calling playPause()\n");
// Give a rumble on each working button!
cwiid_set_rumble(wiimote, 1);
system("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.playPause 0");
break;
case CWIID_BTN_LEFT:
printf("\"Left\" button pressed; calling previous()\n");
cwiid_set_rumble(wiimote, 1);
system("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.previous");
break;
case CWIID_BTN_RIGHT:
printf("\"Right\" button pressed; calling next()\n");
cwiid_set_rumble(wiimote, 1);
system("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.next");
break;
case CWIID_BTN_MINUS:
printf("\"Minus\" button pressed; calling setVolumeRelative(-.1)\n");
cwiid_set_rumble(wiimote, 1);
system("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.setVolumeRelative -.1");
update_volume_leds(wiimote);
break;
case CWIID_BTN_PLUS:
printf("\"Plus\" button pressed; calling setVolumeRelative(.1)\n");
cwiid_set_rumble(wiimote, 1);
system("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player org.gnome.Rhythmbox.Player.setVolumeRelative .1");
update_volume_leds(wiimote);
break;
default:
printf("Button \"%d\" not implemented...\n", mesg[i].btn_mesg.buttons);
break;
}
usleep(10000);
cwiid_set_rumble(wiimote, 0);

break;
default:
printf("Uncaught report...\n");
break;
}
}
}

zondag 15 augustus 2010

Last.fm scrobbling at YouTube

Like most people who like to listen to music, I watch a lot of music videos on YouTube. Also, I'm a big fan of last.fm. For years I was thinking by myself "it would be perfect if I could scrobble the tracks I listen to on YouTube", but I never even tried to look for a way to fix that because I thought it wouldn't be there.

But today I did, and it really made my day because there is a great Greasemonkey script which does exactly what I wanted. It's called youscrobble and it looks like this:You get a nice "Scrobble" button which pops up a form to submit the song. You can even fix the artist and track name if necessary.

woensdag 27 januari 2010

zondag 22 november 2009

A small review of the Massa CPL polarizer filter

Lately I bought the Massa CPL polarizer filter (58mm) at DealExtreme, for only $7.89. I'm planning to use it mainly for landscapes, so today I tested it on some skies. First, here's a picture of a sky with the polarizer filter deactivated.

(Almost) the same picture with my polarizer filter activated looks like this:

Pretty cool huh? I think the contrasts between the sky and the clouds make the picture a lot nicer. Just to see the differences in one picture very clearly, I made another picture with the filter halfway in front of the lens.
I don't have any other polarizer filters to make a comparison, but I think this filter does what it should do.

zondag 25 oktober 2009

Comparing the Canon 55-250mm F/4-5.6 IS and the Tamron 55-200mm F/4-5.6 lens

Yesterday I bought the Canon 55-250mm F/4-5.6 IS lens, replacing my Tamron 55-200mm F/4-5.6 lens. Now I'm really interested in the differences in image quality, so I decided to put the two lenses to the test. I shot the same objects with different settings, modifying the focal length and the aperture. The test results are on a different page, so I was able to use a full screen layout.

My conclusion is that the Canon lens has a much nicer bokeh and more intense colors. However, I don't see very much difference in sharpness. I think the Canon lens is worth the extra money, because it produces better pictures and moreover has a 4-stop image stabilizer.