views:

37

answers:

2

I would like add a this Apple example [AccelerometerGraph] the ability to store the data in a file until the app isn't closed. Without locking issues and other crappy problems of real time data collection.

Any idea, sample or something that a semi newbie can play with?

+1  A: 

you could log the accelerometer data into an NSMutableArray as it hits and then when the app is being closed write that array to a file with:

[array writeToFile:DataPath atomically:YES];

just want to make sure you dont store every single entry or it could get large very fast. Do some checking on the timestamp in the acceleration object in

- (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration 

make it log every couple of seconds depending on how long you are going to be running it. (this method would probably not be wise to run for long lengths of time without throttling it, or doing some other array manipulations so that the entire array isnt held in memory through out the life time of the app)

AtomRiot
A: 

If you are just wanting to view the data as it comes out, you can do the simple way of just logging it to the console.

In MainViewController.m, in the -(void)accelerometer: method just add

[filtered addX:filter.x y:filter.y z:filter.z];  // this line is already there
NSLog(@"%f, %f, %f", acceleration.x, acceleration.y, acceleration.z);

Then when you run it on the device, open up the debugger console and it will stream out the data for you. Here is what I got:

2010-07-13 22:15:45.187 AccelerometerGraph[11241:307] 0.072449, -0.018112, -1.068619
2010-07-13 22:15:45.203 AccelerometerGraph[11241:307] 0.072449, -0.018112, -1.068619
2010-07-13 22:15:45.219 AccelerometerGraph[11241:307] 0.072449, 0.000000, -1.050507
2010-07-13 22:15:45.236 AccelerometerGraph[11241:307] 0.054337, -0.018112, -1.032394
2010-07-13 22:15:45.254 AccelerometerGraph[11241:307] 0.054337, -0.018112, -1.014282
2010-07-13 22:15:45.272 AccelerometerGraph[11241:307] 0.072449, -0.018112, -1.050507
2010-07-13 22:15:45.287 AccelerometerGraph[11241:307] 0.072449, -0.018112, -1.068619
christophercotton
thanks for your answer, however as I pointed out, I was looking for a way to store it, not to just display the data in the console.
amok
Yep, the other person had already posted how to do via file, so I just added another way in case you wanted just to see it. My example also shows where to add the logging (either file or stream).
christophercotton