Ignore:
Timestamp:
07/19/13 15:59:47 (7 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/SignalConverter.m

    rab9d63b r9015b1e  
    1313#define ATTENTION_KEY @"eSenseAttention" 
    1414#define MEDITATION_KEY @"eSenseMeditation" 
     15 
     16#define CHANNEL_A 1 
    1517 
    1618// Converts signals received from the EEG headset to the audio played to fly the helicopter. 
     
    2931@synthesize attentionThreshold, meditationThreshold, running; 
    3032 
     33 
     34- (id) init 
     35{ 
     36    self = [super init]; 
     37    if (self) 
     38    { 
     39        [[TGAccessoryManager sharedTGAccessoryManager] setupManagerWithInterval:0.05]; 
     40        [[TGAccessoryManager sharedTGAccessoryManager] setDelegate:self]; 
     41    } 
     42    return self; 
     43} 
     44 
    3145- (void) setValuesForAttention:(float) attention meditation:(float) meditation 
    3246{ 
     
    4559} 
    4660 
    47 - (void) appClosed 
    48 { 
    49     if ([[TGAccessoryManager sharedTGAccessoryManager] connected]) { 
     61- (void) appStopped 
     62{ 
     63    running = NO; 
     64    if ([TGAccessoryManager sharedTGAccessoryManager].accessory != nil) { 
    5065        [[TGAccessoryManager sharedTGAccessoryManager] stopStream]; 
     66    } 
     67    [audioPlayer stop]; 
     68    if (_delegate != nil) { 
     69        [_delegate appStopped]; 
    5170    } 
    5271} 
     
    105124// The headset was switched on, start the data stream 
    106125- (void)accessoryDidConnect:(EAAccessory *)accessory { 
    107     if (_delegate != nil) 
    108     { 
    109         [_delegate notifyHeadsetConnect]; 
    110     } 
    111     if ([[TGAccessoryManager sharedTGAccessoryManager] accessory] != nil) { 
    112         [[TGAccessoryManager sharedTGAccessoryManager] startStream]; 
    113     } 
    114126} 
    115127 
     
    122134} 
    123135 
     136- (BOOL) isBluetoothReady 
     137{ 
     138    return [[TGAccessoryManager sharedTGAccessoryManager] accessory] != NULL; 
     139} 
     140 
     141- (BOOL) isVolumeMax 
     142{ 
     143    float volume = [[AVAudioSession sharedInstance] outputVolume]; 
     144//    Float32 volume; 
     145//    UInt32 dataSize = sizeof(Float32); 
     146//     
     147//    AudioSessionGetProperty ( 
     148//                             kAudioSessionProperty_CurrentHardwareOutputVolume, 
     149//                             &dataSize, 
     150//                             &volume 
     151//                             ); 
     152    return volume == 1.0; 
     153} 
     154 
    124155#pragma mark start / stop methods 
    125156 
    126 - (void) startProcessing 
    127 { 
    128     running = YES; 
     157- (BOOL) startProcessing 
     158{ 
    129159    EAAccessory *accessory = [[TGAccessoryManager sharedTGAccessoryManager] accessory]; 
    130160    if (accessory != nil) { 
    131         if (_delegate != nil) 
    132         { 
     161        running = YES; 
     162        if (_delegate != nil) { 
    133163            [_delegate notifyDeviceConnected: accessory.name]; 
    134164        } 
    135165        [[TGAccessoryManager sharedTGAccessoryManager] startStream]; 
    136166    } 
     167    return running; 
    137168} 
    138169 
    139170- (void) stopProcessing 
    140171{ 
    141     running = NO; 
    142     if ([[TGAccessoryManager sharedTGAccessoryManager] connected]) { 
    143         [[TGAccessoryManager sharedTGAccessoryManager] stopStream]; 
    144     } 
    145     [audioPlayer stop]; 
     172    [self appStopped]; 
    146173    [self prepare];     
    147174} 
     
    202229} 
    203230 
     231// calculate the checksum for the generated code used to generate the WAV array 
     232- (int) codeChecksum:(int)code 
     233{ 
     234    int checksum = 0; 
     235    for (int i = 0; i < 7; i++) { 
     236        checksum += (code >> 4*i) & 15; 
     237    } 
     238    return 16 - (checksum & 15); 
     239} 
     240 
     241// Generate the code used to create the WAV file based on the given throttle, yaw and pitch. 
     242// Copied from AudioService.java in the Android app 
     243// throttle: 0~127, nothing will happen if this value is below 30. 
     244// yaw: 0~127, normally 78 will keep orbit from rotating. 
     245// pitch: 0~63, normally 31 will stop the top propeller. 
     246// channel: 1=Channel A, 0=Channel B 2= Channel C, depend on which channel you want to pair to the orbit. You can fly at most 3 orbit in a same room. 
     247- (int) generateCodeFromThrottle: (int)throttle yaw: (int)yaw pitch: (int)pitch channel: (int)channel 
     248{ 
     249    int code = (throttle << 21) + 1048576 + (yaw << 12) + (pitch << 4) + (((channel >> 1) & 1) << 19) + ((channel & 1) << 11); 
     250    return code;// + codeChecksum(code); 
     251} 
     252 
    204253@end 
Note: See TracChangeset for help on using the changeset viewer.