Sunday, February 28, 2010

Shuffle array implementation

Once in interview i was asked for logic for shuffling array.So here is implementation in Qt.

int main( int argc, char* argv[] )
{
    QStringList strList;
    strList << "first" << "second" << "third" << "fourth" << "fifth" << "sixth";
    qDebug() << strList;

    qsrand( QTime(0,0,0).secsTo(QTime::currentTime()) );

    for( int i = strList.count() - 1 ; i > 0 ; --i )
    {
        int random = qrand() % strList.count();
        QString str = strList[i];
        strList[i] = strList[random];
        strList[random] = str;
    }

    qDebug() << strList;
}

Using Accelerometers API on Maemo

Maemo is very powerful platform for creating application and Qt as application development framework make development on maemo fun. Maemo provide various API to developer to create application so i thought to try out accelorometer API on maemo.

Accelerometer API can be used in two way. Reading file which store orientation data or Using Dbus API to get orientation data.

You can find more details here http://wiki.maemo.org/Accelerometers

For my purpose reading data from file was quite enough. My puropose to detect in which direction user has Shake the phone.

Here is code for using acceleromete API.

class MotionSenser : public QObject
{
Q_OBJECT

public:
    explicit MotionSenser(QObject *parent = 0); 
private slots:
    void timerEvent(QTimerEvent* event );

private:
    void readCurrentPos();

private:
    QPointF mLastPos;
    QPointF mCurrentPos;
    QObject* mParent;

};


static const QString PROC_ENTRY = "/sys/class/i2c-adapter/i2c-3/3-001d/coord";

MotionSenser::MotionSenser(QObject *parent)
: QObject(parent),mParent(parent)
{
    mLastPos = mCurrentPos = QPointF(0,0);
    this->startTimer(100);   
}
void MotionSenser::timerEvent(QTimerEvent* /*event*/)
{
    if( qAbs( mLastPos.y() - mCurrentPos.y() ) < 250 ) {
        //ignore event
        return;
    }

    if( mCurrentPos.y() > 150 ) {
        qDebug() << "####### Posting right event";
        QCoreApplication::postEvent(mParent,new QKeyEvent(QEvent::KeyPress,Qt::Key_Right,Qt::NoModifier));
    }
    else if ( mCurrentPos.y() < -150 ) {
        qDebug() << "####### Posting left event";
        QCoreApplication::postEvent(mParent,new QKeyEvent(QEvent::KeyPress,Qt::Key_Left,Qt::NoModifier));
    }
    mLastPos = mCurrentPos;
}

void MotionSenser::readCurrentPos()
{
    QFile f(PROC_ENTRY);
    if (!f.exists() or !f.open(QIODevice::ReadOnly | QIODevice::Text)) {
        qDebug() << "could not read motion data";
    }
    else {
        QByteArray line = f.readLine();
        QRegExp rx("([0-9-]+) ([0-9-]+) ([0-9-]+)");

        rx.indexIn(line);
        qreal x = rx.cap(1).toInt();
        qreal y = rx.cap(2).toInt();
        qreal z = rx.cap(3).toInt();

        mCurrentPos.setX(x);
        mCurrentPos.setY(y);

        f.close();
    }
}

Friday, February 26, 2010

Develope Maemo app from Windows

MADDE is new cross-compilation tool which allow creation of Maemo5 application from windows, mac and linux. Now the tech preview is extended to integrated with Qt Creator. It will work with It will work with a preview of QtCreator. Maemo website has put nice instruction to integrate Qt Creator with MADDE on windows system. please find instructino here.

Control panel in wine

Today I tried to install MS Office 2003 in my wine installation, i have read on web that Office 2007 is not that stable and usable on wine so i am trying 2003.

After completing installation, i tried to run Outlook and something goes wrong and my account setup got interrupted. Then when i restarted outlook it always close by saying that default profile corrupted.

Now to resolve this problem I thought to created another mail account from control panel. but i was not able to find windows control panel in wine. After searching Internet a while i found following command that launch control panel.

"wine rundll.exe shell32.dll,Control_RunDLL cplname.cpl" this command should be executed from windows directory from wine installation.

Still I am not able to setup mail account on outlook but I learned something from it.

