How to start method when a value of a global variable changes?

Sorry for not having any code in my question! I want to implement a program where i want to start gyroscope updates when the accelerometer x axis reading exceeds a certain threshold value. When gyroscope is activated i need to stop accelerometer updates as well. The way , i planed is to take accelerometer data to a global variable and then compare it with the an if condition. if it satisfies the condition i need to send the signal to start gyro update and stop accel update?

I can implement code about accel and gyro updates but the problem is i have no idea how to start gyro data n stop accel data when the value of global variable exceeds the threshold value? Please help me!

Answers


you can use getter and setter to change variable. in setter you can check any condition you want. then you just can, for example, post notification about reaching needed threshold.

- (void) setNeededValue:(valueType)newValue;
{
    neededValue = newValue;

    if( neededValue > threshold )
    {
        [[NSNotificationCenter defaultCenter] postNotificationName: someConstStringAsNotificationName object: self];
    }
}

to receive notification use this code in any class you want to receive it by calling

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationHandler) name:someConstStringAsNotificationName object:nil];

Sounds good to me, you just need to try it out. Pseudo:

if ( globalVariable > thresholdValue ) {
    stopAccelData();
    startGyroData();
}

Need Your Help

CDN/sub-domain, resources, and versioning

asp.net-mvc image versioning cdn

I’m hoping to investigate/implement a CDN (initially just via a sub-domain, though moving over to CDN in time) and am having a mare finding resources that talk about handling of versions of files o...

Splash screen coming in inverted way?

ios objective-c splash-screen

When i created App the launch image was correct and now its almost a month but when i run the app in device and simulator the splash screen is just inverted!!! i don't know why ???