Changeset 9015b1e in orbit for iOS/Orbit/Orbit/controllers/FlightViewController.m
- Timestamp:
- 07/19/13 15:59:47 (9 years ago)
- Branches:
- master, RawEEG, Servo, Tab_Interface, pyramid
- Children:
- ce0a7ee, c61115c
- Parents:
- ab9d63b
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
iOS/Orbit/Orbit/controllers/FlightViewController.m
rab9d63b r9015b1e 23 23 @implementation FlightViewController { 24 24 SignalConverter *signalConverter; 25 int deviceStatus; 25 26 } 26 27 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; 28 29 29 30 - (void)viewDidLoad … … 39 40 } 40 41 41 // Start the data stream from the bluetooth headset if it's attached, and reset the display output42 - (void) appForegrounded43 {44 [self resetViews]; // just in case it didn't happen on close45 }46 47 42 #pragma mark view updates 48 43 … … 51 46 { 52 47 signal.progress = 0; 48 signalPercent.text = @"0%"; 53 49 attention.progress = 0; 50 attentionPercent.text = @"0%"; 54 51 meditation.progress = 0; 52 meditationPercent.text = @"0%"; 55 53 power.progress = 0; 54 powerPercent.text = @"0%"; 56 55 [self logMessage:@"Disconnected"]; 56 [self updateStatusImage:STATUS_DEFAULT]; 57 connectButton.title = @"Connect"; 57 58 } 58 59 59 60 - (void) updateStatusImage:(int) statusNo 60 61 { 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 } 62 73 } 63 74 … … 65 76 { 66 77 [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 // }79 78 } 80 79 … … 99 98 self.power.progress = powerLevel; 100 99 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 } 101 112 } 102 113 103 114 - (void) notifyHeadsetConnect 104 115 { 105 [self logMessage:@"Headet connected"]; 116 [self logMessage:@"Headset connected"]; 117 [self updateStatusImage:STATUS_CONNECTING]; 106 118 } 107 119 … … 110 122 // Reset the outputs back to zero 111 123 [self resetViews]; 112 [self logMessage:@"Headet disconnected"];113 124 } 114 125 115 126 - (void) notifyDeviceConnected:(NSString *)name 116 127 { 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 118 136 } 119 137 … … 124 142 if (signalConverter.running) { 125 143 [signalConverter stopProcessing]; 126 connectButton.title = @"Connect";127 144 [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"; 128 155 } 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]; 132 158 } 133 159 }
Note: See TracChangeset
for help on using the changeset viewer.