Skip to content

Commit

Permalink
Changes for version 2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
davidzof committed Feb 15, 2016
1 parent f45bf03 commit 7ff348a
Show file tree
Hide file tree
Showing 25 changed files with 527 additions and 257 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,9 @@ bin/
src-pe/
plugins/
jre6/
jre7/
.classpath
.project
build-mac.xml
libvlc.dll
libvlccore.dll
1 change: 1 addition & 0 deletions properties/MessageBundle_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion src/com/wattzap/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
22 changes: 21 additions & 1 deletion src/com/wattzap/MenuBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -61,6 +63,7 @@ public class MenuBar implements MessageCallback {
private final JMenuItem quitMenuItem;
// File Menu Items
private final JMenuItem openMenuItem;
private final JMenuItem saveRouteMenuItem;
private MenuItem closeMenuItem;
// Training
private final JMenuItem trainMenuItem;
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/com/wattzap/model/RLVReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 2 additions & 3 deletions src/com/wattzap/model/TTSReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down
9 changes: 9 additions & 0 deletions src/com/wattzap/model/UserPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
72 changes: 42 additions & 30 deletions src/com/wattzap/model/ant/SpeedListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -49,8 +49,8 @@ public class SpeedListener extends AntListener implements MessageCallback {
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;
Expand Down Expand Up @@ -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;
Expand All @@ -108,7 +106,7 @@ Telemetry getTelemetry(int time, int count) {
initializing = false;
lastCount = count;
lastTime = time;
elapsedTime = System.currentTimeMillis();
//elapsedTime = System.currentTimeMillis();
}
return null;
}
Expand All @@ -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){
Expand All @@ -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));
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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);
Expand Down
26 changes: 15 additions & 11 deletions src/com/wattzap/model/dto/Point.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand Down Expand Up @@ -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 "";
}
}
Loading

0 comments on commit 7ff348a

Please sign in to comment.