I would like to share my script for users of Torque https://play.google.com/store/apps/details?id=org.prowl.torque
This script allows reading any PIDs from Torque service, for latter use in bindings.
Set it to be run on desktop load.
It will set the following variables:
tq_live – boolean – whether we are connected to Torque service
tq_ecu – boolean – whether Torque is connected to Engine ECU
tq_version – integer – the version of Torque
tq_xxx – float – the value of pid, where xxx is a name of pid as configured at the top of script, you may configure multiple PIDs; see below
— cut —
var refreshInterval = 200;
var pids = [
{pid: 0xff1001, name: “gps_speed”},
{pid: 0xff123A, name: “gps_locked”},
{pid: 0x0c, name: “rpm”},
{pid: 0x42, name: “voltage”}
];
LL.bindClass(“android.os.Parcel”);
LL.bindClass(“android.content.ServiceConnection”);
var binder = null;
var timer = null;
function callSvc(code, fp, fr, def) {
if (binder == null) return def;
var p = Parcel.obtain();
var r = Parcel.obtain();
try {
p.writeInterfaceToken(“org.prowl.torque.remote.ITorqueService”);
if (fp != null) fp(p);
binder.transact(code, p, r, 0);
return r.readExceptionCode() == 0 && (fr != null) ? fr(r) : def;
}
catch (err) {
return def;
}
finally {
r.recycle();
p.recycle();
}
}
// int getVersion()
function getVersion() { return callSvc(
1,
null,
function(r) { return r.readInt(); },
0
); }
// float getValueForPid(long pid, boolean triggersDataRefresh);
function getValueForPid(pid, refresh) { return callSvc(
2,
function(p) { p.writeLong(pid); p.writeByte(refresh ? 1 : 0); },
function(r) { return r.readFloat(); },
0
); }
// boolean isConnectedToECU();
function isConnectedToECU() { return callSvc(
15,
null,
function(r) { return r.readByte() != 0; },
false
); }
function reset() {
var v = LL.getVariables().edit();
v.setBoolean(“tq_live”, false);
v.setBoolean(“tq_ecu”, false);
v.setInteger(“tq_version”, 0);
for(var i = 0; i < pids.length; i++)
v.setFloat(“tq_” + pids[i].name, 0);
v.commit();
}
function refresh() {
if (binder == null) return;
var v = LL.getVariables().edit();
v.setBoolean(“tq_ecu”, isConnectedToECU());
for(var i = 0; i < pids.length; i++)
v.setFloat(“tq_” + pids[i].name, getValueForPid(pids[i].pid, true));
v.commit();
timer = setTimeout(refresh, refreshInterval);
}
var conn = new ServiceConnection({
onServiceConnected: function (n, b) {
binder = b;
var v = LL.getVariables().edit();
v.setBoolean(“tq_live”, true);
v.setInteger(“tq_version”, getVersion());
v.commit();
refresh();
},
onServiceDisconnected: function(n) {
binder = null;
reset();
}
});
reset();
var intent = new Intent();
intent.setClassName(“org.prowl.torque”, “org.prowl.torque.remote.TorqueService”);
var success = LL.getContext().bindService(intent, conn, 1);
— cut —
]]>
< ![CDATA[
Just added exception handling and made minor changes
]]>
< ![CDATA[
Thanks!
]]>
< ![CDATA[
Script updated: made PID read with refresh = true, as some PIDs (e.g. engine RPM) were not refreshed until Torque with that PID’s display is on top.
]]>
< ![CDATA[
Here’s some video of my LLX-powered Car Head Unit, where I added GPS speed and ECU voltage using this my script: https://youtu.be/xgL8oOJThV0
(the speed is all the time 0, because the car was steady)
]]>
< ![CDATA[
Dmitry Avsioukov very cool. I have to order a new obd-II sender. Mine “disappeared” while vehicle was in the shop.
]]>
< ![CDATA[
Dmitry Avsioukov I’ve seen awessome ui on you youtube. How did you handle weather? Using widget?
]]>
< ![CDATA[
Chris LEE, yes, it is Transparent Clock & Weather – just search on Google play store
]]>