Search in sources :

Example 1 with Conversion

use of com.fr3ts0n.ecu.Conversion 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;
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) NumericConversion(com.fr3ts0n.ecu.NumericConversion) TextView(android.widget.TextView) ProgressBar(android.widget.ProgressBar) NumericConversion(com.fr3ts0n.ecu.NumericConversion) Conversion(com.fr3ts0n.ecu.Conversion)

Example 2 with Conversion

use of com.fr3ts0n.ecu.Conversion in project AndrOBD by fr3ts0n.

the class ObdItemTableRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    String fmtText = null;
    // if we don't know the parent table yet, set visual parameters
    if (parentTable == null)
        setParentTable(table);
    // background is dependent on selection status
    setBackground(isSelected ? selColor : bgColor);
    // if row is valid ...
    if (value != null) {
        // get column value
        Object colVal = ((EcuDataPv) value).get(column);
        if (colVal != null) {
            try {
                // formatting is based on column ...
                switch(column) {
                    case EcuDataPv.FID_PID:
                        setHorizontalAlignment(RIGHT);
                        fmtText = String.format("%02X", colVal);
                        break;
                    case EcuDataPv.FID_OFS:
                        setHorizontalAlignment(RIGHT);
                        fmtText = String.valueOf(colVal);
                        break;
                    case EcuDataPv.FID_VALUE:
                    case EcuDataPv.FID_UNITS:
                        EcuDataPv currPv = (EcuDataPv) value;
                        Object cnvObj = currPv.get(EcuDataPv.FID_CNVID);
                        if (cnvObj != null && cnvObj instanceof Conversion[] && ((Conversion[]) cnvObj)[EcuDataItem.cnvSystem] != null) {
                            Conversion cnv;
                            cnv = ((Conversion[]) cnvObj)[EcuDataItem.cnvSystem];
                            if (column == EcuDataPv.FID_VALUE) {
                                setHorizontalAlignment(RIGHT);
                                // formated data
                                fmtText = cnv.physToPhysFmtString((Number) colVal, (String) currPv.get(EcuDataPv.FID_FORMAT));
                            } else {
                                setHorizontalAlignment(LEFT);
                                // formated units
                                fmtText = cnv.getUnits();
                            }
                        } else {
                            fmtText = String.valueOf(colVal);
                        }
                        break;
                    default:
                        setHorizontalAlignment(LEFT);
                        fmtText = String.valueOf(colVal);
                        break;
                }
            } catch (Exception ex) {
                fmtText = String.valueOf(colVal);
            }
        }
    }
    setText(fmtText);
    return this;
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) Conversion(com.fr3ts0n.ecu.Conversion)

Example 3 with Conversion

use of com.fr3ts0n.ecu.Conversion in project AndrOBD by fr3ts0n.

the class ObdProt method preparePidPvs.

/**
 * prepare process variables for each PID
 * @param pvList list of process vars
 */
public void preparePidPvs(int obdService, PvList pvList) {
    // reset fixed PIDs
    resetFixedPid();
    HashMap<String, EcuDataPv> newList = new HashMap<String, EcuDataPv>();
    for (Integer currPid : pidSupported) {
        Vector<EcuDataItem> items = dataItems.getPidDataItems(obdService, currPid);
        // if no items defined, create dummy item
        if (items == null) {
            log.warning(String.format("unknown PID %02X", currPid));
            // create new dummy item / OneToOne conversion
            Conversion[] dummyCnvs = { EcuConversions.dfltCnv, EcuConversions.dfltCnv };
            EcuDataItem newItem = new EcuDataItem(currPid, 0, 0, 0, 32, 0xFFFFFFFF, dummyCnvs, "%#08x", null, null, String.format("PID %02X", currPid), String.format("PID_%02X", currPid));
            dataItems.appendItemToService(obdService, newItem);
            // re-load data items for this PID
            items = dataItems.getPidDataItems(obdService, currPid);
        }
        // loop through all items found ...
        for (EcuDataItem pidPv : items) {
            if (pidPv != null) {
                newList.put(pidPv.toString(), pidPv.pv);
            }
        }
    }
    pvList.putAll(newList, PvChangeEvent.PV_ADDED, false);
}
Also used : EcuDataPv(com.fr3ts0n.ecu.EcuDataPv) HashMap(java.util.HashMap) Conversion(com.fr3ts0n.ecu.Conversion) EcuDataItem(com.fr3ts0n.ecu.EcuDataItem)

Aggregations

Conversion (com.fr3ts0n.ecu.Conversion)3 EcuDataPv (com.fr3ts0n.ecu.EcuDataPv)3 ProgressBar (android.widget.ProgressBar)1 TextView (android.widget.TextView)1 EcuDataItem (com.fr3ts0n.ecu.EcuDataItem)1 NumericConversion (com.fr3ts0n.ecu.NumericConversion)1 HashMap (java.util.HashMap)1