FuzzyLuke / OBD2Kit

OBD-2 library for iPhone
218 stars 57 forks source link

Can't get any other PID except 0x0C and 0x0D #1

Closed 1umpus closed 11 years ago

1umpus commented 11 years ago

Hi,

I'm trying to get other PID's in my app, however all that I'm getting 0x0C and 0x0D. I want 0x2F, 0x0A, and 0x11. Here is the code that I'm trying to use:

- (void)scanTool:(FLScanTool*)scanTool didReceiveResponse:(NSArray*)responses {
    FLINFO(@"DID RECEIVE RESPONSE")

    FLECUSensor* sensor =   nil;

    for (FLScanToolResponse* response in responses) {

        sensor          = [FLECUSensor sensorForPID:response.pid];
        [sensor setCurrentResponse:response];
        PID.text = [NSString stringWithFormat:@"%lu", (unsigned long)response.pid];
        if (response.pid == 0x0C) {
            // Update RPM Display
            rpmLabel.text   = [NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]];
            [rpmLabel setNeedsDisplay];
        }
        else if(response.pid == 0x2F){
            NSLog(@"Fuel level at: %@",[NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]] );
            fuelLevel.text = [NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]];
            [fuelLevel setNeedsDisplay];
        }
        else if(response.pid == 0x0A){
            NSLog(@"Fuel pressure: %@", [NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]]);

        }
        else if(response.pid == 0x11){

            NSLog(@"Throttle Position: %@", [NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]]);
            TPS.text = [NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]];
            [TPS setNeedsDisplay];
        }
        else if(response.pid == 0x0D) {
            // Update Speed Display
            speedLabel.text = [NSString stringWithFormat:@"%@ %@", [sensor valueStringForMeasurement1:NO], [sensor imperialUnitString]];

            [speedLabel setNeedsDisplay];
        }else{

        }

    }

}

What am I doing wrong? I tried printing the value for the PID to a label and all I'm getting is 12 and 13 when I push the gas pedal. I'm driving a Lexus RX400h with a very temperamental brain that likes to control the RPM speed and fuel consumption itself. Is my car the problem?

1umpus commented 11 years ago

Forgot to mention that I'm using an ELM327 OBD-II Wifi Key.

1umpus commented 11 years ago

Never mind, I fixed it. Here's how:

- (void)scanToolDidInitialize:(FLScanTool*)scanTool {
    FLINFO(@"SCANTOOL INITIALIZATION COMPLETE")
    FLDEBUG(@"scanTool.scanToolState: %08X", scanTool.scanToolState)
    FLDEBUG(@"scanTool.supportedSensors count: %d", [scanTool.supportedSensors count])

    statusLabel.text            = @"Scanning...";

    [_scanTool setSensorScanTargets:[NSArray arrayWithObjects:
                                     [NSNumber numberWithInt:0x0C], // Engine RPM
                                     [NSNumber numberWithInt:0x0D], // Vehicle Speed
                                     [NSNumber numberWithInt:0x2F], // Vehicle Fuel Level
                                     [NSNumber numberWithInt:0x11], // Vehicle Throttle Position
                                     [NSNumber numberWithInt:0x0A], // Vehicle Fuel Pressure
                                     [NSNumber numberWithInt:0x010],// Mass Air Flow Rate (MAF)
                                     nil]];

    scanToolNameLabel.text  = _scanTool.scanToolName;
}

Just add all of the PID's you'd like by appending to the setSensorScanTargets: array using [NSNumber numberWithInt:].