Skip to content
Permalink
Browse files

Changes for version 2.7

  • Loading branch information
davidzof committed Feb 15, 2016
1 parent f45bf03 commit 7ff348af489ad12a72c539a2a4ae1894fff04ddc
@@ -9,3 +9,9 @@ bin/
src-pe/
plugins/
jre6/
jre7/
.classpath
.project
build-mac.xml
libvlc.dll
libvlccore.dll
@@ -76,6 +76,7 @@ route=Route
saveclose=Save and Close
saveGPS=Save with GPS and Altitude data?
save=Save
saveroute=Save as GPX
scatter=Scatter Plots
schr=Speed/Cadence/Heart-rate
scid=Speed and Cadence ID
2 run.sh
@@ -1,3 +1,3 @@
LIBS="bin:lib:properties:lib/derby.jar:lib/opencsv-2.3.jar:lib/com-sun-tools-visualvm-charts.jar:lib/com-sun-tools-visualvm-uisupport.jar:lib/commons-lang3-3.2.1.jar:lib/gpx-creator-0.1-beta.jar:lib/hamcrest-core-1.3.jar:lib/jcommon-1.0.17.jar:lib/jcommon-1.0.18.jar:lib/jformica-core1.6.jar:lib/jformica-jsr80-1.6.jar:lib/jfreechart-1.0.14.jar:lib/jna-3.5.1.jar:lib/junit-4.11.jar:lib/miglayout-core-4.2.jar:lib/miglayout-swing-4.2.jar:lib/org-netbeans-lib-profiler-charts.jar:lib/org-netbeans-lib-profiler-ui.jar:lib/org-openide-util-lookup.jar:lib/org-openide-util.jar:lib/usb-api-1.0.2.jar:lib/usb4java-1.2.0.jar:lib/usb4java-javax-1.2.0.jar:lib/vlcj-2.2.0.jar:lib/log4j-1.2.17.jar"
LIBS="bin;lib;properties;lib/derby.jar;lib/opencsv-2.3.jar;lib/com-sun-tools-visualvm-charts.jar;lib/com-sun-tools-visualvm-uisupport.jar;lib/commons-lang3-3.2.1.jar;lib/gpx-creator-0.1-beta.jar;lib/hamcrest-core-1.3.jar;lib/jcommon-1.0.17.jar;lib/jcommon-1.0.18.jar;lib/jformica-core1.6.jar;lib/jformica-jsr80-1.6.jar;lib/jfreechart-1.0.14.jar;lib/jna-3.5.1.jar;lib/junit-4.11.jar;lib/miglayout-core-4.2.jar;lib/miglayout-swing-4.2.jar;lib/org-netbeans-lib-profiler-charts.jar;lib/org-netbeans-lib-profiler-ui.jar;lib/org-openide-util-lookup.jar;lib/org-openide-util.jar;lib/usb-api-1.0.2.jar;lib/usb4java-1.2.0.jar;lib/usb4java-javax-1.2.0.jar;lib/vlcj-2.2.0.jar;lib/log4j-1.2.17.jar"

