Changeset 9015b1e in orbit for iOS/Orbit/Orbit/controllers


Ignore:
Timestamp:
07/19/13 15:59:47 (9 years ago)
Author:
Jonathon Horsman <jonathon@…>
Branches:
master, RawEEG, Servo, Tab_Interface, pyramid
Children:
ce0a7ee, c61115c
Parents:
ab9d63b
Message:

UI working with headset correctly now.
Check Bluetooth enabled and volume at full

File:
1 edited

Legend:

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

    rab9d63b r9015b1e  
    2323@implementation FlightViewController { 
    2424    SignalConverter *signalConverter; 
     25    int deviceStatus; 
    2526} 
    2627 
    27 @synthesize status, attention, meditation, signal, power, attentionThreshold, meditationThreshold, connectButton, statusImage; 
     28@synthesize status, attention, meditation, signal, power, attentionThreshold, meditationThreshold, connectButton, statusImage, signalPercent, attentionPercent, meditationPercent, powerPercent; 
    2829 
    2930- (void)viewDidLoad 
     
    3940} 
    4041 
    41 // Start the data stream from the bluetooth headset if it's attached, and reset the display output 
    42 - (void) appForegrounded 
    43 { 
    44     [self resetViews]; // just in case it didn't happen on close 
    45 } 
    46  
    4742#pragma mark view updates 
    4843 
     
    5146{ 
    5247    signal.progress = 0; 
     48    signalPercent.text = @"0%"; 
    5349    attention.progress = 0; 
     50    attentionPercent.text = @"0%"; 
    5451    meditation.progress = 0; 
     52    meditationPercent.text = @"0%"; 
    5553    power.progress = 0; 
     54    powerPercent.text = @"0%"; 
    5655    [self logMessage:@"Disconnected"]; 
     56    [self updateStatusImage:STATUS_DEFAULT]; 
     57    connectButton.title = @"Connect"; 
    5758} 
    5859 
    5960- (void) updateStatusImage:(int) statusNo 
    6061{ 
    61     [statusImage setImage: [UIImage imageNamed:[NSString stringWithFormat:@"status_%u", statusNo]]]; 
     62    if (statusNo != deviceStatus) { 
     63        [statusImage setImage: [UIImage imageNamed:[NSString stringWithFormat:@"status_%u", statusNo]]]; 
     64        deviceStatus = statusNo; 
     65        if (statusNo == STATUS_CONNECTED) { 
     66            [self logMessage:@"Check headset fitted properly"]; 
     67        } else if (statusNo == STATUS_PROCESSING) { 
     68            [self logMessage:@"Increase your concentration"]; 
     69        } else if (statusNo == STATUS_ACTIVE) { 
     70            [self logMessage:@"Flying!"]; 
     71        } 
     72    } 
    6273} 
    6374 
     
    6576{ 
    6677    [signalConverter setValuesForAttention:attentionThreshold.value meditation:meditationThreshold.value]; 
    67 //     
    68 //    if (attentionThreshold.value < 0.2) { 
    69 //        [self updateStatusImage:STATUS_DEFAULT]; 
    70 //    } else if (attentionThreshold.value < 0.4) { 
    71 //        [self updateStatusImage:STATUS_CONNECTING]; 
    72 //    } else if (attentionThreshold.value < 0.6) { 
    73 //        [self updateStatusImage:STATUS_CONNECTED]; 
    74 //    } else if (attentionThreshold.value < 0.8) { 
    75 //        [self updateStatusImage:STATUS_PROCESSING]; 
    76 //    } else { 
    77 //        [self updateStatusImage:STATUS_ACTIVE]; 
    78 //    } 
    7978} 
    8079 
     
    9998    self.power.progress = powerLevel; 
    10099    self.powerPercent.text = [NSString stringWithFormat:@"%i%%", (int)(powerLevel * 100)]; 
     100    [self updateStatusImage:[self statusFromSignal:signalStrength power:powerLevel]]; 
     101} 
     102 
     103- (int) statusFromSignal: (float)signalLevel power:(float)powerLevel 
     104{ 
     105    if (signalLevel < 0.9) { // weak signal 
     106        return STATUS_CONNECTED; 
     107    } else if (powerLevel == 0.0) { // strong signal but thresholds not met 
     108        return STATUS_PROCESSING; 
     109    } else { // flight command sent to orbit 
     110        return STATUS_ACTIVE; 
     111    } 
    101112} 
    102113 
    103114- (void) notifyHeadsetConnect 
    104115{ 
    105     [self logMessage:@"Headet connected"]; 
     116    [self logMessage:@"Headset connected"]; 
     117    [self updateStatusImage:STATUS_CONNECTING]; 
    106118} 
    107119 
     
    110122    // Reset the outputs back to zero 
    111123    [self resetViews]; 
    112     [self logMessage:@"Headet disconnected"];     
    113124} 
    114125 
    115126- (void) notifyDeviceConnected:(NSString *)name 
    116127{ 
    117     [self logMessage:[NSString stringWithFormat:@"EEG device %@ connected", name]];     
     128    [self logMessage:[NSString stringWithFormat:@"EEG device %@ connected", name]]; 
     129    [self updateStatusImage:STATUS_CONNECTING]; 
     130    connectButton.title = @"Disconnect"; 
     131} 
     132 
     133- (void) appStopped 
     134{ 
     135    [self resetViews]; // just in case it didn't happen on close 
    118136} 
    119137 
     
    124142    if (signalConverter.running) { 
    125143        [signalConverter stopProcessing]; 
    126         connectButton.title = @"Connect"; 
    127144        [self resetViews]; 
     145    } else if (!signalConverter.isBluetoothReady) { 
     146        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]; 
     147        [alert show]; 
     148    } else if (!signalConverter.isVolumeMax) { 
     149        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]; 
     150        [alert show]; 
     151    } else if ([signalConverter startProcessing]) { 
     152        [self logMessage:@"Searching for device"]; 
     153//        [self updateStatusImage:STATUS_CONNECTING]; 
     154        connectButton.title = @"Disconnect"; 
    128155    } else { 
    129         [self logMessage:@"Searching for device"]; 
    130         [signalConverter startProcessing]; 
    131         connectButton.title = @"Disconnect"; 
     156        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Failed to connect" message:@"Check the device is correctly paired on Bluetooth" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil]; 
     157        [alert show]; 
    132158    } 
    133159} 
Note: See TracChangeset for help on using the changeset viewer.