Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 19
Registered: ‎06-21-2012
My Device: z10
My Carrier: Bell

Issue with gyro sensor reading vs range

Hi, I am wirting an simple app that can take gyro reading and put reading into a data file.

It works, but i fell like the data i collected may be wrong. The thing is that I foud out my range should from-2000 to 2000, but my gyro readings are between -2 to 2. I dont really understand why. Did i do wrong or it is supposed to be.Below is part of my code. Thanks.


SensorBpsEventHandler:Smiley FrustratedensorBpsEventHandler()
    m_isMeasurement = false;

    x = 0.0;
    y = 0.0;
    z = 0.0;

    cout << "----------------------------------" << endl;
        int res = BPS_FAILURE;
        cout << "SensorBpsEventHandler: SENSOR_TYPE_gyro is supported!" << endl;
        //sensor_set_skip_duplicates(SENSOR_TYPE_LIGHT, true);

//        unsigned int new_rate = 140000;
//        res = sensor_set_rate(SENSOR_TYPE_LIGHT, new_rate);
//        if(BPS_SUCCESS == res)
//        {
//            cout << "SensorBpsEventHandler: SENSOR_TYPE_LIGHT: successfully set delay to " << new_rate << " microseconds" << endl;
//        }
//        else
//        {
//            cout << "SensorBpsEventHandler: SENSOR_TYPE_LIGHT: cannot set delay to " << new_rate << " microseconds" << endl;
//        }

        sensor_info_t* p_sinfo = NULL;
        res = sensor_info(SENSOR_TYPE_GYROSCOPE, &p_sinfo);
        if(BPS_SUCCESS == res && NULL != p_sinfo)
            float resolution = sensor_info_get_resolution(p_sinfo);
            float rmin = sensor_info_get_range_minimum(p_sinfo);
            float rmax = sensor_info_get_range_maximum(p_sinfo);
            unsigned int dmin =  sensor_info_get_delay_minimum(p_sinfo);
            unsigned int dmax = sensor_info_get_delay_maximum(p_sinfo);
            unsigned int ddef = sensor_info_get_delay_default(p_sinfo);
            float power = sensor_info_get_power(p_sinfo);

            cout << "resolution = " << resolution << endl;
            cout << "range_minimum = " << rmin << endl;
            cout << "range_maximum = " << rmax << endl;
            cout << "delay_minimum = " << dmin << " microseconds" << endl;
            cout << "delay_maximum = " << dmax << " microseconds" << endl;
            cout << "delay_default = " << ddef << " microseconds" << endl;
            cout << "The power consumed by the sensor = " << power << endl;

            m_max = m_current= rmax;

            cout << "SensorBpsEventHandler: cannot extract sensor_info for SENSOR_TYPE_ACC! return value = " << res << endl;
        cout << "SensorBpsEventHandler: SENSOR_TYPE_ACC isn't supported!" << endl;

    cout << "----------------------------------" << endl;


void SensorBpsEventHandler::event( bps_event_t *event ) {
//    cout << "SensorBpsEventHandler::event" << endl;
    FILE *fp;    //the blank position of file pointer
    size_t size;
    fp=fopen("shared/documents/gyro.csv", "a");//open or create a csv file
    if (fp == NULL)    //check if has file open error
       printf("I couldn't open for writing.\n");
    if (bps_event_get_domain(event) == sensor_get_domain())//reading sensor
           uint16_t code = bps_event_get_code(event);
          if (code == SENSOR_GYROSCOPE_READING)
             // Keyboard is now visible. Handle event...
//             cout << "SENSOR_LIGHT_READING event..." << endl;

             uint64_t flags = sensor_event_get_flags(event);
             sensor_accuracy_t acc = sensor_event_get_accuracy(event);
             uint64_t ts = sensor_event_get_timestamp(event);

             if(m_isMeasurement)//there is always a measurement
                 //cout << ts/1000000 << "ms"<<setw(15);
                 //printf("%lu ms", ts/1000000);
                 fprintf(fp,"%.9f,%.9f ,%.9f ", x,y,z);//x y z reading in the same row

                 fprintf(fp,"\n");    // next line


                 m_isMeasurement = true;

              cout << "Received event # " << code << endl;

        cout << "Received unknown domain event" << endl;


Posts: 36
Registered: ‎01-16-2013
My Device: Z10
My Carrier: Telus

Re: Issue with gyro sensor reading vs range

Ya, just by shaking the phone in my hand I get around 2.  Maybe if you bolt the phone to your car tire and accellerate hard on the highway you'll get higher values...   my guess that max of 2000 is what the sensor will not give over, no matter what happens.   It's a float value, so you can scale it to whatever you want.


As a side note, I work with sensors on my app and I found it's very useful to go on blackberry World and download a bunch of "sensor" apps that display the sensors in nice line graphs so I get a feel for how they work.