Thursday, February 25, 2010

Debugging Qt application on maemo

When i started development on qt Maemo platform, it was quite difficult to debug Qt application because Qt creator is not supporting debugging inside scratch box and at that time i was unaware of using gdb and my only hope was to use qDebug() to print function name at start of each function.

But now I know how to use gdb to debug qt application inside scratchbox environment. To be able to debug application on scratchbox you need to install maemo debug script.

run "fakeroot apt-get install maemo-debug-scripts" inside scratchbox. This will install necessary tool required to debug maemo application.

Now on command prompt type "native-gdb", normal gdb command will not work, it will crash immediately. you need to use native-gdb command.

native-gdb command will bring gdb prompt. If gdb prompt comes then setup is ready to debug application.

Now you can use native-gdb to debug application. To start debugging run "native-gbd applicationName" command. applicaitonName is name of binary file that you want to debug.

To put break point you can use "break" gdb commnad.

"break filename:line number" will put break point in mentioned file at mentioned line number.

"break className::functionName()" will put break point at mentioned function.

To run application, type "run" command, now when instruction at breakpoint will execute gdb will stop at that break point and will ask you for command.

to run next line number in code type "next" command.

to run next instruction in code type "step" commnad.

to go to end of current function type "finish" command.

to continue execution until next breakpoint type "continue" command.

to know call stack type "where" command.

to list current function type "list" or "list numberOfLine" commanad.

to run previous command you can just press enter key and it will run previous command.

If you want to exit gdb type quit or q, to bring gdb prompt you can press ctrl + c.

Hope this will help you to start debugging with gdb on maemo platform.

Wednesday, February 24, 2010

Google Shooper application

Google announced android application called Google Shopper. This application lets you find product information quickly by using your phone's camera. It can recognize cover art of books, CDs, DVDs, and video games, along with most barcodes. You can also speak the name of the product you're looking for. It can tell price of item , places from where it can be purchased. It also saves your history so you'll always have product and price information even when you don't have a signal.

Here is demo video from google.



Tuesday, February 23, 2010

Just wated to share some potraits I have drawn

Above image is of  gisele bundchen, i have drawn it from some image that i  downloaded from internet.

This image i have drawn from new paper ad.

Monday, February 22, 2010

Adam Tablet from Notion Ink

I came to know about this new tablet developed by Notion Ink named as Adam, so think to share some information regarding this.

It is prices around $300 aprox 15000 INR and on the technical side, Adam has 6.3 x 9.8 inch display with 1024X600 SVGA, 32 GB flash drive, SD card support, Digital Compass, GPS and Wi-Fi. Connectivity includes USB, HDMI, 3.5mm headphone jack and a microphone input, and a 3 MP autofocus camera with video recording support.

It will run Andriod as Os and will support andriod's app store from which user will be able to download thounds of application.

Sunday, February 21, 2010

Run windows games on Ubuntu 64 bit

I have struggled a lot for installing and running windows game on my Ubuntu 64 bit machine. There are lots of article that explain how to install windows games on Ubuntu but most article refer to 32 bit installation of Ubuntu and for me those instruction does not work. So i am here sharing what i did to run windows games on my 64 bit machine with Ubuntu OS.

1) Install wine.
sudo apt-get install wine1.2

2) Get wine tricks from http://wiki.winehq.org/winetricks

3) Install following software using winetricks. (I am not sure if all software are required or not but i did it anyway)

type winetricks on command prompt and then select following component.

vcrun2005
d3dx9
d3dx10
directx9
dotnet20
msxml6
quicktime72

Now you system is ready to install windows games. Once you installed game and is ready to rum the game.

Open terminal and type following command.

export LIBGL_DRIVERS_PATH=/usr/lib32/dri


then cd to place where game is installed. it should be in ~/.wine/drive_c/Program Files


and then run game from command prompt using wine game_name.exe

I don't know what this command does and what does it mean. But this command works for me.

After this I am able to run Cashflow and Sherlock Homes vs Jack the Ripper game on ubuntu machine. I also installed Assassin's Creed successfully and able to launch it successfully and able to see starting videos, but my graphics card is poor and is not able to support this game so was not able to play it.