Skip to content

Commit

Permalink
track current vibration settings across messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Me authored and Me committed Jun 30, 2019
1 parent 0ce47d1 commit 047d21e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
13 changes: 0 additions & 13 deletions Constants.cs

This file was deleted.

13 changes: 8 additions & 5 deletions Program.cs
Expand Up @@ -188,6 +188,7 @@ static async Task WatchLogFileAsync(string filename, ButtplugClientDevice device
fs.Seek(0, SeekOrigin.End);

// Watch the file
double currentSetting = 0;
using (var sr = new StreamReader(fs))
{
while (true)
Expand All @@ -207,11 +208,12 @@ static async Task WatchLogFileAsync(string filename, ButtplugClientDevice device
{
if (vl is VibrateStart)
{
await HandleVibrateStart(device, vl as VibrateStart);
currentSetting = await HandleVibrateStart(device, vl as VibrateStart, currentSetting);
}
else if (vl is VibrateStop)
{
await device.SendVibrateCmd(0);
currentSetting = 0;
}
}
catch (ButtplugDeviceException)
Expand All @@ -231,15 +233,16 @@ static async Task WatchLogFileAsync(string filename, ButtplugClientDevice device
//wh.Close();
}

private static async Task HandleVibrateStart(ButtplugClientDevice device, VibrateStart vs)
private static async Task<double> HandleVibrateStart(ButtplugClientDevice device, VibrateStart vs, double currentSetting)
{
await device.SendVibrateCmd(vs.strength);
// TODO handle intervals
await vs.time.IfSomeAsync(async time =>
return await vs.time.MatchAsync(async time =>
{
await Task.Delay(time);
await device.SendVibrateCmd(0);
});
await device.SendVibrateCmd(currentSetting);
return currentSetting;
}, () => vs.strength);
}

static Either<Exception, VibrateCommand> ParseVibrateLine(string s)
Expand Down
1 change: 0 additions & 1 deletion skybutt.csproj
Expand Up @@ -78,7 +78,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Constants.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
Expand Down

0 comments on commit 047d21e

Please sign in to comment.