How to display data on the screen and save the data in a file at the same time?

The code can display acceleration on the screen of the playbook.

But, when fprintf (f, "X (m/s2), Accel Accel Y (m/s2), Accel Z (m/s2) \n" ") runs, debug displays no source available.

??

Does anyone know how to solve the problem, which writes data to a file?

The code is below.

/*
* Copyright (c) 2011 Research In Motion Limited.
*
Licensed under the Apache License, Version 2.0 (the "license");
* You may not use this file except in compliance with the license.
* You can get a copy of the license at
*
www.Apache.org/licenses/license-2.0
*
* Unless required by the applicable law or agreement written, software
* distributed under the license is distributed on an "AS IS" BASIS.
* WITHOUT WARRANTIES OR CONDITIONS of ANY KIND, express or implied.
* See the license for the specific language governing permissions and
* limitations under the license.
*/

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

/**
The milliseconds between the accelerometer readings. It's the same thing
* rate in which the accelerometer data will be updated
* material. The update of material rate is below to help
* accelerometer_set_update_frequency (FREQ_40_HZ).
*/
public static const int ACCELEROMETER_MAX_POLL_INTERVAL = 25;

public static screen_context_t screen_ctx;
public static screen_window_t screen_win;
dialog_instance_t main_dialog = 0;

paused int = 0;

The forces of the accelerometer
float force_x, force_y, force_z;

file elements
int _logcounter = 0;
FullName Char [256];
FILE * f;

/**
* Use the PID to set the id of Group window.
*/
public static char
get_window_group_id()
{
public static char s_window_group_id [16] = "";
If (s_window_group_id [0] == '\0') {}
snprintf (s_window_group_id, sizeof (s_window_group_id), "%d", getpid());
}
Return s_window_group_id;
}

/**
* Set up a basic screen, so that the browser will be
* Send window state events when the State of the window changes.
*
* @return @c EXIT_SUCCESS or EXIT_FAILURE @c
*/
public static int
setup_screen()
{
If (screen_create_context (& screen_ctx, SCREEN_APPLICATION_CONTEXT)! = 0) {}
Return EXIT_FAILURE;
}
If (screen_create_window (& screen_win, screen_ctx)! = 0) {}
screen_destroy_context (screen_ctx);
Return EXIT_FAILURE;
}
use of int = SCREEN_USAGE_NATIVE;
If (screen_set_window_property_iv (screen_win, SCREEN_PROPERTY_USAGE, & use)! = 0) goto fail;
If (screen_create_window_buffers (screen_win, 1)! = 0) goto fail;
If (screen_create_window_group (screen_win, get_window_group_id())! = 0) goto fail;
buff screen_buffer_t;
If (screen_get_window_property_pv (screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void *) & buff)! = 0) goto fail;
buffer_size int [2];
If (screen_get_buffer_property_iv (buff, SCREEN_PROPERTY_BUFFER_SIZE, buffer_size)! = 0) goto fail;
int attributes [1] = {SCREEN_BLIT_END};
If (screen_fill (screen_ctx, chamois, attributes)! = 0) goto fail;
int dirty_rects [4] = {0, 0, buffer_size [0], buffer_size [1]};
If (screen_post_window (screen_win, buff, 1, (const int *) dirty_rects, 0)! = 0) goto fail;
Return EXIT_SUCCESS;
in case of failure:
screen_destroy_window (screen_win);
screen_destroy_context (screen_ctx);
Return EXIT_FAILURE;
}

