Accelerometer to csv - Looking for clues

Discussion in 'iOS Programming' started by rd42, Mar 6, 2010.

  1. rd42 macrumors newbie

    Joined:
    Mar 6, 2010
    #1
    I'm looking for clues, pointers (no pun), and search term suggestions on where to start looking for a way to record accelerometer data to a csv file and possibly email/ftp it out. I'm new to Obj C so I'm not quite sure where to start.

    I found this simple accelerometer tutorial that displays the data I want to record.
    http://www.switchonthecode.com/tutorials/iphone-tutorial-reading-the-accelerometer

    In MainViewController.m starting at line 44 I found this:

    Code:
    - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {
      labelX.text = [NSString stringWithFormat:@"%@%f", @"X: ", acceleration.x];
      labelY.text = [NSString stringWithFormat:@"%@%f", @"Y: ", acceleration.y];
      labelZ.text = [NSString stringWithFormat:@"%@%f", @"Z: ", acceleration.z];
      
      self.progressX.progress = ABS(acceleration.x);
      self.progressY.progress = ABS(acceleration.y);
      self.progressZ.progress = ABS(acceleration.z);
    }
    I'm guessing that somewhere in that method I could capture the accelerometer data and write to a file.

    Thanks for any ideas,

    Robert
     
  2. Thomas Harte macrumors 6502

    Joined:
    Nov 30, 2005
    #2
    Cocoa/Objective C uses the delegation model quite a lot — where one object nominates itself to receive reports from another. What you'll do to read the accelerometer is write a class that acts as a delegate to receive accelerometer reports. The method you've found is the one that receives the reports, from an Apple-supplied class called UIAccelerometer.

    Probably the easiest thing to allow reporting is to keep a mutable string and append accelerometer status to it. Add a button to post an email and when the user taps it, use MessageUI to bring up an email dialogue. For security reasons, there's no provided method to send an email silently.

    For simplicity, it's probably fine to just chuck all this functionality into the application delegate for now.
     
  3. rd42 thread starter macrumors newbie

    Joined:
    Mar 6, 2010
    #3
    Thanks, I just discovered the mail challenge.

    I'll check ou NSMutableString, thanks!
     

Share This Page