Skip to content

Commit

Permalink
Merge pull request #236 from yoh-there/master
Browse files Browse the repository at this point in the history
Fields, Charging, Driving, Tyres
  • Loading branch information
yoh-there committed Nov 28, 2015
2 parents 018b6f5 + 1bdeaaa commit a5bb53b
Show file tree
Hide file tree
Showing 11 changed files with 547 additions and 91 deletions.
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
android:name=".activities.FluenceKangooTempsActivity"
android:label="Fluence Kangoo Temp" >
</activity>
<activity
android:name=".activities.TyresActivity"
android:label="@string/title_activity_tyres" >
</activity>
</application>

</manifest>
15 changes: 12 additions & 3 deletions app/src/main/java/lu/fisch/canze/activities/ChargingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ public class ChargingActivity extends CanzeActivity implements FieldListener {
public static final String SID_MaxCharge = "7bb.6101.336";
public static final String SID_SoC = "42e.0"; // user SOC, not raw
public static final String SID_AvChargingPower = "427.40";
public static final String SID_HvTemp = "42e.44";
public static final String SID_SOH = "658.33";
public static final String SID_RangeEstimate = "654.42";
public static final String SID_TractionBatteryVoltage = "7ec.623203.24";
public static final String SID_TractionBatteryCurrent = "7ec.623204.24";
double dcVolt = 0; // holds the DC voltage, so we can calculate the power when the amps come in

private ArrayList<Field> subscribedFields;
double avChPwr;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -98,6 +100,7 @@ private void initListeners() {

addListener(SID_MaxCharge);
addListener(SID_SoC);
addListener(SID_HvTemp);
if(MainActivity.car==MainActivity.CAR_ZOE) addListener(SID_AvChargingPower);
addListener(SID_SOH); // state of health gives continious timeouts. This frame is send at a very low rate
addListener(SID_RangeEstimate);
Expand All @@ -121,13 +124,19 @@ public void run() {
switch (fieldId) {

case SID_MaxCharge:
double maxCharge = field.getValue();
int color = 0xffc0c0c0; // standard grey
if (maxCharge < (avChPwr * 0.8)) {
color = 0xffffc0c0;
}
tv = (TextView) findViewById(R.id.text_max_charge);
tv.setBackgroundColor(color);
break;
case SID_SoC:
tv = (TextView) findViewById(R.id.textSOC);
break;
case SID_SOH:
tv = (TextView) findViewById(R.id.textSOH);
case SID_HvTemp:
tv = (TextView) findViewById(R.id.textHvTemp);
break;
case SID_RangeEstimate:
tv = (TextView) findViewById(R.id.textKMA);
Expand All @@ -153,7 +162,7 @@ public void run() {
tv = (TextView) findViewById(R.id.textAmps);
break;
case SID_AvChargingPower:
double avChPwr = field.getValue();
avChPwr = field.getValue();
tv = (TextView) findViewById(R.id.textAvChPwr);
break;
}
Expand Down
40 changes: 24 additions & 16 deletions app/src/main/java/lu/fisch/canze/activities/DrivingActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public class DrivingActivity extends CanzeActivity implements FieldListener {
// for ISO-TP optimization to work, group all identical CAN ID's together when calling addListener

// free data
public static final String SID_Consumption = "1fd.40"; //EVC
public static final String SID_Pedal = "186.40"; //EVC
public static final String SID_MeanEffectiveTorque = "186.16"; //EVC
public static final String SID_RealSpeed = "5d7.0"; //ESC-ABS
Expand All @@ -56,14 +57,15 @@ public class DrivingActivity extends CanzeActivity implements FieldListener {
public static final String SID_ElecBrakeWheelsTorqueApplied = "1f8.28"; //UBP 10ms

// ISO-TP data
// public static final String SID_EVC_SoC = "7ec.622002.24"; // (EVC)
public static final String SID_MaxCharge = "7bb.6101.336";
// public static final String SID_EVC_SoC = "7ec.622002.24"; // (EVC)
// public static final String SID_EVC_RealSpeed = "7ec.622003.24"; // (EVC)
public static final String SID_EVC_Odometer = "7ec.622006.24"; // (EVC)
// public static final String SID_EVC_Pedal = "7ec.62202e.24"; // (EVC)
public static final String SID_EVC_TractionBatteryVoltage = "7ec.623203.24"; // (EVC)
public static final String SID_EVC_TractionBatteryCurrent = "7ec.623204.24"; // (EVC)
// public static final String SID_EVC_TractionBatteryVoltage = "7ec.623203.24"; // (EVC)
// public static final String SID_EVC_TractionBatteryCurrent = "7ec.623204.24"; // (EVC)

private double dcVolt = 0; // holds the DC voltage, so we can calculate the power when the amps come in
// private double dcVolt = 0; // holds the DC voltage, so we can calculate the power when the amps come in
private int odo = 0;
private int destOdo = 0; // have to init from save file
private double realSpeed = 0;
Expand Down Expand Up @@ -155,7 +157,7 @@ private void saveDestOdo (int d) {
SharedPreferences settings = getSharedPreferences(MainActivity.PREFERENCES_FILE, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putInt("destOdo", d);
editor.commit();
editor.apply();
destOdo = d;
Field field = MainActivity.fields.getBySID(SID_RangeEstimate);
int distInBat = (int) field.getValue();
Expand Down Expand Up @@ -230,18 +232,20 @@ private void initListeners() {

// Make sure to add ISO-TP listeners grouped by ID

addListener(SID_Consumption, 0);
addListener(SID_Pedal, 0);
addListener(SID_MeanEffectiveTorque, 0);
addListener(SID_DriverBrakeWheel_Torque_Request, 0);
addListener(SID_ElecBrakeWheelsTorqueApplied, 0);
addListener(SID_RealSpeed, 0);
addListener(SID_SoC, 3600);
addListener(SID_RangeEstimate, 3600);
addListener(SID_MaxCharge,6000);

//addListener(SID_EVC_SoC);
addListener(SID_EVC_Odometer, 6000);
addListener(SID_EVC_TractionBatteryVoltage, 5000);
addListener(SID_EVC_TractionBatteryCurrent, 0);
//addListener(SID_EVC_TractionBatteryVoltage, 5000);
//addListener(SID_EVC_TractionBatteryCurrent, 0);
//addListener(SID_PEB_Torque);
}

Expand Down Expand Up @@ -279,6 +283,9 @@ public void run() {
//odo = (int) Utils.kmOrMiles(field.getValue());
tv = null;
break;
case SID_MaxCharge:
tv = (TextView) findViewById(R.id.text_max_charge);
break;
case SID_RealSpeed:
// case SID_EVC_RealSpeed:
//realSpeed = (Math.round(Utils.kmOrMiles(field.getValue()) * 10.0) / 10.0);
Expand All @@ -288,15 +295,16 @@ public void run() {
//case SID_PEB_Torque:
// tv = (TextView) findViewById(R.id.textTorque);
// break;
case SID_EVC_TractionBatteryVoltage: // DC volts
// save DC voltage for DC power purposes
dcVolt = field.getValue();
break;
case SID_EVC_TractionBatteryCurrent: // DC amps
// calculate DC power
double dcPwr = Math.round(dcVolt * field.getValue() / 100.0) / 10.0;
tv = (TextView) findViewById(R.id.textDcPwr);
tv.setText("" + (dcPwr));
// case SID_EVC_TractionBatteryVoltage: // DC volts
// // save DC voltage for DC power purposes
// dcVolt = field.getValue();
// break;
// case SID_EVC_TractionBatteryCurrent: // DC amps
// // calculate DC power
case SID_Consumption:
double dcPwr = field.getValue();
// tv = (TextView) findViewById(R.id.textDcPwr);
// tv.setText("" + (dcPwr));
tv = (TextView) findViewById(R.id.textConsumption);
if (realSpeed > 5) {
tv.setText("" + (Math.round(1000.0 * dcPwr / realSpeed) / 10.0));
Expand Down
162 changes: 162 additions & 0 deletions app/src/main/java/lu/fisch/canze/activities/TyresActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
/*
CanZE
Take a closer look at your ZE car
Copyright (C) 2015 - The CanZE Team
http://canze.fisch.lu
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or any
later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package lu.fisch.canze.activities;

import android.os.Bundle;
import android.widget.TextView;

import java.util.ArrayList;

import lu.fisch.canze.R;
import lu.fisch.canze.actors.Field;
import lu.fisch.canze.interfaces.FieldListener;

// If you want to monitor changes, you must add a FieldListener to the fields.
// For the simple activity, the easiest way is to implement it in the actitviy itself.
public class TyresActivity extends CanzeActivity implements FieldListener {

public static final String SID_TyreSpdPresMisadaption = "673.0";
public static final String SID_TyreFLState = "673.11";
public static final String SID_TyreFLPressure = "673.40";
public static final String SID_TyreFRState = "673.8";
public static final String SID_TyreFRPressure = "673.32";
public static final String SID_TyreRLState = "673.5";
public static final String SID_TyreRLPressure = "673.24";
public static final String SID_TyreRRState = "673.2";
public static final String SID_TyreRRPressure = "673.16";

private ArrayList<Field> subscribedFields;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_tyres);

initListeners();

}

private void addListener(String sid) {
Field field;
field = MainActivity.fields.getBySID(sid);
if (field != null) {
field.addListener(this);
MainActivity.device.addActivityField(field);
subscribedFields.add(field);
}
else
{
MainActivity.toast("sid " + sid + " does not exist in class Fields");
}

}

@Override
protected void onDestroy() {
super.onDestroy();

// free up the listeners again
for(Field field : subscribedFields)
{
field.removeListener(this);
}
subscribedFields.clear();
}

@Override
protected void onResume() {
super.onResume();

// initialise the widgets
initListeners();
}

private void initListeners() {

subscribedFields = new ArrayList<>();

addListener(SID_TyreSpdPresMisadaption);
addListener(SID_TyreFLState);
addListener(SID_TyreFLPressure);
addListener(SID_TyreFRState);
addListener(SID_TyreFRPressure);
addListener(SID_TyreRLState);
addListener(SID_TyreRLPressure);
addListener(SID_TyreRRState);
addListener(SID_TyreRRPressure);
}

// This is the event fired as soon as this the registered fields are
// getting updated by the corresponding reader class.
@Override
public void onFieldUpdateEvent(final Field field) {
// the update has to be done in a separate thread
// otherwise the UI will not be repainted
runOnUiThread(new Runnable() {
@Override
public void run() {
String fieldId = field.getSID();
TextView tv = null;

// get the text field
switch (fieldId) {

case SID_TyreSpdPresMisadaption:
tv = (TextView) findViewById(R.id.text_TyreSpdPresMisadaption);
break;
case SID_TyreFLState:
tv = (TextView) findViewById(R.id.text_TyreFLState);
break;
case SID_TyreFLPressure:
tv = (TextView) findViewById(R.id.text_TyreFLPressure);
break;
case SID_TyreFRState:
tv = (TextView) findViewById(R.id.text_TyreFRState);
break;
case SID_TyreFRPressure:
tv = (TextView) findViewById(R.id.text_TyreFRPressure);
break;
case SID_TyreRLState:
tv = (TextView) findViewById(R.id.text_TyreRLState);
break;
case SID_TyreRLPressure:
tv = (TextView) findViewById(R.id.text_TyreRLPressure);
break;
case SID_TyreRRState:
tv = (TextView) findViewById(R.id.text_TyreRRState);
break;
case SID_TyreRRPressure:
tv = (TextView) findViewById(R.id.text_TyreRRPressure);
break;
}
// set regular new content, all exeptions handled above
if (tv != null) {
tv.setText("" + (Math.round(field.getValue() * 10.0) / 10.0));
}

tv = (TextView) findViewById(R.id.textDebug);
tv.setText(fieldId);
}
});

}
}
Loading

0 comments on commit a5bb53b

Please sign in to comment.