Monday, March 3, 2008

You got a call.. with Python OSD and Sony Ericsson K300i

Consider the situation where you have put your mobile in silent mode and working on your PC. Most of the times,
you will not be able to attend the calls simply because you won’t care the buzzing of the mobile phone… 

This Python program will Show an On Screen Display telling ” You have a call” to divert our attention to the mobile phone. Only thing is that you should connect your Mobile with your PC using the USB cable 
provided with your mobile ..  or if you are a bit adventurous, try to connect your phone using bluetooth using the
bluetooth dongle.. ( /dev/rfcomm0 instead of /dev/ttyUSB0)..

For Bluetooth ….

###################
hcitool scan
Scanning …
11:22:33:44:55:66

Then modify the /etc/bluetooth/rfcomm.conf file
#
# RFCOMM configuration file.
#

rfcomm0 {
# Automatically bind the device at startup
bind no;

# Bluetooth address of the device
device 11:22:33:44:55:66;

# RFCOMM channel for the connection
channel 1;

# Description of the connection
comment “Example Bluetooth device”;
}

Then give this command

rfcomm bind /dev/rfcomm0 

after running the below given python program, release the device

rfcomm release /dev/rfcomm0
###################

Then try this python program

######################################################
# mobilecall.py #
# Python program which displays the information when #
# somebody calls your mobile (here my K300i) which is #
# plugged to my pc using the usb cable. #
# ################################################### #
# Technical Details: #
# The usb device is shown as ttyUSB0 in the Linux PC #
# The serial module can be used to read and write from#
# that device. PyOSD is used to diplay the information#
# on the screen. #
# If you want, you can use the pygame module to play #
# music in your PC to inform you about the call .. #
# or dbus module to mute other music players #
# #
# Technically , this is the meanest way(or simplest) #
# to achieve this using python #
######################################################

import serial
import time
import pyosd
#import pygame

def mobilecall():
try:
# /dev/rfcomm0 in the case you are using bluetooth connectivity :)
s= serial.Serial(’/dev/ttyUSB0′,9600)
# This will wait till some string is pushed from phone.
# Highest probable event is ‘RING’ indication from phone
# when somebody calls you.
data = s.readline()

# PyOSD initialization and other settings..
displayer = pyosd.osd()
displayer.set_colour(’red’)
displayer.set_pos(0)
displayer.set_timeout(10)
displayer.display(’You have a call . Please pick up your mobile’)

# Uncomment this if you want to play music on receiving a call
#pygame.mixer.init()
#indi_music = pygame.mixer.Sound(’/usr/share/sounds/KDE_Startup.wav’)
#pygame.mixer.Sound.play(indi_music)

 time.sleep(10)
except:
   print ‘Failed to open Port’

# Pythonic way to invoke the function
if __name__== ‘__main__’:
   mobilecall()

###############################################################

And here goes the output:

Posted by maxinbjohn at 10:57:59 | Permalink | Comments (1) »

Wednesday, February 6, 2008

Aiming Small — An embedded Java program for my K300i mobile

When I spent money to correct the long privailing display problem of my Sony Ericsson K300i mobile phone, only aim in my mind was to use it as a programmer’s toy :)… write my own programs (Here they restricted me to Java alone) for my small device that I own.

I still remember that rainy day in Mumbai. Then I was working with HCL infosystems, Andheri East office, Mumbai. It was raining slowly when we left the office. From Chandivili to RahejaVihar (Where I work and live respectively) there was about 1.5 km distance. So we decided to walk. I was keeping my newly owned K300i on my pant’s pocket to keep it from water. Almost on the middle of the journey, the rain became heavy. So we decided to find refuge in the nearby bar ( Titanic bar near Chandivili studio which “sank” in fire almost six months later, anyway me and Sreekumar frequently visited there on Saturdays and Sundays). Standing under the safety of the roofs of Titanic, I felt like I should sneeze.. As I was(?) a gentleman , I decided to cover my face during sneezing to help others :) …… As the urge to sneeze was high, I went for the handkerchief which was in my pants pocket . I got a touch of it and I went for it very fast…. too fast….

Then I saw something raising in the air… That was my mobile phone which I kept in my pants pocket along with handkerchief. On the hurry , I took the handkerchief in a hurry but forget to keep the mobile in the pocket itself. It flew in the air and landed on the road. I felt a shiver in my body.. my devil…. what did I do with my Rs. 5500 /- :(
After that , the same mobile served me loyally for about an year without display .. My friends used to advise me to change the mobile. But I thought as it is doing the basic functions even without the display, why bother to change it ?

But later I have changed my decision and repaired it by spending near to a cool thousand rupees. My only aim was to use the JVM in that phone .. Yes , the K300i has a JVM installation in it. I have installed the necessary packages, J2SE implemenation for Linux. the sun_java_wireless_toolkit-2_5_2-linux.bin , the J2ME implementation … etc and used the Sun’s sample program available at http://developers.sun.com/mobility/midp/articles/wtoolkit/src/HelloMIDlet.java.

Now the screenshot of that emulator running that program in Fedora core 6 is available with me :) I need to check the newly developed jad and jar on my mobile phone today itself :)

Posted by maxinbjohn at 06:22:09 | Permalink | No Comments »