Skip to content

Commit

Permalink
Fix issue #8: Status display shows ELM status in bluetooth ONLINE mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fr3ts0n committed Sep 22, 2015
1 parent f966d30 commit f1948dd
Showing 1 changed file with 43 additions and 10 deletions.
53 changes: 43 additions & 10 deletions src/com/fr3ts0n/ecu/gui/androbd/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@

import org.apache.log4j.Level;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.io.File;
import java.io.InputStream;
import java.util.Arrays;
Expand All @@ -69,7 +71,7 @@
* Main Activity for AndrOBD app
*/
public class MainActivity extends ListActivity
implements PvChangeListener, AdapterView.OnItemLongClickListener
implements PvChangeListener, AdapterView.OnItemLongClickListener, PropertyChangeListener
{
/** Key names received from the BluetoothChatService Handler */
public static final String DEVICE_NAME = "device_name";
Expand All @@ -84,6 +86,7 @@ public class MainActivity extends ListActivity
public static final int MESSAGE_TOAST = 5;
public static final int MESSAGE_DATA_ITEMS_CHANGED = 6;
public static final int MESSAGE_UPDATE_VIEW = 7;
public static final int MESSAGE_OBD_STATE_CHANGED = 8;
private static final String TAG = "AndrOBD";
/** internal Intent request codes */
private static final int REQUEST_CONNECT_DEVICE_SECURE = 1;
Expand Down Expand Up @@ -175,6 +178,7 @@ public void setMode(MODE mode)
}
// set new mode
this.mode = mode;
setStatus(mode.toString());
}
}

Expand Down Expand Up @@ -220,6 +224,7 @@ public void handleMessage(Message msg)
break;
}
break;

case MESSAGE_WRITE:
break;

Expand Down Expand Up @@ -273,6 +278,16 @@ public void handleMessage(Message msg)
getListView().invalidateViews();
break;

case MESSAGE_OBD_STATE_CHANGED:
/* Show ELM status only in ONLINE mode */
if(getMode() != MODE.DEMO)
{
PropertyChangeEvent evt = (PropertyChangeEvent)msg.obj;
setStatus(evt.getNewValue().toString());
}
break;


}
}
};
Expand Down Expand Up @@ -337,13 +352,16 @@ protected void onCreate(Bundle savedInstanceState)
mVidAdapter = new VidItemAdapter(this, R.layout.obd_item, ObdProt.VidPvs);
mDfcAdapter = new DfcItemAdapter(this, R.layout.obd_item, ObdProt.tCodes);
currDataAdapter = mPidAdapter;

// load csv files for protocol extensions
loadPreferredExtensions();

// create file helper instance
fileHelper = new FileHelper(this, mCommService.elm);
// set listeners for data structure changes
setDataListeners();
// automate elm status display
mCommService.elm.addPropertyChangeListener(this);

// Get local Bluetooth adapter
mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Expand Down Expand Up @@ -381,8 +399,8 @@ private void setDataListeners()
| PvChangeEvent.PV_CLEARED
);
ObdProt.VidPvs.addPvChangeListener(this,
PvChangeEvent.PV_ADDED
| PvChangeEvent.PV_CLEARED
PvChangeEvent.PV_ADDED
| PvChangeEvent.PV_CLEARED
);
ObdProt.tCodes.addPvChangeListener(this,
PvChangeEvent.PV_ADDED
Expand Down Expand Up @@ -469,7 +487,6 @@ private void setFiltered(boolean filtered)
public boolean onOptionsItemSelected(MenuItem item)
{
// Handle presses on the action bar items
Intent serverIntent;
updateTimer.purge();

switch (item.getItemId())
Expand Down Expand Up @@ -634,9 +651,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data)
// When the request to enable Bluetooth returns
if (resultCode == Activity.RESULT_OK)
{
// Launch the DeviceListActivity to see devices and do scan
Intent serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_SECURE);
// Start online mode
setMode(MODE.ONLINE);
} else
{
// Start demo service Thread
Expand Down Expand Up @@ -824,9 +840,9 @@ public void onListItemClick(ListView l, View v, int position, long id)
super.onListItemClick(l, v, position, id);
// enable graphic actions only on DATA service if min 1 item selected
setMenuItemEnable(R.id.graph_actions,
((mCommService.elm.getService() == ObdProt.OBD_SVC_DATA)
&& (getListView().getCheckedItemCount() > 0)
)
((mCommService.elm.getService() == ObdProt.OBD_SVC_DATA)
&& (getListView().getCheckedItemCount() > 0)
)
);
}

Expand Down Expand Up @@ -1051,6 +1067,23 @@ public synchronized void pvChanged(PvChangeEvent event)
mHandler.sendMessage(msg);
}

/**
* Property change listener to ELM-Protocol
*
* @param evt the property change event to be handled
*/
public void propertyChange(PropertyChangeEvent evt)
{
/* handle protocol status changes */
if (evt.getPropertyName().equals("status"))
{
// forward property change to the UI Activity
Message msg = mHandler.obtainMessage(MainActivity.MESSAGE_OBD_STATE_CHANGED);
msg.obj = evt;
mHandler.sendMessage(msg);
}
}

/**
* clear OBD fault codes after a warning
* confirmation dialog is shown and the operation is confirmed
Expand Down

0 comments on commit f1948dd

Please sign in to comment.