Skip to content

Commit

Permalink
Merge pull request #10 from harp-tech/fix_pulse_valves
Browse files Browse the repository at this point in the history
Fix pulse valves
  • Loading branch information
artursilva0 authored Jan 25, 2024
2 parents 6422a50 + c2cb331 commit 27a285a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 46 deletions.
2 changes: 1 addition & 1 deletion App/Olfactometer.Design/Olfactometer.Design.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<RuntimeIdentifiers>win-x64;osx-x64;linux-x64</RuntimeIdentifiers>
<RootNamespace>Olfactometer.Design</RootNamespace>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
Expand Down
76 changes: 44 additions & 32 deletions App/Olfactometer.Design/ViewModels/OlfactometerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public class OlfactometerViewModel : ReactiveValidationObject
[Reactive] public float Channel4TargetFlow { get; set; }
[Reactive] public float Channel4ActualFlow { get; set; }

[Reactive] public ushort PulseValve0 { get; set; }
[Reactive] public ushort PulseValve1 { get; set; }
[Reactive] public ushort PulseValve2 { get; set; }
[Reactive] public ushort PulseValve3 { get; set; }
[Reactive] public ushort PulseEndValve0 { get; set; }
[Reactive] public ushort PulseEndValve1 { get; set; }
[Reactive] public ushort Valve0PulseDuration { get; set; }
[Reactive] public ushort Valve1PulseDuration { get; set; }
[Reactive] public ushort Valve2PulseDuration { get; set; }
[Reactive] public ushort Valve3PulseDuration { get; set; }
[Reactive] public ushort EndValve0PulseDuration { get; set; }
[Reactive] public ushort EndValve1PulseDuration { get; set; }

[Reactive] public bool Valve0State { get; set; }
[Reactive] public bool Valve1State { get; set; }
Expand All @@ -77,12 +77,12 @@ public class OlfactometerViewModel : ReactiveValidationObject
[Reactive] public bool EndValve0State { get; set; }
[Reactive] public bool EndValve1State { get; set; }

[Reactive] public bool Valve0Pulse { get; set; }
[Reactive] public bool Valve1Pulse { get; set; }
[Reactive] public bool Valve2Pulse { get; set; }
[Reactive] public bool Valve3Pulse { get; set; }
[Reactive] public bool EndValve0Pulse { get; set; }
[Reactive] public bool EndValve1Pulse { get; set; }
[Reactive] public bool Valve0PulseState { get; set; }
[Reactive] public bool Valve1PulseState { get; set; }
[Reactive] public bool Valve2PulseState { get; set; }
[Reactive] public bool Valve3PulseState { get; set; }
[Reactive] public bool EndValve0PulseState { get; set; }
[Reactive] public bool EndValve1PulseState { get; set; }

[Reactive] public int DigitalOutput0Config { get; set; }
[Reactive] public int DigitalOutput1Config { get; set; }
Expand Down Expand Up @@ -220,8 +220,8 @@ await _olfactometer.WriteChannelsTargetFlowAsync(new ChannelsTargetFlowPayload(
}
});

