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