0

I am working on a project using Neurosky MindWave to create an IOS app. I am using the ThinkGear SDK for IOS available here: http://developer.neurosky.com/docs/doku.php?id=beta

The project reads values from the MindWave device and stores them in a NSDictionary in Objective C implementation file. I am trying to access these values in my Swift file to control 3D animations in SceneKit.

Here's the set up in the header file:

// the eSense values
typedef struct {
int attention;
 int meditation;
} ESenseValues;

// the EEG power bands
typedef struct {
int delta;
int theta;
int lowAlpha;
int highAlpha;
int lowBeta;
int highBeta;
int lowGamma;
int highGamma;
} EEGValues;

@interface RootViewController : UITableViewController        <TGAccessoryDelegate> {
short rawValue;
int rawCount;
int buffRawCount;
int blinkStrength;
int poorSignalValue;
int heartRate;
float respiration;
int heartRateAverage;
int heartRateAcceleration;

ESenseValues eSenseValues;
EEGValues eegValues;

bool logEnabled;
NSFileHandle * logFile;
NSString * output;

UIView * loadingScreen;

NSThread * updateThread;
}

// TGAccessoryDelegate protocol methods
- (void)accessoryDidConnect:(EAAccessory *)accessory;
- (void)accessoryDidDisconnect;
- (void)dataReceived:(NSDictionary *)data;

- (UIImage *)updateSignalStatus;

- (void)initLog;
- (void)writeLog;

@property (nonatomic, retain) IBOutlet UIView * loadingScreen;

Here's the Objective C code which stores the values in a dictionary:

//  This method gets called by the TGAccessoryManager when data is        received from the
//  ThinkGear-enabled device.
- (void)dataReceived:(NSDictionary *)data {
    [data retain];

    NSString * temp = [[NSString alloc] init];
    NSDate * date = [NSDate date];   

    // check to see whether the eSense values are there. if so, we assume that
    // all of the other data (aside from raw) is there. this is not necessarily
    // a safe assumption.
    if([data valueForKey:@"eSenseAttention"]){

       eSenseValues.attention =    [[data valueForKey:@"eSenseAttention"] intValue];
       eSenseValues.meditation =   [[data valueForKey:@"eSenseMeditation"] intValue];
        temp = [temp stringByAppendingFormat:@"%f: Attention: %d\n", [date timeIntervalSince1970], eSenseValues.attention];
        temp = [temp stringByAppendingFormat:@"%f: Meditation: %d\n", [date timeIntervalSince1970], eSenseValues.meditation];

        eegValues.delta =       [[data valueForKey:@"eegDelta"] intValue];
        eegValues.theta =       [[data valueForKey:@"eegTheta"] intValue];
        eegValues.lowAlpha =    [[data valueForKey:@"eegLowAlpha"] intValue];
        eegValues.highAlpha =   [[data valueForKey:@"eegHighAlpha"] intValue];
        eegValues.lowBeta =     [[data valueForKey:@"eegLowBeta"] intValue];
        eegValues.highBeta =    [[data valueForKey:@"eegHighBeta"] intValue];
        eegValues.lowGamma =    [[data valueForKey:@"eegLowGamma"] intValue];
        eegValues.highGamma =   [[data valueForKey:@"eegHighGamma"] intValue];

    }

    if(logEnabled) {
        [output release];
        output = [[NSString stringWithString:temp] retain];
        [self performSelectorOnMainThread:@selector(writeLog) withObject:nil waitUntilDone:NO];        
    }

    //[temp release];

    // release the parameter
    [data release];
}

Whenever I try to get any of these values I get "Use of unresolved identifier" or similar error. I am trying to display them as 3D text in SceneKit:

    override func viewDidLoad() {
    super.viewDidLoad()


    // Create Scene
    let scene = SCNScene()


    let myText = SCNText(string: attention , extrusionDepth: 5)
    myText.font = UIFont(name: "Optima", size: 1)
    let myTextNode = SCNNode(geometry: myText)
    myTextNode.position = SCNVector3(x: -2, y: -1, z: -7)
    myTextNode.orientation = SCNQuaternion(x: 0.1, y: 0, z: 0.5, w: 0)
    scene.rootNode.addChildNode(myTextNode)



}

I'm very new to IOS development and have been working on how to do this for nearly a week now. Any clues on being able to access the values would be very much appreciated.

ChloeS
  • 3
  • 3
  • Post your swift code where you are trying to access the values – dan Mar 16 '16 at 17:37
  • What is `eegValues`? And, as @dan mentioned, post the code that's actually giving the compile time error. Or is the error being generated in this Objective-C code? – David Berry Mar 16 '16 at 17:41
  • Edit the code into your question – dan Mar 16 '16 at 17:48
  • @DavidBerry the error is in the Swift file when I am trying to access the values from the Objective C file. – ChloeS Mar 16 '16 at 18:01

0 Answers0