forked from upstream-mirrors/OpenTracks
Bluetooth LE: implemented cycling cadence and speed sensors.
Cadence is working while speed still requires the wheel size.
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
package de.dennisguse.opentracks.util;
|
||||
|
||||
public class UintUtils {
|
||||
|
||||
public static int UINT16_MAX = 0xFFFF;
|
||||
public static long UINT32_MAX = 0xFFFFFFFFL;
|
||||
|
||||
private UintUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes a - b for UINT with overflow (b < a).
|
||||
*
|
||||
* @return diff or -1 (invalid)
|
||||
*/
|
||||
public static long diff(long a, long b, final long UINT_MAX) {
|
||||
if (a < 0 || b < 0) {
|
||||
return -1;
|
||||
}
|
||||
if (a > UINT_MAX && b > UINT_MAX) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (a >= b) {
|
||||
return a - b;
|
||||
}
|
||||
|
||||
return (UINT_MAX - b) + a;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user