/**
* Rotates the screen at the specified angle.
*
@param angle angle to rotate the screen.  Must be 0, 90, 180 or 270.
*
* @return @c EXIT_SUCCESS on success, to another @c EXIT_FAILURE
*/
public static int
rotate_screen (int angle)
{
If ((angle! = 0) & (angle! = 90) & (angle! = 180) & (angle! = 270)) {}
fprintf (stderr, "Invalid Angle\n");
Return EXIT_FAILURE;
}
int rc;
int rotation;
RC = screen_get_window_property_iv (screen_win, SCREEN_PROPERTY_ROTATION, & rotation);
If (rc! = 0) {}
fprintf (stderr, "error getting the window of the screen rotation: %d\n", rc);
Return EXIT_FAILURE;
}
int size [2];
RC = screen_get_window_property_iv (screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
If (rc! = 0) {}
fprintf (stderr, "error getting size memory buffer window screen: %d\n", rc);
Return EXIT_FAILURE;
}
int temp;
switch (angle - rotation) {}
case - 270:
case - 90:
decision 90:
case 270:
Temp = size [0];
size [0] = size [1];
size [1] = temp;
break;
by default:
break;
}
RC = screen_set_window_property_iv (screen_win, SCREEN_PROPERTY_ROTATION, &angle);)
If (rc! = 0) {}
fprintf (stderr, "screen rotation window for parameter error: %d\n", rc);
Return EXIT_FAILURE;
}
RC = screen_set_window_property_iv (screen_win, SCREEN_PROPERTY_SIZE, size);
If (rc! = 0) {}
fprintf (stderr, "error creating window screen size: %d\n", rc);
Return EXIT_FAILURE;
}
RC = screen_set_window_property_iv (screen_win, SCREEN_PROPERTY_SOURCE_SIZE, size);
If (rc! = 0) {}
fprintf (stderr, "error creating window screen size: %d\n", rc);
Return EXIT_FAILURE;
}
RC = screen_set_window_property_iv (screen_win, SCREEN_PROPERTY_BUFFER_SIZE, size);
If (rc! = 0) {}
fprintf (stderr, "error creating window buffer size of the screen: %d\n", rc);
Return EXIT_FAILURE;
}
Return EXIT_SUCCESS;
}

/**
To manage an event of navigator.
*
* @return @c the value true if the application should shut down, another fake.
*/
public static bool
handle_navigator_event(bps_event_t *Event)
{
bool should_exit = false;
switch (bps_event_get_code (event)) {}
case NAVIGATOR_EXIT:
should_exit = true;
break;
case NAVIGATOR_ORIENTATION_CHECK:
navigator_orientation_check_response (event, true);
break;
case NAVIGATOR_ORIENTATION:
{
int angle = navigator_event_get_orientation_angle (event);
If (rotate_screen (angle) == EXIT_FAILURE) {}
should_exit = true;
}
navigator_done_orientation (Event);
break;
}
}
Return should_exit;
}
/**
* Display an alert dialog box that contains the location data.
*/
public static void
show_main_dialog()
{
If {(main_dialog)
return;
}
dialog_create_alert(&main_dialog);
dialog_set_alert_message_text (main_dialog, "Acceleration to first fix");
dialog_set_size (main_dialog, DIALOG_SIZE_FULL);
dialog_set_group_id (main_dialog, get_window_group_id());
dialog_set_cancel_required (main_dialog, true);
dialog_show (main_dialog);
}

/**
* Displays geolocation data in the main dialog box.
*/
public static void
display_acceleration_data (float force_x, float force_y, float force_z) {}
char buf [1024];
snprintf (buf, sizeof buf,
"\tX: m\n % 7.3.f.
"\tY: m\n % 7.3.f.
"\tZ: m\n % 7.3.f."
force_x, force_y, force_z);
dialog_set_alert_message_text (main_dialog, buf);
dialog_update (main_dialog);
}

void createafile() {}
sprintf (fullname, "shared/documents/Raw-%d.txt",_logcounter);
{if(f==null)}
file does not exist
f = fopen (fullname, "r");
{while(f!=null)}
file exists
fclose (f);
++ _logcounter;
sprintf (fullname, "shared/documents/Raw-%d.txt",_logcounter);
f = fopen (fullname, "r");
}
}
}

