Welcome!

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

Reply
Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.
Accepted Solution

How to get screen orientation angle with 40 Hz stably without timing delay??

Purpose: Obtain screen orientation angle in 40 Hz stably without timing delay. 

 

Problem with two situations:

1.When using bbutil_swap and navigator_event_get_orientation_angle(event) to get screen orientation angle with other sensors data such as accelerations and gyroscope data, the sampling rate will down grade to 10Hz randomly. The timing difference will increase from 25 ms to 100 ms.

 

2.When screen orientation angle is collected in the following code to get the angle only, the sampling timing difference will have 1, 2, or 5 seconds delay randomly.

 

Question: How to get screen orientation angle with 40 Hz stably without timing delay??

                  or Something wrong in my code??

 

Mini code:

static void handleNavigatorEvent(bps_event_t *event) {
    switch (bps_event_get_code(event)) {
         case NAVIGATOR_ORIENTATION_CHECK:
         navigator_orientation_check_response(event, true);//if no the line, no rotation update on screen.
         angle = navigator_event_get_orientation_angle(event);
    break;
    case NAVIGATOR_EXIT:
         shutdown = true;
    break;
    }
}

 

static void handle_events() {
    for(;:smileywink: {
        bps_event_t *event = NULL;
    if (BPS_SUCCESS != bps_get_event(&event, 0)) {
          fprintf(stderr, "bps_get_event failed\n");
          break;
     }
    if (event) {
            if (bps_event_get_domain(event) == navigator_get_domain()) {
                        handleNavigatorEvent(event);
             } 
     } else {
             break;
     }
            pthread_create(&t1, NULL, (void*) &rawacceleration, NULL);
     }
}

int main(int argc, char *argv[]) {
         screen_create_context(&screen_cxt, 0);
         bps_initialize();

        if (EXIT_SUCCESS != bbutil_init_egl(screen_cxt)) {
             fprintf(stderr, "bbutil_init_egl failed\n");
             bbutil_terminate();
             screen_destroy_context(screen_cxt);
             return 0;
       }

      if (BPS_SUCCESS != screen_request_events(screen_cxt)) {
          fprintf(stderr, "screen_request_events failed\n");
          bbutil_terminate();
         screen_destroy_context(screen_cxt);
         return 0;
      }

     if (BPS_SUCCESS != navigator_request_events(0)) {
           fprintf(stderr, "navigator_request_events failed\n");
          bbutil_terminate();
          screen_destroy_context(screen_cxt);
          return 0;
       }

 

      rawlog = fopen(rawfilename, "w"); //save file into a specific file path.
      fprintf(rawlog, "System Time(ms), Angle\n");

 

      navigator_request_events(0);

      while (!shutdown) {
             handle_events();
             bbutil_swap();
      }

       

      closeshutdown();

 

      return 0;
}

 

Thank your attention,

 

-Fight with BB10
Retired
Posts: 15
Registered: ‎10-11-2012
My Device: BlackBerry Z10

Re: How to get screen orientation angle with 40 Hz stably without timing delay??

Are you trying to get the application orientation or the device orientation?

 

Application orientation should only be sent once every time a change happens. If you use the orientation_sensor you can a more responsive rate. Note that the orientation_sensor and navigator orientation might not be the same.  For example if your application is locked to a certain orientation or the user has orientation lock on.

 

I noticed that you are creating a new thread for every accelerometer event in your code:
pthread_create(&t1, NULL, (void*) &rawacceleration, NULL);

 

At a fast accelerometer sampling rate this would be a heavy load on the system.

Super Contributor
Posts: 253
Registered: ‎08-19-2010
My Device: BB10, Playbook, 9900, 9800, 9700, 9550, 9530, 9500, 8700.

Re: How to get screen orientation angle with 40 Hz stably without timing delay??

I am trying to get both screen orientation (from navigator) and device orientation (from sensor_type).

 

Application orientation should only be sent once every time a change happens. 

--> using bbutil_swap to detect change happens --> can get the data in 10 Hz.

 

Just ask a possiblity to get 40 Hz Application orientation data.

 

Is it possilbt to get the applicaiton orientation data in 40 Hz?

 

Thanks aparco.

 

-Fight with BB10
Retired
Posts: 15
Registered: ‎10-11-2012
My Device: BlackBerry Z10

Re: How to get screen orientation angle with 40 Hz stably without timing delay??

Using SENSOR_TYPE_ORIENTATION from sensor_type_t you should be able to get > 10Hz.  Use sensor_set_rate() to get the slowest delay found from calling sensor_info().  Make sure to not enable sensor_set_skip_duplicates().

 

However getting the orientation at streaming 40Hz will not make your application any more repsonsive.  The only way to make your application more reponsive would be to handle the orientation change in a shorter amount of time.  That is the time from when the orientation changes (at hardware level), to you recieving and handling it.  This is usually a system constraint and there is not much you can do about it.  What you are going to see using the code above is the same information repeated over and over; FACE_UP, FACE_UP, FACE_UP, which isn't really useful.