ALS sensor reading

Discussion in 'iOS Programming' started by DennisBlah, Feb 23, 2014.

  1. DennisBlah, Feb 23, 2014
    Last edited: Feb 24, 2014

    DennisBlah macrumors 6502


    Dec 5, 2013
    The Netherlands
    Is anyone around here, working with the IOKit library?
    I'm following this :
    And it keeps crashing and crashing.

    With this code underneath, I'm able to read out the 'PrimaryUsage and the PrimaryUsagePage', and also the backlight level and more.
    But this issnt exactly what I'm looking for. Backlight level I already read out by brightness, thats just basicly the same but only works if I lock the screen, block the sensors and open back up the app.
    CFMutableDictionaryRef matching , properties = NULL;
        io_registry_entry_t entry = 0;
        matching = IOServiceMatching( "AppleEmbeddedI2CLightSensor" );
        //matching = IOServiceNameMatching( "AppleSmartBattery" );
        entry = IOServiceGetMatchingService( kIOMasterPortDefault , matching );
        IORegistryEntryCreateCFProperties( entry , &properties , NULL , 0 );
        NSLog( @"%@" , properties );
        [logs setText: [NSString stringWithFormat: @"%@", properties]];
        CFRelease( properties );
        IOObjectRelease( entry );
    I would like to read out the lux level itself from the sensor. But I cant find any way to acomplish this.

    BTW I'm doing the [logs setText:, because the app will crash once I'm calling the IOKit Library, so I cant log from xcode itself, thats just a bit of weird...

    I hope someone can help me out
  2. DennisBlah thread starter macrumors 6502


    Dec 5, 2013
    The Netherlands
    Even with only this part it crashes out
    >> IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL); <<
        IOHIDEventSystemRef system = IOHIDEventSystemCreate(NULL);
    //    IOHIDEventSystemOpen(system, handle_event, NULL, NULL, NULL);
    //    IOHIDEventSystemClose(system, NULL);
    void handle_event (void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) {
        tempLogs = [NSString stringWithFormat: @"%@\nReceived event of type %2d from service %p.\n", tempLogs, IOHIDEventGetType(event), service];
  3. ianray macrumors 6502

    Jun 22, 2010
    Is system NULL?

    What version of iOS?

    Where did you get the headers?

    What are you linking against? (Or what are you dlopen'ing?)
  4. DennisBlah thread starter macrumors 6502


    Dec 5, 2013
    The Netherlands
    I'm working on iOS7, and I'm using the IOKit libraries.
    These are correct ones as I can gather raw battery information and stuff with it.

    I'm building an functional test app for iphones for the company.
    For now I wrote an cheap work around by getting the background brightness, but the 'testers' must lock the device, cover the sensor, and unlock the device and get back in the app and uncover the sensor again and watch the brightness slider move back to original state.

    I would like to have an 'live' result of the sensor itself. But after few weeks of playing around it just wont work.

    I had loads examples, also one from this forum but they are not working. This one came as close as possible. I can't find the webpage anymore about this example.

Share This Page