use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.
the class DashBoardActivity method onResume.
/* (non-Javadoc)
* @see android.app.Activity#onResume()
*/
@Override
protected void onResume() {
EcuDataPv currPv;
super.onResume();
// set the desired content screen
int resId = getIntent().getIntExtra(RES_ID, R.layout.dashboard);
setContentView(resId);
// calculate minimum gauge size (1.6 inch) based on screen density
getWindowManager().getDefaultDisplay().getMetrics(metrics);
MIN_GAUGE_SIZE = Math.min(metrics.densityDpi * 16 / 10, Math.min(metrics.widthPixels, metrics.heightPixels));
int height = metrics.heightPixels;
int width = metrics.widthPixels;
int numColumns = Math.max(1, Math.min(positions.length, width / MIN_GAUGE_SIZE));
int numRows = Math.max(1, Math.min(positions.length, height / MIN_GAUGE_SIZE));
// distribute gauges on screen
if (positions.length < numColumns * numRows) {
// read for corresponding number of gauges & orientation
numColumns = rowCols[positions.length][(width > height) ? 0 : 1];
numRows = rowCols[positions.length][(width > height) ? 1 : 0];
}
// calc max gauge size
int minWidth = width / numColumns;
int minHeight = height / numRows;
/* get grid object */
grid = (GridView) findViewById(android.R.id.list);
grid.setNumColumns(numColumns);
// set data adapter
adapter = new ObdGaugeAdapter(this, R.layout.obd_gauge, minWidth, minHeight, metrics);
pidNumbers.clear();
for (int position : positions) {
// get corresponding Process variable
currPv = (EcuDataPv) mAdapter.getItem(position);
if (currPv != null) {
currPv.setRenderingComponent(null);
pidNumbers.add(currPv.getAsInt(EcuDataPv.FID_PID));
adapter.add(currPv);
}
}
grid.setAdapter(adapter);
// limit selected PIDs to selection
MainActivity.setFixedPids(pidNumbers);
// start display update task
try {
refreshTimer.schedule(updateTask, 0, 100);
} catch (Exception e) {
// exception ignored here ...
}
}
use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.
the class ObdItemAdapter method getView.
/*
* (non-Javadoc)
*
* @see android.widget.ArrayAdapter#getView(int, android.view.View,
* android.view.ViewGroup)
*/
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// get data PV
EcuDataPv currPv = (EcuDataPv) getItem(position);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.obd_item, parent, false);
}
// fill view fields with data
// description text
TextView tvDescr = (TextView) convertView.findViewById(R.id.obd_label);
tvDescr.setText(String.valueOf(currPv.get(EcuDataPv.FID_DESCRIPT)));
TextView tvValue = (TextView) convertView.findViewById(R.id.obd_value);
TextView tvUnits = (TextView) convertView.findViewById(R.id.obd_units);
ProgressBar pb = (ProgressBar) convertView.findViewById(R.id.bar);
// format value string
String fmtText;
Object colVal = currPv.get(EcuDataPv.FID_VALUE);
Object cnvObj = currPv.get(EcuDataPv.FID_CNVID);
Number min = (Number) currPv.get(EcuDataPv.FID_MIN);
Number max = (Number) currPv.get(EcuDataPv.FID_MAX);
int pid = currPv.getAsInt(EcuDataPv.FID_PID);
try {
if (cnvObj != null && cnvObj instanceof Conversion[] && ((Conversion[]) cnvObj)[EcuDataItem.cnvSystem] != null) {
Conversion cnv;
cnv = ((Conversion[]) cnvObj)[EcuDataItem.cnvSystem];
// set formatted text
fmtText = cnv.physToPhysFmtString((Number) colVal, (String) currPv.get(EcuDataPv.FID_FORMAT));
// set progress bar only on LinearConversion
if (min != null && max != null && cnv instanceof NumericConversion) {
pb.setVisibility(ProgressBar.VISIBLE);
pb.getProgressDrawable().setColorFilter(ChartActivity.getItemColor(pid), PorterDuff.Mode.SRC_IN);
pb.setProgress((int) (100 * ((((Number) colVal).doubleValue() - min.doubleValue()) / (max.doubleValue() - min.doubleValue()))));
} else {
pb.setVisibility(ProgressBar.GONE);
}
} else {
fmtText = String.valueOf(colVal);
}
} catch (Exception ex) {
fmtText = String.valueOf(colVal);
}
// set value
tvValue.setText(fmtText);
tvUnits.setText(currPv.getUnits());
return convertView;
}
use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.
the class ObdDataPanel method setPidPvs.
/**
* Setter for property pidPvs.
*
* @param pidPvs New value of property pidPvs.
*/
@SuppressWarnings("unchecked")
public void setPidPvs(PvList pidPvs) {
TimeSeries ts;
// if there is an o previous instance registered, unregister ...
if (this.pidPvs instanceof PvList)
this.pidPvs.removePvChangeListener(this);
this.pidPvs = pidPvs;
tblPids.setProcessVar(pidPvs);
tblPids.setDefaultRenderer(Object.class, new ObdItemTableRenderer());
pidPvs.addPvChangeListener(this);
// update all TimeSeries with PIDs from PV-List
plotter.dataset.removeAllSeries();
selPids.clear();
Iterator<EcuDataPv> it = pidPvs.values().iterator();
while (it.hasNext()) {
EcuDataPv pv = it.next();
// create new data series
ts = new TimeSeries(String.valueOf(pv.get(EcuDataPv.FID_DESCRIPT)));
ts.setDescription(String.valueOf(pv.get(EcuDataPv.FID_DESCRIPT)));
ts.setRangeDescription(String.valueOf(pv.get(EcuDataPv.FID_UNITS)));
// set graph time of new element
ts.setMaximumItemAge(slGraphTime.getValue() * 60);
// and add to selectable PID list
selPids.put(getPvId(pv), ts);
}
updateColumnWidths();
}
use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.
the class ObdDataPanel method valueChanged.
/**
* handle change in table selection
* activate / deactivate graphing of selected data items
*/
public void valueChanged(ListSelectionEvent e) {
TimeSeries ts;
int[] selIDs;
// clean up dataset
plotter.removeAllSeries();
// get selected items as list of data
// rather than array of ID's'
selIDs = tblPids.getSelectedRows();
for (int i = 0; i < selIDs.length; i++) {
/* since table model changed, it returns the complete object for any field */
EcuDataPv currPid = (EcuDataPv) tblPids.getModel().getValueAt(selIDs[i], EcuDataPv.FID_PID);
ts = selPids.get(currPid.get(EcuDataPv.FID_PID));
// if Series found
if (ts != null) {
// add new series to plotter ..
plotter.addSeries(ts);
}
}
}
use of com.fr3ts0n.ecu.EcuDataPv in project AndrOBD by fr3ts0n.
the class CanProt method preparePidPvs.
/**
* prepare process variables for each PID
*
* @param checkIfSupported if true, only supported PIDs will be processed
*/
public void preparePidPvs(boolean checkIfSupported) {
for (int i = 0; i < getMsgParameters().length; i++) {
Integer paramId = i;
/**
* enter process variables for each parameter
*/
EcuDataPv pidData = (EcuDataPv) CanPvs.get(paramId);
if (pidData != null) {
int convId = getMsgParameters()[i][FLD_ID_CONV];
pidData.put(EcuDataPv.FID_UNITS, Conversions.getUnits(convId));
}
}
}
Aggregations