Changeset ad80ed2 in orbit for iOS


Ignore:
Timestamp:
08/27/13 02:48:11 (6 years ago)
Author:
Steve Castellotti <sc@…>
Branches:
master, Servo, Tab_Interface, pyramid
Children:
f43124e
Parents:
d249b65
Message:

Orbit:

  • Set Attention and Meditation to zero if we've lost signal
Location:
iOS/Orbit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • iOS/Orbit/Orbit/controllers/FlightViewController.m

    rd249b65 rad80ed2  
    2222 
    2323@implementation FlightViewController { 
    24     SignalConverter *signalConverter; 
    25     int deviceStatus; 
    26     BOOL warned; 
     24   SignalConverter *signalConverter; 
     25   int deviceStatus; 
     26   BOOL warned; 
    2727} 
    2828 
     
    3131- (void)viewDidLoad 
    3232{ 
    33     [super viewDidLoad]; 
    34  
    35     attention.progressTintColor = [UIColor redColor]; 
    36     self.attentionThreshold.minimumTrackTintColor = [UIColor grayColor]; 
    37     meditation.progressTintColor = [UIColor blueColor]; 
    38     self.meditationThreshold.minimumTrackTintColor = [UIColor grayColor]; 
    39     self.meditationThreshold.value = 0; 
     33   [super viewDidLoad]; 
    4034    
    41     AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
    42     signalConverter = appDelegate.signalConverter; 
    43      
    44     signalConverter.delegate = self; 
    45     [self setThresholds]; 
    46     [self.attentionThreshold addTarget:self action:@selector(setThresholds) forControlEvents:UIControlEventValueChanged]; 
    47     [self.meditationThreshold addTarget:self action:@selector(setThresholds) forControlEvents:UIControlEventValueChanged]; 
     35   attention.progressTintColor = [UIColor redColor]; 
     36   self.attentionThreshold.minimumTrackTintColor = [UIColor grayColor]; 
     37   meditation.progressTintColor = [UIColor blueColor]; 
     38   self.meditationThreshold.minimumTrackTintColor = [UIColor grayColor]; 
     39   self.meditationThreshold.value = 0; 
     40    
     41   AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
     42   signalConverter = appDelegate.signalConverter; 
     43    
     44   signalConverter.delegate = self; 
     45   [self setThresholds]; 
     46   [self.attentionThreshold addTarget:self action:@selector(setThresholds) forControlEvents:UIControlEventValueChanged]; 
     47   [self.meditationThreshold addTarget:self action:@selector(setThresholds) forControlEvents:UIControlEventValueChanged]; 
    4848} 
    4949 
     
    5353- (void) resetViews 
    5454{ 
    55     signal.progress = 0; 
    56     signalPercent.text = @"0%"; 
    57     attention.progress = 0; 
    58     attentionPercent.text = @"0%"; 
    59     meditation.progress = 0; 
    60     meditationPercent.text = @"0%"; 
    61     power.progress = 0; 
    62     powerPercent.text = @"0%"; 
    63     [self updateStatusImage:STATUS_DEFAULT]; 
    64     connectButton.title = @"Connect"; 
     55   signal.progress = 0; 
     56   signalPercent.text = @"0%"; 
     57   attention.progress = 0; 
     58   attentionPercent.text = @"0%"; 
     59   meditation.progress = 0; 
     60   meditationPercent.text = @"0%"; 
     61   power.progress = 0; 
     62   powerPercent.text = @"0%"; 
     63   [self updateStatusImage:STATUS_DEFAULT]; 
     64   connectButton.title = @"Connect"; 
    6565} 
    6666 
    6767- (void) updateStatusImage:(int) statusNo 
    6868{ 
    69     if (statusNo != deviceStatus) { 
    70         [statusImage setImage: [UIImage imageNamed:[NSString stringWithFormat:@"status_%u", statusNo]]]; 
    71         deviceStatus = statusNo; 
    72     } 
     69   if (statusNo != deviceStatus) { 
     70      [statusImage setImage: [UIImage imageNamed:[NSString stringWithFormat:@"status_%u", statusNo]]]; 
     71      deviceStatus = statusNo; 
     72   } 
    7373} 
    7474 
    7575- (void) setThresholds 
    7676{ 
    77     [signalConverter setValuesForAttention:attentionThreshold.value meditation:meditationThreshold.value]; 
     77   [signalConverter setValuesForAttention:attentionThreshold.value meditation:meditationThreshold.value]; 
    7878} 
    7979 
     
    8585                          power: (float)powerLevel 
    8686{ 
     87   
     88   // Set Attention and Meditation to zero if we've lost signal 
     89   if (signalStrength < 100.0) { 
     90      attentionLevel = 0.000000; 
     91      meditationLevel = 0.000000; 
     92      powerLevel = 0.000000; 
     93   } 
    8794    
    88 //   self.signal.progress = (int)(signalStrength); 
    89     self.signal.progress = signalStrength / 100; 
    90 //    NSLog(@"Setting self.signal.progress: %f", signalStrength / 100); 
     95   self.signal.progress = signalStrength / 100; 
     96   self.signalPercent.text = [NSString stringWithFormat:@"%i%%", (int)(signalStrength)]; 
     97   self.attention.progress = attentionLevel; 
     98   self.attentionPercent.text = [NSString stringWithFormat:@"%i%%", (int)(attentionLevel * 100)]; 
     99   self.meditation.progress = meditationLevel; 
     100   self.meditationPercent.text = [NSString stringWithFormat:@"%i%%", (int)(meditationLevel * 100)]; 
     101   self.power.progress = powerLevel; 
     102   self.powerPercent.text = [NSString stringWithFormat:@"%i%%", (int)(powerLevel * 100)]; 
     103   [self updateStatusImage:[self statusFromSignal:signalStrength power:powerLevel]]; 
    91104    
    92     self.signalPercent.text = [NSString stringWithFormat:@"%i%%", (int)(signalStrength)]; 
    93     self.attention.progress = attentionLevel; 
    94     self.attentionPercent.text = [NSString stringWithFormat:@"%i%%", (int)(attentionLevel * 100)]; 
    95     self.meditation.progress = meditationLevel; 
    96     self.meditationPercent.text = [NSString stringWithFormat:@"%i%%", (int)(meditationLevel * 100)]; 
    97     self.power.progress = powerLevel; 
    98     self.powerPercent.text = [NSString stringWithFormat:@"%i%%", (int)(powerLevel * 100)]; 
    99     [self updateStatusImage:[self statusFromSignal:signalStrength power:powerLevel]]; 
    100105} 
    101106 
    102107- (int) statusFromSignal: (float)signalLevel power:(float)powerLevel 
    103108{ 
    104     if (signalLevel < 0.9) { // weak signal 
    105         return STATUS_CONNECTED; 
    106     } else if (powerLevel == 0.0) { // strong signal but thresholds not met 
    107         return STATUS_PROCESSING; 
    108     } else { // flight command sent to orbit 
    109         return STATUS_ACTIVE; 
    110     } 
     109   if (signalLevel < 0.9) { // weak signal 
     110      return STATUS_CONNECTED; 
     111   } else if (powerLevel == 0.0) { // strong signal but thresholds not met 
     112      return STATUS_PROCESSING; 
     113   } else { // flight command sent to orbit 
     114      return STATUS_ACTIVE; 
     115   } 
    111116} 
    112117 
    113118- (void) notifyHeadsetConnect 
    114119{ 
    115     [self updateStatusImage:STATUS_CONNECTING]; 
     120   [self updateStatusImage:STATUS_CONNECTING]; 
    116121} 
    117122 
    118123- (void) notifyHeadsetDisconnect 
    119124{ 
    120     // Reset the outputs back to zero 
    121     [self resetViews]; 
     125   // Reset the outputs back to zero 
     126   [self resetViews]; 
    122127} 
    123128 
    124129- (void) notifyDeviceConnected:(NSString *)name 
    125130{ 
    126     [self updateStatusImage:STATUS_CONNECTING]; 
    127     connectButton.title = @"Disconnect"; 
     131   [self updateStatusImage:STATUS_CONNECTING]; 
     132   connectButton.title = @"Disconnect"; 
    128133} 
    129134 
    130135- (void) appStopped 
    131136{ 
    132     [self resetViews]; // just in case it didn't happen on close 
     137   [self resetViews]; // just in case it didn't happen on close 
    133138} 
    134139 
     
    136141 
    137142- (IBAction) connectButtonPressed:(id) sender { 
    138      
    139     if (signalConverter.running) { 
    140         [signalConverter stopProcessing]; 
    141         [self resetViews]; 
    142     } else { 
    143         BOOL volumeMax  = [signalConverter isVolumeMax]; 
    144         BOOL headphones = [signalConverter isAudioJackPlugged]; 
    145          
    146         if (!warned && !volumeMax && !headphones) { 
    147             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Check Volume & Transmitter" message:@"Ensure the volume is at max and the transmitter is plugged into the headphones" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    148             [alert show]; 
    149         } else if (!warned && !volumeMax) { 
    150             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Turn Up The Volume" message:@"Your device volume must be at the maximum for proper operation" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    151             [alert show]; 
    152         } else if (!warned && !headphones) { 
    153             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Plug In The Transmitter" message:@"Ensure the infrared transmitter is plugged into the headphone jack" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    154             [alert show]; 
    155         } else if (!signalConverter.isBluetoothReady) { 
    156             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Device not found" message:@"No Bluetooth device detected. Ensure Bluetooth is on and the Mindwave headset is paired" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    157             [alert show]; 
    158         } else if ([signalConverter startProcessing]) { 
    159             connectButton.title = @"Disconnect"; 
    160         } else { 
    161             UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed to connect" message:@"Check the device is correctly paired on Bluetooth" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    162             [alert show]; 
    163         } 
    164         warned = YES; 
    165     } 
     143    
     144   if (signalConverter.running) { 
     145      [signalConverter stopProcessing]; 
     146      [self resetViews]; 
     147   } else { 
     148      BOOL volumeMax  = [signalConverter isVolumeMax]; 
     149      BOOL headphones = [signalConverter isAudioJackPlugged]; 
     150       
     151      if (!warned && !volumeMax && !headphones) { 
     152         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Check Volume & Transmitter" message:@"Ensure the volume is at max and the transmitter is plugged into the headphones" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     153         [alert show]; 
     154      } else if (!warned && !volumeMax) { 
     155         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Turn Up The Volume" message:@"Your device volume must be at the maximum for proper operation" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     156         [alert show]; 
     157      } else if (!warned && !headphones) { 
     158         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Plug In The Transmitter" message:@"Ensure the infrared transmitter is plugged into the headphone jack" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     159         [alert show]; 
     160      } else if (!signalConverter.isBluetoothReady) { 
     161         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Device not found" message:@"No Bluetooth device detected. Ensure Bluetooth is on and the Mindwave headset is paired" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     162         [alert show]; 
     163      } else if ([signalConverter startProcessing]) { 
     164         connectButton.title = @"Disconnect"; 
     165      } else { 
     166         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed to connect" message:@"Check the device is correctly paired on Bluetooth" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     167         [alert show]; 
     168      } 
     169      warned = YES; 
     170   } 
    166171} 
    167172 
    168173- (IBAction) testButtonPressed:(id) sender { 
    169     [signalConverter isAudioJackPlugged]; 
    170     if (signalConverter.running) { 
    171         UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Stop test sound" message:@"Press Stop first to end the test" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
    172         [alert show]; 
    173     } else { 
    174         if (signalConverter.testing) { 
    175             testButton.title = @"Test"; 
    176             [signalConverter stopTestSound]; 
    177         } else { 
    178             testButton.title = @"Stop"; 
    179             [signalConverter playTestSound]; 
    180         } 
    181     } 
     174   [signalConverter isAudioJackPlugged]; 
     175   if (signalConverter.running) { 
     176      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Stop test sound" message:@"Press Stop first to end the test" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     177      [alert show]; 
     178   } else { 
     179      if (signalConverter.testing) { 
     180         testButton.title = @"Test"; 
     181         [signalConverter stopTestSound]; 
     182      } else { 
     183         testButton.title = @"Stop"; 
     184         [signalConverter playTestSound]; 
     185      } 
     186   } 
    182187} 
    183188 
Note: See TracChangeset for help on using the changeset viewer.