java -cp $LIBS -Dlog4j.logger.level=DEBUG com.wattzap.Main
@@ -19,7 +19,6 @@
import java.awt.Container;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.io.IOException;
import java.util.HashMap;
@@ -43,13 +43,15 @@
* Externalize menu setup to this class. Registers for Locale change messages so
* we can reinitialize text when language changes.
*
* (c) 2014-2015 David George / Wattzap.com
* (c) 2014-2016 David George / Wattzap.com
*
* @author David George
* @date 25 November 2014
*/
public class MenuBar implements MessageCallback {
private final static UserPreferences userPrefs = UserPreferences.INSTANCE;

public final static String SAVEROUTE = "save";

private final JMenu fileMenu;
private final JMenu trainingMenu;
@@ -61,6 +63,7 @@
private final JMenuItem quitMenuItem;
// File Menu Items
private final JMenuItem openMenuItem;
private final JMenuItem saveRouteMenuItem;
private MenuItem closeMenuItem;
// Training
private final JMenuItem trainMenuItem;
@@ -79,6 +82,8 @@ public MenuBar(MainFrame frame) {
// Preferences
Preferences preferences = new Preferences();
prefMenuItem = new JMenuItem();
prefMenuItem.setAccelerator(KeyStroke.getKeyStroke('P', Toolkit
.getDefaultToolkit().getMenuShortcutKeyMask(), false));
prefMenuItem.addActionListener(preferences);

// About Dialog
@@ -106,6 +111,12 @@ public MenuBar(MainFrame frame) {

RouteFilePicker picker = new RouteFilePicker(frame);
openMenuItem.addActionListener(picker);

saveRouteMenuItem = new JMenuItem();
saveRouteMenuItem.setActionCommand(SAVEROUTE);

saveRouteMenuItem.addActionListener(picker);
fileMenu.add(saveRouteMenuItem);

closeMenuItem = new MenuItem(Messages.CLOSE);
fileMenu.add(closeMenuItem);
@@ -129,18 +140,26 @@ public MenuBar(MainFrame frame) {
trainMenuItem.addActionListener(tPicker);
}
analizeMenuItem = new JMenuItem();
analizeMenuItem.setAccelerator(KeyStroke.getKeyStroke('A', Toolkit
.getDefaultToolkit().getMenuShortcutKeyMask(), false));
trainingMenu.add(analizeMenuItem);
analizeMenuItem.setActionCommand(TrainingController.analyze);

saveMenuItem = new JMenuItem();
saveMenuItem.setAccelerator(KeyStroke.getKeyStroke('S', Toolkit
.getDefaultToolkit().getMenuShortcutKeyMask(), false));
saveMenuItem.setActionCommand(TrainingController.save);
trainingMenu.add(saveMenuItem);

viewMenuItem = new JMenuItem();
viewMenuItem.setAccelerator(KeyStroke.getKeyStroke('V', Toolkit
.getDefaultToolkit().getMenuShortcutKeyMask(), false));
viewMenuItem.setActionCommand(TrainingController.view);
trainingMenu.add(viewMenuItem);

recoverMenuItem = new JMenuItem();
recoverMenuItem.setAccelerator(KeyStroke.getKeyStroke('R', Toolkit
.getDefaultToolkit().getMenuShortcutKeyMask(), false));
recoverMenuItem.setActionCommand(TrainingController.recover);
trainingMenu.add(recoverMenuItem);

@@ -184,6 +203,7 @@ private void doText() {
fileMenu.setText(userPrefs.getString("route"));
openMenuItem.setText(userPrefs.getString("open"));
closeMenuItem.setText(userPrefs.getString("close"));
saveRouteMenuItem.setText(userPrefs.getString("saveroute"));

trainingMenu.setText(userPrefs.getString("training"));
analizeMenuItem.setText(
@@ -204,7 +204,7 @@ public void load(String filename) {
normPower = 1.2 * (UserPreferences.INSTANCE.getMaxPower() / maxPower);
}
// 40% of FTP
float recoveryPower = UserPreferences.INSTANCE.getMaxPower() * 0.4f;
int recoveryPower = (int) (UserPreferences.INSTANCE.getMaxPower() / 0.4);
if (recoveryPower == 0) {
recoveryPower = 75;
}
@@ -221,7 +221,7 @@ public void load(String filename) {
runningDistance += distance;

// Normalize power
rlvP.setPower(p.getPower() * normPower);
rlvP.setPower((int) (p.getPower() * normPower));
if (rlvP.getPower() < recoveryPower) {
// put a floor on minimum power
rlvP.setPower(recoveryPower);
@@ -249,7 +249,7 @@ public void load(String filename) {
}
}
// Normalize power
p.setPower(p.getPower() * normPower);
p.setPower((int) (p.getPower() * normPower));
if (p.getPower() < recoveryPower) {
// put a floor on minimum power
p.setPower(recoveryPower);
@@ -579,11 +579,10 @@ private void GPSData(int version, byte[] data) {
double lon = Float.intBitsToFloat(getUInt(data, i * 16 + 8));
double altitude = Float.intBitsToFloat(getUInt(data, i * 16 + 12));

// System.out.println("alt " + altitude + " distance " + distance);

// GPX Data
// GPS Data
Waypoint wayPoint = new Waypoint(lat, lon);
wayPoint.setEle(altitude);

path.addWaypoint(wayPoint);

while (pointCount < pointList.size()) {
@@ -228,6 +228,15 @@ public boolean isMetric() {
public void setUnits(boolean value) {
setBoolean("units", value);
}

// For automatic screen shots
public boolean isScreenshot() {
return getBoolean("screenshot", false);
}

public void setScreenshot(boolean value) {
setBoolean("screenshot", value);
}

// Social
public String getSLUser() {
@@ -35,7 +35,7 @@
* @author David George
* @date 24th November 2014
*
* (c) 2014 David George / Wattzap.com
* (c) 2014-2016 David George / Wattzap.com
*/
public class SpeedListener extends AntListener implements MessageCallback {
public static String name = "C:SPD";
@@ -49,8 +49,8 @@
private boolean initializing = false;
private Rolling powerRatio;
private boolean simulSpeed;
private static long elapsedTime;
private static long elapsedTimestamp = 0;
//private static long elapsedTime;
//private static long elapsedTimestamp = 0;
private double distance = 0.0;

RouteReader routeData;
@@ -94,8 +94,6 @@ public void receiveMessage(BroadcastDataMessage message) {
* @return Telemetry or null if no reliable data could be calculated.
*/
Telemetry getTelemetry(int time, int count) {


if (lastCount == -1) {
// first time thru, initialize counters
lastCount = count;
@@ -108,7 +106,7 @@ Telemetry getTelemetry(int time, int count) {
initializing = false;
lastCount = count;
lastTime = time;
elapsedTime = System.currentTimeMillis();
//elapsedTime = System.currentTimeMillis();
}
return null;
}
@@ -128,25 +126,33 @@ Telemetry getTelemetry(int time, int count) {
return null;
}

if(tDiff == 0){
//if(tDiff == 0){
//no new value received from sensor could be normal at slow speed if cCount < 6
cCount++;
} else {
//cCount++;
//} else {
//a new value received from sensor clear cCount
cCount = 0;
}
//cCount = 0;
//}

double speed = 0;
double distanceKM = 0;
Telemetry t = new Telemetry();

//allow trainer speed null for down
long timestamp = System.currentTimeMillis();
if (tDiff == 0 && elapsedTimestamp > 0 && routeData != null && routeData.getPoint(distance).getGradient() < 0) {
tDiff = (int) (timestamp - elapsedTimestamp)*1024/1000;
}

elapsedTimestamp = timestamp;
/*
* This allows us to record a speed when we are slowing down to stop by using realtime rather than anttime for readings.
*
* tDiff is zero - so no time difference.
* elapsedtime is not zero so we've started recording
* gradient is less than zero, so downhill
*/
//long timestamp = System.currentTimeMillis();
//if (tDiff == 0 && elapsedTimestamp > 0 && routeData != null && routeData.getPoint(distance).getGradient() < 0) {
//tDiff = (int) (timestamp - elapsedTimestamp)*1024/1000;
//System.out.println(">>> " + tDiff + " sDiff " + sDiff);

//}
//elapsedTimestamp = timestamp;

if (tDiff > 0 ) {
if(sDiff == 0){
if(cCount < 12){
@@ -159,7 +165,7 @@ Telemetry getTelemetry(int time, int count) {
}

double timeS = ((double) tDiff) / 1024;
elapsedTime += (int) (timeS * 1000);
//elapsedTime += (int) (timeS * 1000);
distanceKM = (sDiff * wheelSize) / 100000;

speed = distanceKM / (timeS / (3600));
@@ -172,14 +178,14 @@ Telemetry getTelemetry(int time, int count) {
// based on power and gradient using magic sauce
if (simulSpeed && routeData != null) {
Point p = routeData.getPoint(distance);

if (routeData.routeType() == RouteReader.SLOPE) {
if (p == null) {
// end of the road
distance = 0.0;
return null;
}
if (powerWatts >= 0) {
if (powerWatts > 0) {
// only works when power is positive, this is most of
// the time on a turbo
double realSpeed = (power.getRealSpeed(mass,
@@ -198,21 +204,25 @@ Telemetry getTelemetry(int time, int count) {
* Power Profile: speed is the ratio of our trainer power to
* the expected power, we also apply a bit of smoothing
*/
double ratio = powerRatio.add(powerWatts / p.getPower());
double ratio = powerRatio.add(powerWatts / (double)p.getPower());

// speed is video speed * power ratio
speed = p.getSpeed() * ratio;
distanceKM = (speed / 3600) * timeS;
}
if(distanceKM == 0){
//if(distanceKM == 0){
//the down is to small for have speed. we stop chrono (rollback the increase of elapsedTime)
elapsedTime -= (int) (timeS * 1000);
}
//elapsedTime -= (int) (timeS * 1000);
//}
}

cCount = 0; // received a value, reset counter
} else {
cCount++;
if (cCount < 6) {
// a zero value may just be due to too fast sensor update, wait 6 messages before sending zero
return null;
}

} else if (cCount < 6) {
// a zero value may just be due to too fast sensor update, wait 6 messages before sending zero
return null;
}

lastTime = time;
@@ -231,7 +241,9 @@ Telemetry getTelemetry(int time, int count) {
t.setLongitude(p.getLongitude());
}
t.setSpeed(speed);
t.setTime(elapsedTime);
//t.setTime(elapsedTime);
t.setTime(System.currentTimeMillis()); // use realtime

distance += distanceKM;

logger.debug("sending " + t);
@@ -19,17 +19,17 @@
*
* Represents a data point from a route or power file (gpx, rlv, pwr etc)
*
* @author David George (c) Copyright 2013
* @author David George (c) Copyright 2013-2016
* @date 19 June 2013
*/
public class Point {
private double latitude;
private double longitude;
private double elevation;
private double distanceFromStart;
private double gradientOrPower;
private double gradient;
private int power;
private double speed;
// private double level;
private long time;

public double getSpeed() {
@@ -49,19 +49,19 @@ public void setTime(long time) {
}

public double getGradient() {
return gradientOrPower;
return gradient;
}

public double getPower() {
return gradientOrPower; // overload gradient with power
public int getPower() {
return power; // overload gradient with power
}

public void setGradient(double gradient) {
this.gradientOrPower = gradient;
this.gradient = gradient;
}

public void setPower(double power) {
this.gradientOrPower = power;
public void setPower(int power) {
this.power = power;
}

public double getLatitude() {
@@ -100,7 +100,11 @@ public void setDistanceFromStart(double distanceFromStart) {
public String toString() {
return "Point [latitude=" + latitude + ", longitude=" + longitude
+ ", elevation=" + elevation + ", distanceFromStart="
+ distanceFromStart + ", gradient=" + gradientOrPower
+ ", speed=" + speed + ", time=" + time + "]";
+ distanceFromStart + ", gradient=" + gradient + ", power="
+ power + ", speed=" + speed + ", time=" + time + "]";
}

public String getTcxExtensionsXml() {
return "";
}
}

0 comments on commit 7ff348a

Please sign in to comment.
You can’t perform that action at this time.