@Override protected void onResume() { super.onResume(); // initialize our preferences tempUomPref = Integer.parseInt(prefs.getString("prefs_uom_temp", "1")); afrNotEqualTargetPref = prefs.getBoolean("prefs_afrnottarget_pref", false); afrNotEqualTargetTolerance = prefs.getFloat("prefs_afrnottarget_tolerance_pref", 5f); waterTempPref = prefs.getBoolean("prefs_watertemp_pref", false); remoteName = prefs.getString("prefs_remote_name", ""); remoteMacAddr = prefs.getString("prefs_remote_mac", ""); autoConnect = prefs.getBoolean("prefs_auto_connect", false); // need to set gauge scale based on uom selected switch (tempUomPref) { case 0: minimumWaterTemp = prefs.getFloat("prefs_min_water_temp", AdaptivePreferences.MIN_WATER_TEMP_CELCIUS); maximumWaterTemp = prefs.getFloat("prefs_max_water_temp", AdaptivePreferences.MAX_WATER_TEMP_CELCIUS); iatNeedle.setPivotPoint(.5f); iatNeedle.setMinValue(0); iatNeedle.setMaxValue(100); iatNeedle.setMinDegrees(-180); iatNeedle.setMaxDegrees(90); imgIat.setImageResource(R.drawable.iatgauge_celcius); break; case 1: minimumWaterTemp = prefs.getFloat("prefs_min_water_temp", AdaptivePreferences.MIN_WATER_TEMP_FAHRENHEIT); maximumWaterTemp = prefs.getFloat("prefs_max_water_temp", AdaptivePreferences.MAX_WATER_TEMP_FAHRENHEIT); iatNeedle.setPivotPoint(.5f); iatNeedle.setMinValue(0); iatNeedle.setMaxValue(200); iatNeedle.setMinDegrees(-180); iatNeedle.setMaxDegrees(90); imgIat.setImageResource(R.drawable.iatgauge); break; } afrAlarmLogging = prefs.getBoolean("prefs_afr_alarm_logging", false); if (menuShareLog != null) { menuShareLog.setVisible(afrAlarmLogging && !afrAlarmLogItems.getItems().isEmpty()); } // ensure both fragments are hidden FragmentTransaction ft = getFragmentManager().beginTransaction(); ft.hide(adaptiveFragment); ft.hide(gaugesFragment); ft.hide(fuelFragment); ft.commit(); ActionBar bar = getActionBar(); bar.selectTab(bar.getTabAt(prefs.getInt("prefs_last_tab", 1))); // EVAN String action = getIntent().getAction(); if (Intent.ACTION_MAIN.equals(action) || UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action)) { if (DEBUG_MODE) Log.d(TAG, "USB Device Attached"); connected = UsbConnectedThread.checkConnectedUsbDevice(this, connectionHandler); if (connected != null) { lastUpdateInMillis = System.currentTimeMillis(); } } // END EVAN if (connected != null && connected.isAlive()) { refreshHandler.postDelayed(RefreshRunnable, LONG_PAUSE); } else { if (autoConnect && remoteMacAddr.length() > 0) { disconnect(); new Handler() .postDelayed( (new Runnable() { public void run() { connect(remoteName, remoteMacAddr); } }), 1000); // connect(remoteName, remoteMacAddr); } } }
private static void process4096Response(final String data) { final String[] buf = data.substring(data.indexOf(EIGHT_REGISTERS), data.length()).split(" "); if (ModbusRTU.validCRC(buf, REGISTER_4096_LENGTH)) { imgStatus.setBackgroundColor(Color.GREEN); dataArray.clear(); final int rpm = Integer.parseInt(buf[3] + buf[4], 16); final int map = Integer.parseInt(buf[5] + buf[6], 16); final int mat = getTemperatureValue(buf[7] + buf[8]); final int wat = getTemperatureValue(buf[9] + buf[10]); final float afr = Integer.parseInt(buf[14], 16) / 10f; final float referenceAfr = Integer.parseInt(buf[13], 16) / 10f; tps = Integer.parseInt(buf[17] + buf[18], 16); iatNeedle.setValue(mat); waterNeedle.setValue(Integer.parseInt(buf[9] + buf[10], 16) * 9 / 5 + 32); mapNeedle.setValue(map); { float afrVal = afr * 100; float targetAfrVal = targetAFR * 100; if (afrVal > AFR_MAX) afrVal = AFR_MAX; if (afrVal < AFR_MIN) afrVal = AFR_MIN; if (targetAfrVal > AFR_MAX) targetAfrVal = AFR_MAX; if (targetAfrVal < AFR_MIN) targetAfrVal = AFR_MIN; afrNeedle.setValue(AFR_MAX - afrVal + AFR_MIN); targetAfrNeedle.setValue(AFR_MAX - targetAfrVal + AFR_MIN); } if (rpm >= 200) lastRPM = rpm; dataArray.add(String.format("RPM\n%d", lastRPM)); rpmNeedle.setValue(lastRPM); dataArray.add(String.format("MAP\n%d kPa", map)); dataArray.add(String.format("MAT\n%d\u00B0 %s", mat, getTemperatureSymbol())); dataArray.add(String.format("AFR\n%.1f (%.1f)", afr, referenceAfr)); dataArray.add("TAFR\n" + (targetAFR != 0f ? String.format("%.1f", targetAFR) : "--.-")); dataArray.add(String.format("WAT\n%d\u00B0 %s", wat, getTemperatureSymbol())); // alarm stuff if (gridData.getChildAt(3) != null && gridData.getChildAt(5) != null) { // water temperature gridData.getChildAt(5).setBackgroundColor(Color.TRANSPARENT); if (waterTempPref) { if (wat < minimumWaterTemp) gridData.getChildAt(5).setBackgroundColor(Color.BLUE); if (wat > maximumWaterTemp) gridData.getChildAt(5).setBackgroundColor(Color.RED); } // afr vs target alarm gridData.getChildAt(3).setBackgroundColor(Color.TRANSPARENT); if (afrNotEqualTargetPref) { final float threshold = targetAFR * (afrNotEqualTargetTolerance * .01f); if (Math.abs(targetAFR - afr) >= threshold) { if (afr > targetAFR) { gridData.getChildAt(3).setBackgroundColor(Color.RED); } else { gridData.getChildAt(3).setBackgroundColor(Color.BLUE); } if (afrAlarmLogging) { LogItem newItem = afrAlarmLogItems.newLogItem(); newItem.setAfr(afr); newItem.setReferenceAfr(referenceAfr); newItem.setMap(map); newItem.setMat(mat); newItem.setRpm(rpm); newItem.setTargetAfr(targetAFR); newItem.setWat(wat); afrAlarmLogItems.getItems().add(newItem); if (!menuShareLog.isVisible()) { menuShareLog.setVisible(true); } } } } } if (DEBUG_MODE) Log.d(TAG, "Processed " + lastRegister + " response: " + data); sendRequest(REGISTER_4140_PLUS_SIX); return; } else { if (DEBUG_MODE) Log.d(TAG, "bad CRC for " + lastRegister + ": " + data); imgStatus.setBackgroundColor(Color.RED); sendRequest(); } }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ctx = this; prefs = PreferenceManager.getDefaultSharedPreferences(ctx); adaptiveFragment = getFragmentManager().findFragmentById(R.id.frag_adaptive); gaugesFragment = getFragmentManager().findFragmentById(R.id.frag_gauges); fuelFragment = getFragmentManager().findFragmentById(R.id.frag_fuel); ActionBar bar = getActionBar(); bar.addTab(bar.newTab().setText(R.string.tab_adaptive).setTabListener(this), false); bar.addTab(bar.newTab().setText(R.string.tab_gauges).setTabListener(this), false); bar.addTab(bar.newTab().setText("Fuel Map").setTabListener(this), false); mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null); bar.setCustomView(mActionBarView); bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_USE_LOGO); bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); bar.setDisplayShowHomeEnabled(true); txtData = (TextView) findViewById(R.id.txtData); lvDevices = (ListView) findViewById(R.id.lvDevices); layoutDevices = (RelativeLayout) findViewById(R.id.layoutDevices); imgStatus = (ImageView) findViewById(R.id.imgStatus); txtFuelLearn = (TextView) findViewById(R.id.fuellearn); imgIWait = (ImageView) findViewById(R.id.imgIWait); imgIRpm = (ImageView) findViewById(R.id.imgIRpm); imgILoad = (ImageView) findViewById(R.id.imgILoad); imgFWait = (ImageView) findViewById(R.id.imgFWait); imgFRpm = (ImageView) findViewById(R.id.imgFRpm); imgFLoad = (ImageView) findViewById(R.id.imgFLoad); imgIat = (ImageView) findViewById(R.id.iat); gridData = (GridView) findViewById(R.id.gridData); dataArray = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1); dataArray.add("RPM\n ----"); dataArray.add("MAP\n ---"); dataArray.add("MAT\n ---\u00B0"); dataArray.add("AFR\n --.-"); dataArray.add("TAFR\n --.-"); dataArray.add("WAT\n ---\u00B0"); gridData.setAdapter(dataArray); lvDevices.setOnItemClickListener(DevicesClickListener); waterNeedle = (GaugeNeedle) findViewById(R.id.waterneedle); iatNeedle = (GaugeNeedle) findViewById(R.id.iatneedle); mapNeedle = (GaugeNeedle) findViewById(R.id.mapneedle); afrNeedle = (GaugeNeedle) findViewById(R.id.afrneedle); targetAfrNeedle = (GaugeNeedle) findViewById(R.id.targetafrneedle); rpmNeedle = (GaugeNeedle) findViewById(R.id.rpmneedle); waterNeedle.setPivotPoint(.65f); waterNeedle.setMinValue(100); waterNeedle.setMaxValue(240); waterNeedle.setMinDegrees(-50); waterNeedle.setMaxDegrees(55); afrNeedle.setPivotPoint(.5f); afrNeedle.setMinValue(AFR_MIN); afrNeedle.setMaxValue(AFR_MAX); afrNeedle.setMinDegrees(-180); afrNeedle.setMaxDegrees(90); targetAfrNeedle.setPivotPoint(.5f); targetAfrNeedle.setMinValue(AFR_MIN); targetAfrNeedle.setMaxValue(AFR_MAX); targetAfrNeedle.setMinDegrees(-180); targetAfrNeedle.setMaxDegrees(90); mapNeedle.setPivotPoint(.5f); mapNeedle.setMinValue(0); mapNeedle.setMaxValue(200); mapNeedle.setMinDegrees(-150); mapNeedle.setMaxDegrees(140); rpmNeedle.setPivotPoint(.5f); rpmNeedle.setMinValue(0); rpmNeedle.setMaxValue(9000); rpmNeedle.setMinDegrees(-130); rpmNeedle.setMaxDegrees(157); ChangeLog cl = new ChangeLog(this); if (cl.firstRun()) { cl.getLogDialog().show(); } LinearLayout group = (LinearLayout) findViewById(R.id.linearLayoutTchart); chart = new TChart(this); chart.setAutoRepaint(false); group.addView(chart); ThemesList.applyTheme(chart.getChart(), 1); chart.removeAllSeries(); ser = new Surface(chart.getChart()); chart.getAspect().setView3D(true); ser.setIrregularGrid(true); ser.setUseColorRange(false); ser.setUsePalette(true); ser.setPaletteStyle(PaletteStyle.RAINBOW); chart.getPanel().setBorderRound(7); chart.getAspect().setView3D(true); chart.getAspect().setChart3DPercent(100); chart.getAspect().setOrthogonal(false); chart.getAspect().setZoom(75); chart.getAspect().setRotation(350); chart.getAspect().setElevation(350); chart.getAspect().setPerspective(37); chart.getAxes().getDepth().setVisible(true); chart.getLegend().setVisible(false); chart.getHeader().setText("Fuel Map #1 (VE)"); chart.getHeader().getFont().setSize(18); chart.getHeader().getFont().setBold(true); ser.setColor(com.steema.teechart.drawing.Color.darkGray); new Rotate(chart.getChart()); // EVAN mUsbDetachedFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED); registerReceiver(mUsbReceiver, mUsbDetachedFilter); // END EVAN }