Changeset daf54d5 in orbit for iOS/Orbit/Orbit/ViewController.m


Ignore:
Timestamp:
12/25/12 16:52:35 (8 years ago)
Author:
Steve Castellotti <sc@…>
Branches:
master, RawEEG, Raw_EEG_Plot, Servo, Tab_Interface, pyramid
Children:
ae32e69
Parents:
2aabdf3
Message:
  • Connect button added to interface
  • Variable volume level fixed
  • Enhanced display log output
File:
1 edited

Legend:

Unmodified
Added
Removed
  • iOS/Orbit/Orbit/ViewController.m

    r2aabdf3 rdaf54d5  
    2828    
    2929   int currentAttentionLevel, currentMeditationLevel; // the latest readings from the headset 
     30   BOOL processingDevice; 
    3031   BOOL demoRunning; 
    3132} 
    3233 
    33 @synthesize log, attention, meditation, signal, power, attentionThreshold, meditationThreshold, demoButton; 
     34@synthesize log, attention, meditation, signal, power, attentionThreshold, meditationThreshold, connectButton, demoButton; 
    3435 
    3536- (void)viewDidLoad 
     
    5253- (void) appForegrounded 
    5354{ 
    54    EAAccessory *accessory = [[TGAccessoryManager sharedTGAccessoryManager] accessory]; 
    55    if (accessory != nil) { 
    56       [self logMessage:[NSString stringWithFormat:@"App opened with %@ connected. Starting data stream", accessory.name]]; 
    57       [[TGAccessoryManager sharedTGAccessoryManager] startStream]; 
    58    } 
     55   //   EAAccessory *accessory = [[TGAccessoryManager sharedTGAccessoryManager] accessory]; 
     56   //   if (accessory != nil) { 
     57   //      [self logMessage:[NSString stringWithFormat:@"App opened with %@ connected. Starting data stream", accessory.name]]; 
     58   //      [[TGAccessoryManager sharedTGAccessoryManager] startStream]; 
     59   //   } 
    5960   [self resetViews]; // just in case it didn't happen on close 
    6061} 
     
    135136// The headset was switched on, start the data stream 
    136137- (void)accessoryDidConnect:(EAAccessory *)accessory { 
    137    [self logMessage:[NSString stringWithFormat:@"%@ was connected to this device. Starting data stream...", [accessory name]]]; 
     138   [self logMessage:[NSString stringWithFormat:@"%@ connected to this device", [accessory name]]]; 
    138139   if ([[TGAccessoryManager sharedTGAccessoryManager] accessory] != nil) { 
    139140      [[TGAccessoryManager sharedTGAccessoryManager] startStream]; 
     
    144145// Reset the outputs back to zero 
    145146- (void)accessoryDidDisconnect { 
    146    [self logMessage:@"Accessory was disconnected."]; 
     147   [self logMessage:@"Accessory was disconnected"]; 
    147148   [self resetOutputToZero]; 
    148149} 
     
    221222- (void) playAudio 
    222223{ 
    223    audioPlayer.volume = [self currentPowerLevel]; 
    224    [audioPlayer play]; 
     224   //   audioPlayer.volume = [self currentPowerLevel]; 
     225   if ([self currentPowerLevel] > 0) { 
     226      audioPlayer.volume = 100; 
     227      [audioPlayer play]; 
     228   } else { 
     229      [audioPlayer stop]; 
     230   } 
    225231} 
    226232 
     
    245251      [audioPlayer stop]; 
    246252   } 
     253   [self logMessage:@"Demo stopped"]; 
    247254} 
    248255 
     
    288295   } 
    289296} 
     297 
     298- (void) startProcessing 
     299{ 
     300   processingDevice = YES; 
     301   [self logMessage:@"Connecting to EEG Headset"]; 
     302   [connectButton setTitle:@"Disconnect" forState:UIControlStateNormal]; 
     303    
     304   EAAccessory *accessory = [[TGAccessoryManager sharedTGAccessoryManager] accessory]; 
     305   if (accessory != nil) { 
     306      [self logMessage:[NSString stringWithFormat:@"EEG device %@ connected", accessory.name]]; 
     307      [[TGAccessoryManager sharedTGAccessoryManager] startStream]; 
     308   } 
     309    
     310} 
     311 
     312- (void) stopProcessing 
     313{ 
     314   processingDevice = NO; 
     315   [self logMessage:@"Disconnecting from EEG Headset"]; 
     316   if ([[TGAccessoryManager sharedTGAccessoryManager] connected]) { 
     317      [[TGAccessoryManager sharedTGAccessoryManager] stopStream]; 
     318   } 
     319   [connectButton setTitle:@"Connect" forState:UIControlStateNormal]; 
     320    
     321   [self resetOutputToZero]; 
     322   [audioPlayer stop]; 
     323    
     324} 
     325 
     326- (IBAction) connectButtonPressed:(id) sender { 
     327    
     328   if (processingDevice) { 
     329      [self stopProcessing]; 
     330   } else { 
     331      [self startProcessing]; 
     332   } 
     333    
     334} 
    290335@end 
Note: See TracChangeset for help on using the changeset viewer.