write data to the file
void writedataintofile() {}
f = fopen (fullname, "w");
fprintf (f, "X (m/s2), Accel Accel Y (m/s2), Accel Z (m/s2) \n" ");
fprintf (f, "" 7% 7% .3f, .3f, %7.3f\n ', force_x, force_y, force_z ");
fclose (f);
}

/**
* A sample application shows the native APIs of BlackBerry for accelerometer.
* The example initializes and reads the accelerometer periodically until one
* NAVIGATOR_EXIT event is received.
Enforcement also tuned to changes status window in the browser so that
* It can stop reading the accelerometer when the application is no longer visible.
*/
int main (int argc, char * argv {})
bool exit_application = false;
/*
* Until we can listen for events from the BlackBerry Tablet OS platform
* services, we need to initialize the BPS infrastructure
*/
bps_initialize();
/*
* Once the BPS infrastructure has been initialized, we can save to
* events of different services of BlackBerry Tablet OS platform. The
* Browser service manages and provides the life cycle of application and
* events of visibility.
For the example, we ask browser events so that we can follow when
* the system ends the application (NAVIGATOR_EXIT event). This allows to
* us to clean up resources in the application.
*/
navigator_request_events (0);
dialog_request_events (0);
/*
* Initialize the screen so that the Windows Id is correctly set, to allow
* dialogs to display.
*/
If (setup_screen()! = EXIT_SUCCESS) {}
fprintf (stderr, "Failed to initialize the screen.");
Exit (-1);
}
/*
* Once the BPS infrastructure has been initialized, we can save to
* events of different services of BlackBerry Tablet OS platform. The
* Browser service manages and provides the life cycle of application and
* events of visibility.
*
For the example, we ask browser events so that we can follow when
* the system ends the application (NAVIGATOR_EXIT event).
*
* We ask events of dialogue so that we can be notified when the service of dialogue
* answers to our queries/requests.
*/
If (BPS_SUCCESS! = navigator_request_events (0)) {}
fprintf (stderr, "error asking navigator events: %s", strerror(errno) (errno));
Exit (-1);
}
If (BPS_SUCCESS! = dialog_request_events (0)) {}
fprintf (stderr, "error asking dialog events: %s", strerror(errno) (errno));
Exit (-1);
}
/*
* Create and display the dialog box that displays the data from the accelerometer.
*/
show_main_dialog();
/*
Prior to initialize the accelerometer function, we must ensure the unit
* takes in charge
*/
If (sensor_is_supported (SENSOR_TYPE_ACCELEROMETER)) {}
/*
* If the device does not support the accelerometer so warn the user,.
* clean in and out
*/
public static const int SENSOR_RATE = 40;
sensor_set_rate (SENSOR_TYPE_ACCELEROMETER, SENSOR_RATE);
sensor_request_events (SENSOR_TYPE_ACCELEROMETER);

}
/*
* Initialize the accelerometer setting the rate at which the
* accelerometer values will be updated material
*/
accelerometer_set_update_frequency (FREQ_40_HZ);

/*
Treat browser events and take the accelerometer readings periodically
* until we receive a NAVIGATOR_EXIT event.
*/
createafile();
f = fopen (fullname, "w");

While (! exit_application) {}
/*
* By setting the timeout to bps_get_event to ACCELEROMETER_MAX_POLL_INTERVAL,
* We assign the maximum duration (in millis) who will wait before
* release so that we can take a reading of the accelerometer.
*/
bps_event_t * event = NULL;
bps_get_event (& event, ACCELEROMETER_MAX_POLL_INTERVAL);