this.WhenAnyValue(x => x.Valve0Pulse, x => x.Valve1Pulse, x => x.Valve2Pulse, x => x.Valve3Pulse,
x => x.EndValve0Pulse, x => x.EndValve1Pulse)
this.WhenAnyValue(x => x.Valve0PulseState, x => x.Valve1PulseState, x => x.Valve2PulseState, x => x.Valve3PulseState,
x => x.EndValve0PulseState, x => x.EndValve1PulseState)
.Subscribe(async x =>
{
if (_olfactometer != null)
Expand Down Expand Up @@ -279,6 +279,17 @@ private IObservable<Unit> SaveConfiguration(bool savePermanently)
await _olfactometer.WriteDO0SyncAsync((DO0SyncConfig)DigitalOutput0Config);
await _olfactometer.WriteDO1SyncAsync((DO1SyncConfig)DigitalOutput1Config);
await _olfactometer.WriteDI0TriggerAsync((DI0TriggerConfig)DigitalInput0Config);

// Pulse state
await _olfactometer.WriteEnableValvePulseAsync(GetCurrentValvesPulse());

// Pulse Valves duration
await _olfactometer.WriteValve0PulseDurationAsync(Valve0PulseDuration);
await _olfactometer.WriteValve1PulseDurationAsync(Valve1PulseDuration);
await _olfactometer.WriteValve2PulseDurationAsync(Valve2PulseDuration);
await _olfactometer.WriteValve3PulseDurationAsync(Valve3PulseDuration);
await _olfactometer.WriteEndValve0PulseDurationAsync(EndValve0PulseDuration);
await _olfactometer.WriteEndValve1PulseDurationAsync(EndValve1PulseDuration);

// External control valves
await _olfactometer.WriteEnableValveExternalControlAsync((EnableFlag)ValveExternalControl);
Expand Down Expand Up @@ -422,12 +433,13 @@ private IObservable<Unit> ConnectAndGetBaseInfo()
Channel4TargetFlow = await _olfactometer.ReadChannel4TargetFlowAsync();
Channel4ActualFlow = await _olfactometer.ReadChannel4ActualFlowAsync();

PulseValve0 = await _olfactometer.ReadValve0PulseDurationAsync();
PulseValve1 = await _olfactometer.ReadValve1PulseDurationAsync();
PulseValve2 = await _olfactometer.ReadValve2PulseDurationAsync();
PulseValve3 = await _olfactometer.ReadValve3PulseDurationAsync();
PulseEndValve0 = await _olfactometer.ReadEndValve0PulseDurationAsync();
PulseEndValve1 = await _olfactometer.ReadEndValve1PulseDurationAsync();
// Get Valves Pulse Duration
Valve0PulseDuration = await _olfactometer.ReadValve0PulseDurationAsync();
Valve1PulseDuration = await _olfactometer.ReadValve1PulseDurationAsync();
Valve2PulseDuration = await _olfactometer.ReadValve2PulseDurationAsync();
Valve3PulseDuration = await _olfactometer.ReadValve3PulseDurationAsync();
EndValve0PulseDuration = await _olfactometer.ReadEndValve0PulseDurationAsync();
EndValve1PulseDuration = await _olfactometer.ReadEndValve1PulseDurationAsync();

// get ValvesState (OdorValves and EndValves)
var odorValvesState = await _olfactometer.ReadOdorValveStateAsync();
Expand All @@ -441,12 +453,12 @@ private IObservable<Unit> ConnectAndGetBaseInfo()

// get ValvesPulse
var valvesPulse = await _olfactometer.ReadEnableValvePulseAsync();
Valve0Pulse = valvesPulse.HasFlag(Valves.Valve0);
Valve1Pulse = valvesPulse.HasFlag(Valves.Valve1);
Valve2Pulse = valvesPulse.HasFlag(Valves.Valve2);
Valve3Pulse = valvesPulse.HasFlag(Valves.Valve3);
EndValve0Pulse = valvesPulse.HasFlag(Valves.EndValve0);
EndValve1Pulse = valvesPulse.HasFlag(Valves.EndValve1);
Valve0PulseState = valvesPulse.HasFlag(Valves.Valve0);
Valve1PulseState = valvesPulse.HasFlag(Valves.Valve1);
Valve2PulseState = valvesPulse.HasFlag(Valves.Valve2);
Valve3PulseState = valvesPulse.HasFlag(Valves.Valve3);
EndValve0PulseState = valvesPulse.HasFlag(Valves.EndValve0);
EndValve1PulseState = valvesPulse.HasFlag(Valves.EndValve1);

// get default values for DO0_SYNC, DO1_SYNC, DI0_TRIGGER
var do0Sync = await _olfactometer.ReadDO0SyncAsync();
Expand Down Expand Up @@ -485,17 +497,17 @@ private IObservable<Unit> ConnectAndGetBaseInfo()
private Valves GetCurrentValvesPulse()
{
_valvesPulse = 0;
if (Valve0Pulse)
if (Valve0PulseState)
_valvesPulse |= Valves.Valve0;
if (Valve1Pulse)
if (Valve1PulseState)
_valvesPulse |= Valves.Valve1;
if (Valve2Pulse)
if (Valve2PulseState)
_valvesPulse |= Valves.Valve2;
if (Valve3Pulse)
if (Valve3PulseState)
_valvesPulse |= Valves.Valve3;
if (EndValve0Pulse)
if (EndValve0PulseState)
_valvesPulse |= Valves.EndValve0;
if (EndValve1Pulse)
if (EndValve1PulseState)
_valvesPulse |= Valves.EndValve1;

return _valvesPulse;
Expand Down
24 changes: 12 additions & 12 deletions App/Olfactometer.Design/Views/OlfactometerView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@
IsChecked="{Binding Path=Valve0State}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<ToggleSwitch Grid.Row="1" Grid.Column="2" Margin="10"
IsChecked="{Binding Valve0Pulse}" VerticalAlignment="Center"
IsChecked="{Binding Valve0PulseState}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<NumericUpDown Grid.Row="1" Grid.Column="3" Margin="10" Increment="1" Minimum="1"
Maximum="65535" MinWidth="130" ClipValueToMinMax="True"
Text="{Binding PulseValve0}" VerticalAlignment="Center"
Text="{Binding Valve0PulseDuration}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBlock Grid.Row="1" Grid.Column="4" Margin="10" Text="[1:65535] ms"
VerticalAlignment="Center" HorizontalAlignment="Center" />
Expand All @@ -249,11 +249,11 @@
IsChecked="{Binding Path=Valve1State}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<ToggleSwitch Grid.Row="2" Grid.Column="2" Margin="10"
IsChecked="{Binding Valve1Pulse}" VerticalAlignment="Center"
IsChecked="{Binding Valve1PulseState}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<NumericUpDown Grid.Row="2" Grid.Column="3" Margin="10" Increment="1" Minimum="1"
Maximum="65535" MinWidth="130" ClipValueToMinMax="True"
Text="{Binding PulseValve1}" VerticalAlignment="Center"
Text="{Binding Valve1PulseDuration}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBlock Grid.Row="2" Grid.Column="4" Margin="10" Text="[1:65535] ms"
VerticalAlignment="Center" HorizontalAlignment="Center" />
Expand All @@ -264,11 +264,11 @@
IsChecked="{Binding Path=Valve2State}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<ToggleSwitch Grid.Row="3" Grid.Column="2" Margin="10"
IsChecked="{Binding Valve2Pulse}" VerticalAlignment="Center"
IsChecked="{Binding Valve2PulseState}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<NumericUpDown Grid.Row="3" Grid.Column="3" Margin="10" Increment="1" Minimum="1"
Maximum="65535" MinWidth="130" ClipValueToMinMax="True"
Text="{Binding PulseValve2}" VerticalAlignment="Center"
Text="{Binding Valve2PulseDuration}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBlock Grid.Row="3" Grid.Column="4" Margin="10" Text="[1:65535] ms"
VerticalAlignment="Center" HorizontalAlignment="Center" />
Expand All @@ -279,11 +279,11 @@
IsChecked="{Binding Path=Valve3State}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<ToggleSwitch Grid.Row="4" Grid.Column="2" Margin="10"
IsChecked="{Binding Valve3Pulse}" VerticalAlignment="Center"
IsChecked="{Binding Valve3PulseState}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<NumericUpDown Grid.Row="4" Grid.Column="3" Margin="10" Increment="1" Minimum="1"
Maximum="65535" MinWidth="130" ClipValueToMinMax="True"
Text="{Binding PulseValve3}" VerticalAlignment="Center"
Text="{Binding Valve3PulseDuration}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBlock Grid.Row="4" Grid.Column="4" Margin="10" Text="[1:65535] ms"
VerticalAlignment="Center" HorizontalAlignment="Center" />
Expand All @@ -294,11 +294,11 @@
IsChecked="{Binding Path=EndValve0State}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<ToggleSwitch Grid.Row="5" Grid.Column="2" Margin="10"
IsChecked="{Binding EndValve0Pulse}" VerticalAlignment="Center"
IsChecked="{Binding EndValve0PulseState}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<NumericUpDown Grid.Row="5" Grid.Column="3" Margin="10" Increment="1" Minimum="1"
Maximum="65535" MinWidth="130" ClipValueToMinMax="True"
Text="{Binding PulseEndValve0}" VerticalAlignment="Center"
Text="{Binding EndValve0PulseDuration}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBlock Grid.Row="5" Grid.Column="4" Margin="10" Text="[1:65535] ms"
VerticalAlignment="Center" HorizontalAlignment="Center" />
Expand All @@ -309,11 +309,11 @@
IsChecked="{Binding Path=EndValve1State}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<ToggleSwitch Grid.Row="6" Grid.Column="2" Margin="10"
IsChecked="{Binding EndValve1Pulse}" VerticalAlignment="Center"
IsChecked="{Binding EndValve1PulseState}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<NumericUpDown Grid.Row="6" Grid.Column="3" Margin="10" Increment="1" Minimum="1"
Maximum="65535" MinWidth="130" ClipValueToMinMax="True"
Text="{Binding PulseEndValve1}" VerticalAlignment="Center"
Text="{Binding EndValve1PulseDuration}" VerticalAlignment="Center"
HorizontalAlignment="Center" />
<TextBlock Grid.Row="6" Grid.Column="4" Margin="10" Text="[1:65535] ms"
VerticalAlignment="Center" HorizontalAlignment="Center" />
Expand Down
2 changes: 1 addition & 1 deletion App/Olfactometer/Olfactometer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
<RootNamespace>Olfactometer</RootNamespace>
<BaseOutputPath>..\bin</BaseOutputPath>
<Version>1.0.0</Version>
<Version>1.0.1</Version>
</PropertyGroup>

<PropertyGroup>
Expand Down

0 comments on commit 27a285a

Please sign in to comment.