SparkFun_CAN-Bus_Arduino_Library icon indicating copy to clipboard operation
SparkFun_CAN-Bus_Arduino_Library copied to clipboard

Add voltage and version ELM calls to the lib

Open ranknfyle opened this issue 2 years ago • 0 comments

This lib works fine for PID codes. But there are useful bits of info (voltage, version) that don't use PID codes, they use ELM327 commands. In another Arduino OBD library, I found the relevant calls (below). Can they be adapted and merged into the lib? I don't think I can adapt them myself.

float COBD::getVoltage()
{
    char buf[32];
	if (sendCommand("ATRV\r", buf, sizeof(buf)) > 0) {
		char* p = getResultValue(buf);
		if (p) return (float)atof(p);
    }
    return 0;
}

byte COBD::getVersion()
{
	byte version = 0;
	for (byte n = 0; n < 3; n++) {
		char buffer[32];
		if (sendCommand("ATI\r", buffer, sizeof(buffer), 200)) {
			char *p = strchr(buffer, ' ');
			if (p) {
				p += 2;
				version = (*p - '0') * 10 + (*(p + 2) - '0');
				break;
			}
		}
	}
	return version;
}

ranknfyle avatar Jan 29 '22 05:01 ranknfyle