If {(event)
If (bps_event_get_domain (event) is {sensor_get_domain()})
/*
* We woke up. See if we are in the paused state. If not,
take a reading of the accelerometer
*/
If (! pause) {}
sensor_event_get_xyz (event, & force_x, & force_y, & force_z);
display_acceleration_data (force_x, force_y, force_z);
fprintf (f, "X (m/s2), Accel Accel Y (m/s2), Accel Z (m/s2) \n" ");
fprintf (f, "" 7% 7% .3f, .3f, %7.3f\n ', force_x, force_y, force_z ");
} //paused
}
/ * If this is an event of the dialog box, determine the response code and handle
* the event accordingly.
*/
{ElseIf (bps_event_get_domain (event) == dialog_get_domain() {)}
;
}
/*
* If it's a NAVIGATOR_EXIT event and then set the exit_application
* indicator so that the application stops processing events, clean and
* output.
*/
{ElseIf (bps_event_get_domain (event) == navigator_get_domain() {)}
exit_application = handle_navigator_event (event);
}
} //if event
} //while
/*
* Destroy the dialog box, if it exists.
*/
If {(main_dialog)
dialog_destroy (main_dialog);
}

fclose (f);

/*
* Clean the infrastructure bps and output
*/
sensor_stop_events (SENSOR_TYPE_ACCELEROMETER);
bps_shutdown();
screen_destroy_window (screen_win);
screen_destroy_context (screen_ctx);
return 0;
} //main

Hello

As I said on your other thread:

In order to write in the shared directory/documents, your application should request action "access_shared" and it must be granted by the user. Make sure you have

access_shared

in your bar - descriptor.xml.

Also note that the shared documents folder may not be the best place to write the application log data. There is one connects / in the sandbox to this effect, or the application directory data / directory if the information should be persisted. The documents/shared/folder is designed for documents that the user creates or interacts with.

HTH,

Christian

Tags: BlackBerry Developers

