FritzNet

FritzNet is a blog of my path to freedom from Micro$oft. I'm embarking on trip into the Open Source movement. In this blog, I will be documenting my plans, successes and failures.

Monday, June 19, 2006

Function keys are now working

In a previous post, I mentioned that didn't have any function keys working. Well, since I got out of this semester, I fixed this problem. Long ago, I found instructions for making the function keys work on the Gentoo forums. I had to read through them and took out the parts that I didn't need. After paring down all that discussion, I ended up with a much quicker and easier procedure that works.

First, I put the following code into a file called sonyfn.c This code was submitted to the Gentoo forums by Pijalu. If this code is helpful to you, please let him know.


#include
#include
#include
#include
#include
#include

// input thing
#include

// sound stuff
#include

// keys
#define FN_F2 1 // cut sound
#define FN_F3 2 // volume -
#define FN_F4 4 // volume +
#define FN_F5 8 // Brightness -
#define FN_F6 16 // Brightness +
#define FN_F7 32 // LCD/SCREEN
#define FN_F10 128 // Zoom in
#define FN_F12 64 // Suspend
#define S1_BTN 4096 // S1 custom button
#define S2_BTN 8192 // S2 custom button

#define FN_INPUT_VALUE 245 // Fn key generate a 245 value
#define FN_INPUT_TYPE 4 // a 4 type
#define FN_INPUT_CODE 4 // and a 4 code

// config hard coded :p
#define MIXER_DEV "/dev/mixer"

// SOUND HANDLER
int get_volume(int *value)
{
int mixer = open(MIXER_DEV, O_RDONLY);

if (mixer) {
ioctl(mixer, SOUND_MIXER_READ_VOLUME, value);
close(mixer);
return 0;
}
else
return 1;
}

int set_volume(int *value)
{
int mixer = open(MIXER_DEV, O_RDWR);

if (mixer) {
ioctl(mixer, SOUND_MIXER_WRITE_VOLUME, value);
close(mixer);
return 0;
}
else
return 1;
}

int volume_up()
{
int value = 0;

get_volume(&value);

if (value < 0x5a5a)
value += 0x0a0a;
else
value = 0x6464;

set_volume(&value);

return 0;
}

int volume_down()
{
int value = 0;

get_volume(&value);

if (value > 0x0a0a)
value -= 0x0a0a;
else
value = 0;

set_volume(&value);

return 0;
}

int oldvalue;
int mute()
{
int value;

get_volume(&value);

if (value) {
oldvalue=value;
value=0;
set_volume(&value);
}
else {
if (!oldvalue) {
volume_up();
}
else {
set_volume(&oldvalue);
}
}

return 0;
}
// END OF SOUND

/* Return current brightness of the screen */
int getBrightness() {
FILE* handle;
char buffer[2];
int ret;

if ((handle=fopen("/proc/acpi/sony/brightness","rb"))==NULL) {
perror("Error opening /proc/acpi/sony/brightness");
exit(-1);
}
if (fscanf(handle,"%d",&ret)!=1) {
perror("Error reading /proc/acpi/sony/brightness");
exit(-1);
}
fclose(handle);
return ret;

}

/* Set the current brightness of the screen */
void setBrightness(int b) {
FILE* handle;
char buffer[2];

// validate values
if (b>8) {
b=8;
}
else if (b<1) {
b=1;
}

if ((handle=fopen("/proc/acpi/sony/brightness","wb"))==NULL) {
perror("Error opening /proc/acpi/sony/brightness");
exit(-1);
}
if (fprintf(handle,"%d",b)!=1) {
perror("Error writing /proc/acpi/sony/brightness");
exit(-1);
}
fclose(handle);
}

// Pool the fnkey status
int getCodes() {
FILE* handle;
char buffer[10];
int ret;
if ((handle=fopen("/proc/acpi/sony/fnkey","rb"))==NULL) {
perror("Error opening /proc/acpi/sony/fnkey");
exit(-1);
}
if (fscanf(handle,"%d",&ret)!=1) {
perror("Error reading /proc/acpi/sony/fnkey");
exit(-1);
}
fclose(handle);
return ret;
}

