|
@@ -26,6 +26,7 @@ namespace SicknessReduction.Haptic
|
|
|
public int fixedCycleRpm;
|
|
|
|
|
|
private int currentCycle;
|
|
|
+ private bool stopped = false;
|
|
|
|
|
|
private bool initialCyclePublished;
|
|
|
private int previousCadence = -1;
|
|
@@ -71,8 +72,10 @@ namespace SicknessReduction.Haptic
|
|
|
|
|
|
private async Task StopVibrating()
|
|
|
{
|
|
|
+ if (stopped) return;
|
|
|
await Broker.Publish(TOPIC_CYCLE, "0");
|
|
|
currentCycle = 0;
|
|
|
+ stopped = true;
|
|
|
}
|
|
|
|
|
|
private async Task VibrateAlternatingCadenceBased()
|
|
@@ -81,6 +84,7 @@ namespace SicknessReduction.Haptic
|
|
|
if (!cadence.HasValue) return;
|
|
|
var c = cadence.Value;
|
|
|
|
|
|
+ stopped = false;
|
|
|
PreviousUpdateActive = true; //flag to avoid concurrent updates
|
|
|
//as soon as we have a cadence, we want the motors to vibrate
|
|
|
if (!initialCyclePublished)
|
|
@@ -119,9 +123,13 @@ namespace SicknessReduction.Haptic
|
|
|
|
|
|
private async Task VibrateContinuous(int cycleValue)
|
|
|
{
|
|
|
- if (Math.Abs(cycleValue - currentCycle) > 0)
|
|
|
+ if (Math.Abs(cycleValue - currentCycle) > 2)
|
|
|
+ {
|
|
|
+ stopped = false;
|
|
|
//Debug.Log($"Sending Cycle {cycleValue}");
|
|
|
await Broker.Publish(TOPIC_CYCLE, $"{cycleValue}");
|
|
|
+ currentCycle = cycleValue;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private async Task PublishCadence(int cadence)
|