Similar Questions

  • Display Html, design mode and display CSS at the same time?

    Hi all!

    Well, that's my problem:

    I'm on a double screen, on a single screen monitor, I have the code Inspector "' to view my html code and the second screen, I have the design view.

    Problem is that I hate to always spend my tabs when I need to work on my Html and my CSS.

    I was wondering if anyone has found a way to show, I don't know maybe not 2 code inspector or simply to find a way to split the screen so I can see the html and css at the same time?

    Thank you very much!

    Nick

    If you are using Dreamweaver CS4, it's very easy. View the HTML code in the Code Inspector and have split vertical in the main Document window. In the related files toolbar, select the style sheet.

  • How many flv loaded at the same time?

    Hello

    an important point regarding my question is that all flv files that have been mentioned are local, so there is no delay involved download.

    I am writing a multicamera demo application that essentially lets you can switch between different camera on the same topic views: there are 5 flv files: one with four views together in a mosaic (made in editing and exported as a single flv file) more a flv by each of the 4 views.

    the very simple interface allows you to switch views to others, including mosaic view, so that, when a view is opened, the video starts playing at the same moment in time that you where when you clicked on in the previous screen.

    It will never be more than an FLV playing simultaneously, there will be other loading and pauses, but playing alone at the time.

    Since I did not download, my biggest concern is use of RAM and CPU. I use three video objects, one to hold the multicam flv and two for two single cam videos as possible. My question is this: what would be the most time and resources consuming, having three videos 'responsible but constantly stopped' (is an open NetConnection and a NetStream loaded with a clip in the paused state) or opening, loading and launch video at each request?

    Thank you very much in advance,

    José

    the least local resources would be by having a single instance of the netstream and by switching the stream when you want.  because these flows is downloading so there will be a (short) lag when switching.

    If this delay is not acceptable, then you must do what you are currently doing with multiple netstream instances if you want among all instances paused.

  • BlackBerry Smartphones AT & T 8310: SIM Card - SD card, how to use both at the same time?

    Just got my AT & T 8310 today so I apologize for my newbie question, but I want to install an SD card, but looks like it's going where the card SIM - does that mean that I have no telephone service I have the SD card as the SIM card is removed or am I missing something obvious?

    Hi and welcome to the forums!

    How about a coup! :

    http://CrackBerry.com/BlackBerry-101-Lecture-6-How-install-microSDHC-card-your-BlackBerry

    If this answers your question please solve the post, if not please ask for more!

    Thank you!

  • How can I enter BIOS compaq610 screen and set the date, time

    How can I enter BIOS compaq610 screen and set the date, time

    Hello

    See Page 94 or Page 100 (according to what's relevant) of your & Maintenance Guide.

    Kind regards

    DP - K

  • How to display date / time in the browser console?

    How to display date / time in the browser console?

    You can set through the Options (gear icon) page in the Web Console (Firefox/tools > Web Developer).
    This applies to the browser console and the Web console.

  • How to display on my screen 2 different applications at the same time?

    How to display on my screen 2 different applications at the same time?

    Hello

    The best place to ask would be the forums for answers corresponding to your version of Windows.

    Answers - Windows Forums
    http://answers.Microsoft.com/en-us/Windows

    =====================

    If you have Windows 7 with Aero - click with the right button on the taskbar at the bottom of the screen and click on 'show windows '.
    Side by Side.

    For all versions of Windows:

    You could also reduce less than full screen using the small box to the left of the red X at the top right
    and then resizing windows as you want.

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle=""><- mark="" twain="" said="" it="">

  • How to display two or more files on the screen at the same time in format "cascade" or "tile"?

    How to display two or more files on the screen at the same time in format "cascade" or "tile"?

    What types of files,

    He each file separately.

    Right-click your taskbar, and then click the option side by side...

    Breaking of Windows,

    http://Windows.Microsoft.com/en-us/Windows7/products/features/snap

    http://Windows.Microsoft.com/en-us/Windows7/arrange-Windows-side-by-side-on-the-desktop-using-snap

  • How to display two open sites at the same time on the screen instead of switch between tabs?

    I need to open two different sites using Firefox. They appear as tabs, but I can only show a tab at a time and have continually switch back. I need to have two separate sites open and displayed simultaneously on the screen. Is there a way to do this or an add-on that will support multiple windows open on the screen?

    You can open all pages in separate windows and resize and position windows horizontally or vertically to the two visible at the same time.

    Note that you can drag a tab slightly downwards in the navigation window to tear off the tab, or use the context menu of the tab (transition to the new window).

  • How to collect data on the programs of LabView and VC ++ at the same time?

    Hello

    There are two programs in LabVIEW and another is in VC ++. The two programs to collect hardware data.

    Therefore, for the experience, it is necessary to begin to collect data at the same time and lag must be

    less than millisecond (it is essential for the experience). How can this be achieved? BTW, I'm new to LabView.

    I think on the use of network socket to get the message for both applications.

    I was wondering if there is a better way.

    Thank you.

    MARK002-MAB wrote:

    Hello

    There are two programs in LabVIEW and another is in VC ++. The two programs to collect hardware data.

    Therefore, for the experience, it is necessary to begin to collect data at the same time and lag must be

    less than millisecond (it is essential for the experience). How can this be achieved? BTW, I'm new to LabView.

    I think on the use of network socket to get the message for both applications.

    I was wondering if there is a better way.

    Thank you.

    You do not say if two programs access the same material, but I guess not. Because if they did, you probably get conflicts when the two programs try to access the same material at the same time.

    In either case, the only really reliable way to ensure that your needs of< 1ms="" would="" be="" hardware="" triggering.="" one="" hardware="" unit="" is="" programmed="" to="" provide="" a="" hardware="" trigger,="" typically="" a="" digital="" signal="" and="" the="" other="" is="" programmed="" previous="" to="" the="" desired="" start="" point,="" to="" wait="" for="" that="" trigger="" and="" start="" automatically="" when="" it="" is="" received.="" if="" both="" hardware="" units="" are="" ni="" daq="" cards="" you="" can="" do="" that="" fairly="" easily="" using="" the="" rtsi="" bus="" or="" in="" case="" of="" pxi="" the="" pxi="" trigger="" lines.="" if="" they="" are="" different="" hardware="" then="" it="" can="" get="" more="" complicated="" to="">

  • How to have a media player and a document word on the screen at the same time?

    Original title: in a document.

    How to have a media player and a document word on the screen at the same time?  I opened an e-mail with a note of saved file and I type in a document.

    Hi Carol OB,.

    According to the description, it seems that you want to use document Word and Media Player at the same time. I'll be happy to help you in this problem.

    I suggest you to consult and follow the steps from the link that can help you in the use of both applications at the same time and check if it helps.

    Take an application: use two applications at the same time

    http://Windows.Microsoft.com/en-us/Windows-8/snap-apps#1TC=T1

    I hope this helps. Try the above steps and get back to us for assistance. We will be happy to help you.

  • How can I leave my desktop screen and go to the screen where I can click on the icons to go to the websites I want?

    How can I leave my desktop screen and go to the screen where I can click on the icons to go to the websites I want?

    Hello

    Please, move your cursor to the bottom left. You will see a small photo with the screen full of apps, then click on that and you will be taken to this screen,
    It will be useful.
    Josh.
  • How to run a window of data acquisition and another pane at the same time

    Hello

    I have a main window for data acquisition and in front panel there are four Sub Vi. When the main window of data acquisition is running and at the same time if I run the Subvi - main window stops data acquisition and the secondary window starts to run. But I want to launch the window of acquisition of primary data and the pane at the same time. Please give me a solution for this...

    Thanking in advance.

    Nikhil

    Hi Nikhil,

    My explanation has answered your question. Take a look at the image as an attachment. Let us know if you have any other questions.

  • Does anyone know how to display along with the app on the Mac App Store in the Sierra of MacOS?

    Does anyone know how to display along with the app on the Mac App Store in the Sierra of MacOS?

    I've just updated to Sierra. Since the upgrade did several reboots. When I discover an app the side also shows "4 +" or similar and I click on the note to view reviews and ratings of customer, a blank screen appears. Everyone knows this or have a way to solve this problem?

    I see even here in Seattle, so I think the question is about the end of Apple.

    By the end of 2012 Mac minis, macOS?  Watch 38 mm silver AL, watchOS 3; iPad 2 Air & iPhone 6 + iOS 10.0.1;  Apple Airport Express

  • How to hide a control and change a background image at the same TIME

    Hello

    I made a slideshow on LabView VI, who also monitors data in real time to a data logger.

    The program works like this: -.

    Start/Page 1:-bottom pane displays a nice screenshot. A set of indicators displays the data in real time. Switches to Page 2 after 20 seconds.

    Page 2:-background to an another screenshot. Hide indicators in real time and a set of three graphs appear, displaying historical data. Switches after 20 years.

    Page 3 etc:-hide charts and indicators, a 'slide show' appears by changing the history pane. Back to page 1 after the sequence.

    Everything works fine, except for one thing: I can't hide indicators and background to change at once, resulting in a clumsy "discrepancy" between the two.

    I did one VI example to illustrate this. Simply select two separate images to the façade, run the VI and toggle the Boolean control to see what I mean.

    Any idea how to get indicators and background of change at the same time?

    Thanks in advance,

    Hello

    Hi Jin,

    have you tried to "DeferPanelUpdates" when you power on? This is a property of the component...

    So David value = TRUE, do all the switching, to redefine Defer to FALSE!

  • Display brightness and RGB histograms at the same time on 7 d MII

    How can I display brightness and RGB histograms on the screen at the same time during playback on the 7 d MII.  Page 358 of the PDF manual shows a graph of the two together under Lens/histogram information, but I've been able to display one or the other, not both.

    I found the answer.  It takes a combination of the Info button and the button to display the two histograms.  In read mode, press the info button until the image and the histogram that is selected in the menu of the Play3 appear side-by-side, then use the multidirectional button(up/dn) to switch to the other the histogram.

Maybe you are looking for