// main and loop
int main(int argc, char **argv) {
// event interface
int fd = -1; /* the file descriptor for the device */
int i; /* loop counter */
size_t read_bytes; /* how many bytes were read */
struct input_event ev[64]; /* the events (up to 64 at once) */

/* key code */
int key;

/* used if event hit fn */
int hasSomething;

/* open event interface*/
if (argc != 2) {
/* i don't like outputs...
fprintf(stderr, "Using /dev/input/event0 for input\n");
fprintf(stderr, "Overide with %s event-device\n", argv[0]);
*/
if ((fd = open("/dev/input/event0", O_RDONLY)) < 0) {
perror("event interface open failed");
exit(1);
}
}
else {
if ((fd = open(argv[1], O_RDONLY)) < 0) {
perror("event interface open failed");
exit(1);
}
}

nice(10); // be a nice dirty code (less dirty but keep nice)


while(1) { /* loop */
hasSomething=0; /* nothing yet */

/* read the event interface */
read_bytes = read(fd, ev, sizeof(struct input_event) * 64);

if (read_bytes < (int) sizeof(struct input_event)) {
perror("sonyfn: short read");
exit (1);
}

/* Loop for all readed events until we have something interesting.. */
for (i = 0;! hasSomething && ( i < (int) (read_bytes / sizeof(struct input_event)) ); i++) {
hasSomething= (ev[i].type == FN_INPUT_TYPE)
&& (ev[i].code == FN_INPUT_CODE)
&& (ev[i].value == FN_INPUT_VALUE);
}

/* If we got a FN event, plz do something...*/
if ( hasSomething && (key=getCodes()) ) {
if ((key & FN_F5)==FN_F5) { // lower brightness
setBrightness(getBrightness()-1);
}
if ((key & FN_F6)==FN_F6) { // higher brightness
setBrightness(getBrightness()+1);
}
if ((key & FN_F2)==FN_F2){
mute();
}
if ((key & FN_F3)==FN_F3) {
volume_down();
}
if ((key & FN_F4)==FN_F4) {
volume_up();
}
if ((key & FN_F12)==FN_F12) {
if (fork()==0) {
/* that's my home made script for swsusp
#!/bin/sh
sync
echo "disk" > /sys/power/state
*/
if (execv("/bin/hibernate",NULL)==-1) {
perror("Cannot run hibernate");
}
}
}
/* rest i still don't care */
}
}// while

close(fd);
return 0;
}


Then I had to compile this by doing a:


$ gcc sonyfn.c -o sonyfn
$ mv sonyfn /usr/bin
$ sudo chown root /usr/bin/sonyfn
$ sudo chmod 4755 /usr/bin/sonyfn


Then to manually run this, you call the program and provide the path to the keyboard. In my case, the keyboard is /dev/input/event0.

So now I need it to launch at boot time, so I'm using the Session GUI to add it to the start up programs.

sonyfn /dev/input/event0 &


I rebooted and it launches just fine.

Wednesday, June 14, 2006

Upgrading to Dapper Drake

On June 1st, the latest version of Ubuntu came out. It was 6.06, Dapper Drake. I read that there have been a couple improvements implemented. I don't know the details, but I do know that they improved hibernate. I was waiting for my classes to be over, and today I took my last final.

So it's time to upgrade. I did a quick search, and came up with this blog. Since it appears that it would be a piece of cake, so I decided to go for it. I launched the Upgrade Manager and saw that it knew about the upgrade. I clicked to install the upgrade and accepted all defaults, although the only real choices you had were to continue and after the install you could choose to remove the non-supported applications. It took just over an hour to download and install the upgrade.

Now for the testing. I found that hibernate works just fine. I put it to sleep and woke it up just fine. I'll put it to sleep tonight and see if it wakes up tomorrow. I also know that it now supports WPA. I'm going to read up on that and see how to configure it. Since everything else in Ubuntu is a piece of cake, I doubt this will be any more difficult. Is it obvious that I really like this distro?

One thing that is different is my touch pad now has a scroll portion. I don't particularly like it yet. I'll have to use it a little and see if I like it better. Time will tell.

Saturday, June 03, 2006

Crossover Office

I had to use Office 2003 for some of my school work. I took an Access course, so had to use Office 2003. I have been using OpenOffice.org for all my papers and any writing I need to do. I registered and paid for my next courses and started working on my reimbursement paperwork. What do I find? The forms I have to fill in won't work in OpenOffice.

So I started looking around and downloaded Crossover Office. I got the 30 day free trial. Since I'm using Ubuntu, I did have to set up my system to allow logging in as root. After downloading, I found it's just a script that gets run. I had to run it several times. I ran it first as sudo and the script told me that I couldn't run it as sudo. I then used "su -" and the script told me that I was not able to use this because root does not have display settings configured. I then ran it with "su" and it worked just fine. Installed without any errors.

Next thing that needed done is installing whatever you need to run. I picked Office 2003 from the list and told it where to install from. Again, I had to do this 2 times. The first time, the program informed me that because it's a Windows CD, there are hidden files that the CD-ROM could not see. It then offered to fix this problem itself. I usually wouldn't allow a program to "fix" my system, but it spelled out exactly what was going to happen. All it needed to do was edit my fstab file. It modified the file and I was able to install Office 2003 without a hitch. I'm curious if Office will expire or not.

Will I buy Crossover Office? Maybe, it all depends on how often I use it.