Showing posts with label Accelerometer. Show all posts
Showing posts with label Accelerometer. Show all posts

Saturday, December 18, 2010

[Qt] Push-ups Counter: Step2-Look&Feel

So ... It looks like I lack that talent of Look&Feel stuff. I've been trying to make something fancy but I just couldn't.

Anyways, this is the last version of the application. It has only one screen. It contains the option of "Silent Mode" which disables the beep during exercise (the beep of reaching the up/down level). And when stopping the counter, it shows a message with the time elapsed since starting.


Here is the code in case you want to take a look: (Download)



Creative Commons License
Blog Example by Mahmoud Adly Ezzat is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Saturday, December 11, 2010

[Qt] Push-ups Counter: Step1-Functionality

I made the first version of my Push-ups counter using Qt. It is based on using the accelerometer to sense the movement of the mobile. In this version:
- It has a settings screen with only one option till now: Mute Sound.
- The next screen counts the push-ups depending on some internally-set variables (the positions of up/down)
- It makes a beep when I reach the up/down position, so I know if I'm up/down enough.
= I noticed that if my arm shakes, it may count extra points.(to be fixed)




The main important points in the application are how to read the device's position and how to count.
To read the position, I read the "x" value of the accelerometer:
I use two classes: QSensor, QSensorReading

QSensor *sensor = new QSensor("QAccelerometer");
sensor->start();
QSensorReading *reading = sensor->reading();
int value = abs(reading->property("x").value<qreal>()/1);

Some notes:
- The abs() method is because the value can be +ve or -ve depending on which arm I use, so I just take the absolute value.
- The value<qreal>()/1 is a simple way of moving any noise. If I get the value as int, it will be in a big range (I can't remember it right now), and it may be useful in sensitive applications but not in this case. The range I get is 0-9. And the division by 1 is to neglect the fractions.


I added two flags to detect if the next calculation to for going up or down. An a timer to calculate the value of the accelerometer every period of time. I know that the QSensor class has a signal of readingChanged(), but it is very rapid and will exhaust the processor.

void CounterWindow::readSensorValue()
{
    int value = abs(reading->property("x").value<qreal>()/1);

    if(nextUp)
    {
        if(value <= upValue)
        {
            if(!muted) QApplication::beep();
            nextUp = false;
            nextDown = true;
            score++;
            counterLabel->setText(QString::number(score));
        }
    }
    else if(nextDown)
    {
        if(value >= downValue)
        {
            if(!muted) QApplication::beep();
            nextUp = true;
            nextDown = false;
        }
    }
}


I also had to add some Symbian code to disable the change of orientation when the mobile rotates and force the Portrait orientation.

[PushupsCounter.pro]
symbian {
    LIBS += -lcone -leikcore -lavkon
}

[main.cpp]
// Needed Symbian specific headers
#ifdef Q_OS_SYMBIAN
#include <eikenv.h>
#include <eikappui.h>
#include <aknenv.h>
#include <aknappui.h>
#endif

and add this code before calling the window
[main.cpp]
StartingWindow w;
#if defined(Q_OS_SYMBIAN)
    CAknAppUi* appUi = dynamic_cast<CAknAppUi*>(CEikonEnv::Static()->AppUi());
        if(appUi){
            QT_TRAP_THROWING(appUi ->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait));
        }
#endif
    w.showMaximized();


So... the next step is for the Look&Feel and fixing any bug that may appear.

Download v1.0



Creative Commons License
Blog Example by Mahmoud Adly Ezzat is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.

Thursday, September 9, 2010

Pushups Counter using Adobe Flash Lite (Part 1)

[stopped for a while()]

A friend of mine was talking about an iPhone app for counting pushups and how it was a success. At the same time I was introduced to the new world (it was new for me) of Adobe Flash Lite. So I thought about testing this Adobe thing and putting this app as a goal to apply what I learn.

I started to think about ways to sense the pushups:
  • Altitude: too complex for a small app.
  • Accelerometer: counting the pushups depending on changing the orientation of the device. Whether to put it on your back (stupid) or on the arm.
And I found some ideas on the web:
  • Touching the screen with your nose (believe me, it's a real app).
  • Using the iPhone proximity sensor to detect your chest.

Here are some videos:






So, my desired app will be using the accelerometer. What about my sources to learn Adobe Flash Lite?
.... Plus any video or website that can help.

I found a video on Vimeo that demonstrates accessing the accelerometer. I guess it can help.



Platform Services and the Accelerometer from Adobe Flash Lite on Vimeo.

So, here I go.