Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simu branch created #30

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Ev3SimuGui/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
</configuration>
8 changes: 8 additions & 0 deletions Ev3SimuGui/Application.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Application x:Class="Application"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
StartupUri="MainWindow.xaml">
<Application.Resources>

</Application.Resources>
</Application>
6 changes: 6 additions & 0 deletions Ev3SimuGui/Application.xaml.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Class Application

' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
' can be handled in this file.

End Class
106 changes: 106 additions & 0 deletions Ev3SimuGui/BytesToImageConverter.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
Imports MonoBrickFirmware.Display

Public Class BytesToImageConverter
Implements IValueConverter

Private PixelFormat As PixelFormat = PixelFormats.BlackWhite
Private CorrectBytes As Byte()
Private BytesPerLine As Integer = CInt((Lcd.Width * PixelFormat.BitsPerPixel + 7) / 8)

Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
Dim BmpSrc As System.Windows.Media.Imaging.BitmapSource

If value Is Nothing Then
' create white screen
CreateEmptyScreen()
Else
'CorrectBitOrder(CType(value, Byte()))
CorrectBytes = CType(value, Byte())
End If

BmpSrc = ByteArrayToBitmapSource(CorrectBytes)
Return BmpSrc
End Function

Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
Return Nothing
End Function

Private Sub CreateEmptyScreen()
If CorrectBytes Is Nothing Then
ReDim CorrectBytes(Lcd.Height * BytesPerLine - 1)
End If
For i = LBound(CorrectBytes) To UBound(CorrectBytes)
CorrectBytes(i) = 255
Next
End Sub

'Private Sub CorrectBitOrder(ReverseBitByteArray As Byte())
' For i = LBound(ReverseBitByteArray) To UBound(ReverseBitByteArray)
' CorrectBytes(i) = ConvertBits(ReverseBitByteArray(i))
' Next
'End Sub

'Private Function ConvertBits(WrongByte As Byte) As Byte
' ' Reverse sequence and invert bits
' Dim NewValue As Byte = 0
' If WrongByte = 0 Then
' NewValue = 255
' Else
' Dim Mask As Byte = 128
' Dim NewBit As Byte = 1
' For i = 0 To 7
' If (WrongByte And Mask) > 0 Then
' ' nothing to do
' Else
' NewValue = NewValue + NewBit
' End If
' Mask = Mask >> 1
' NewBit = NewBit << 1
' Next
' End If
' Return NewValue
'End Function


Private Function ByteArrayToBitmapSource(ByteArray() As Byte) As System.Windows.Media.Imaging.BitmapSource
Dim BmpSrc As System.Windows.Media.Imaging.BitmapSource
Dim Width As Integer = Lcd.Width
Dim Height As Integer = Lcd.Height
Dim dpiX As Double = 200
Dim dpiY As Double = 200
Dim BitmapPalette As BitmapPalette = BitmapPalettes.BlackAndWhite
BmpSrc = System.Windows.Media.Imaging.BitmapSource.Create _
(Width, Height, dpiX, dpiY, PixelFormat, BitmapPalette, ByteArray, BytesPerLine)
Return BmpSrc
End Function

Private Function ByteToBinary(Value As Byte) As String
Dim Mask As Byte = 128
Dim s As String = ""
For i = 1 To 8
If (Value And Mask) > 0 Then
s = s & "1"
Else
s = s & "0"
End If
Mask = CByte(Mask \ 2)
Next
Return s
End Function

Private Function BinaryToByte(Bits As String) As Byte
Dim Mask As Byte = 128
Dim s As String = Bits
Dim b As Byte = 0
For i = 1 To 8
If Mid(s, i, 1) = "1" Then
b = b + Mask
End If
Mask = CByte(Mask \ 2)
Next
Return b
End Function


End Class
174 changes: 174 additions & 0 deletions Ev3SimuGui/Ev3SimuGui.vbproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B55F611B-9D25-4E91-9EC9-2FF43425C441}</ProjectGuid>
<ProjectTypeGuids>{60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}</ProjectTypeGuids>
<OutputType>WinExe</OutputType>
<RootNamespace>Ev3SimuGui</RootNamespace>
<AssemblyName>Ev3SimuGui</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<MyType>Custom</MyType>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<IncrementalBuild>true</IncrementalBuild>
<OutputPath>bin\Debug\</OutputPath>
<DocumentationFile>Ev3SimuGui.xml</DocumentationFile>
<NoWarn>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42314</NoWarn>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<DebugSymbols>false</DebugSymbols>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<IncrementalBuild>false</IncrementalBuild>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DocumentationFile>Ev3SimuGui.xml</DocumentationFile>
<NoWarn>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42314</NoWarn>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>On</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\x86\Debug\</OutputPath>
<DocumentationFile>Ev3SimuGui.xml</DocumentationFile>
<NoWarn>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42314</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<DefineTrace>true</DefineTrace>
<OutputPath>bin\x86\Release\</OutputPath>
<DocumentationFile>Ev3SimuGui.xml</DocumentationFile>
<Optimize>true</Optimize>
<NoWarn>41999,42016,42017,42018,42019,42020,42021,42022,42032,42036,42314</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<CodeAnalysisRuleSet>ManagedMinimumRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="System.Xaml">
<RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference>
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
</ItemGroup>
<ItemGroup>
<ApplicationDefinition Include="Application.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</Page>
<Compile Include="Application.xaml.vb">
<DependentUpon>Application.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="BytesToImageConverter.vb" />
<Compile Include="MainWindow.xaml.vb">
<DependentUpon>MainWindow.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Import Include="System.Threading.Tasks" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Diagnostics" />
<Import Include="System.Windows" />
<Import Include="System.Windows.Controls" />
<Import Include="System.Windows.Data" />
<Import Include="System.Windows.Documents" />
<Import Include="System.Windows.Input" />
<Import Include="System.Windows.Shapes" />
<Import Include="System.Windows.Media" />
<Import Include="System.Windows.Media.Imaging" />
<Import Include="System.Windows.Navigation" />
</ItemGroup>
<ItemGroup>
<Compile Include="MWViewModelBitmap.vb" />
<Compile Include="My Project\AssemblyInfo.vb">
<SubType>Code</SubType>
</Compile>
<Compile Include="My Project\MyExtensions\MyWpfExtension.vb">
<VBMyExtensionTemplateID>Microsoft.VisualBasic.WPF.MyExtension</VBMyExtensionTemplateID>
<VBMyExtensionTemplateVersion>1.0.0.0</VBMyExtensionTemplateVersion>
</Compile>
<Compile Include="My Project\Resources.Designer.vb">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="My Project\Settings.Designer.vb">
<AutoGen>True</AutoGen>
<DependentUpon>Settings.settings</DependentUpon>
<DesignTimeSharedInput>True</DesignTimeSharedInput>
</Compile>
<EmbeddedResource Include="My Project\Resources.resx">
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
<CustomToolNamespace>My.Resources</CustomToolNamespace>
</EmbeddedResource>
<None Include="My Project\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
</None>
<AppDesigner Include="My Project\" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Resource Include="Resources\MonoBrickLogo.jpg" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MonoBrickFirmware\MonoBrickFirmware.csproj">
<Project>{67261e03-d263-4c42-a5ad-2a4820231b28}</Project>
<Name>MonoBrickFirmware</Name>
</ProjectReference>
<ProjectReference Include="..\SimuTestExample\SimuTestExample.vbproj">
<Project>{58f1f795-105f-475e-996a-46e1af1f5780}</Project>
<Name>SimuTestExample</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
</Project>
25 changes: 25 additions & 0 deletions Ev3SimuGui/MWViewModelBitmap.vb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Imports MonoBrickFirmware.HardwareIF

Public Class MWViewModelBitmap

Private _ButtonHAL As ButtonHAL = ButtonHal.Init
Private WithEvents _LcdHAL As LcdHAL = LcdHal.Init


Public Sub New()

End Sub

Public ReadOnly Property ButtonHal As ButtonHAL
Get
Return _ButtonHAL
End Get
End Property

Public ReadOnly Property LcdHal As LcdHAL
Get
Return _LcdHAL
End Get
End Property

End Class
67 changes: 67 additions & 0 deletions Ev3SimuGui/MainWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:HardwareIF="clr-namespace:MonoBrickFirmware.HardwareIF;assembly=MonoBrickFirmware"
xmlns:UserInput="clr-namespace:MonoBrickFirmware.UserInput;assembly=MonoBrickFirmware"
xmlns:local="clr-namespace:Ev3SimuGui"
Title="EV3-Simulator" Height="560" Width="340" MinWidth="340" MinHeight="560" ScrollViewer.VerticalScrollBarVisibility="Disabled" >
<Window.Resources>
<local:BytesToImageConverter x:Key="BytesToImageConverter" />
</Window.Resources>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="80*"/>
<ColumnDefinition Width="80*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="71"/>
<RowDefinition Height="249*"/>
<RowDefinition Height="60"/>
<RowDefinition Height="45"/>
<RowDefinition Height="54"/>
<RowDefinition Height="110"/>
</Grid.RowDefinitions>
<Ellipse x:Name="eLed" Grid.Column="2" Fill="#FF343434" Grid.Row="3" IsEnabled="False" Opacity="0.2" Margin="-10"/>
<Rectangle Grid.ColumnSpan="4" Fill="#FFE6E6E6" Grid.Row="5" Margin="1,0"/>
<Rectangle Grid.ColumnSpan="4" Fill="#FFE6E6E6" Grid.RowSpan="2" IsEnabled="False" Margin="0,0,2.25,1"/>
<Button x:Name="bEscape" Content="Escape" HorizontalAlignment="Left" Margin="10" Grid.Row="2" VerticalAlignment="Top" Width="60" Height="22"/>
<Button x:Name="bLeft" Content="Left" Grid.Column="1" HorizontalAlignment="Right" Margin="10" Grid.Row="3" VerticalAlignment="Center" Width="60" Height="22"/>
<Button x:Name="bEnter" Content="Enter" Grid.Column="2" HorizontalAlignment="Center" Margin="10" Grid.Row="3" VerticalAlignment="Center" Width="60" Height="22"/>
<Button x:Name="bDown" Content="Down" Grid.Column="2" HorizontalAlignment="Center" Margin="10" Grid.Row="4" VerticalAlignment="Top" Width="60" Height="22"/>
<Button x:Name="bRight" Content="Right" Grid.Column="3" HorizontalAlignment="Left" Margin="10" Grid.Row="3" VerticalAlignment="Center" Width="60" Height="22"/>
<Button x:Name="bUp" Content="Up" Grid.Column="2" HorizontalAlignment="Center" Margin="10" Grid.Row="2" VerticalAlignment="Bottom" Width="60" Height="22"/>
<TextBox x:Name="tbOutA" Height="23" Margin="20,10,21,0" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Top" TextAlignment="Center"/>
<TextBox Grid.Column="1" Height="23" Margin="21,10,20,0" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Top" TextAlignment="Center"/>
<TextBox Grid.Column="2" Height="23" Margin="20,10,20,0" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Top" TextAlignment="Center"/>
<TextBox Grid.Column="3" Height="23" Margin="20,10,21,0" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Top" TextAlignment="Center"/>
<TextBox Height="23" Margin="20,0,21,10" Grid.Row="5" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Bottom" TextAlignment="Center"/>
<TextBox Grid.Column="1" Height="23" Margin="21,0,20,10" Grid.Row="5" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Bottom" TextAlignment="Center"/>
<TextBox Grid.Column="2" Height="23" Margin="20,0,20,10" Grid.Row="5" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Bottom" TextAlignment="Center"/>
<TextBox Grid.Column="3" Height="23" Margin="20,0,21,10" Grid.Row="5" TextWrapping="Wrap" Text="tbd" VerticalAlignment="Bottom" TextAlignment="Center"/>
<Label x:Name="lOutA" Content="OutputA" Margin="10,0,10,10" VerticalAlignment="Bottom" Height="26" IsEnabled="False" HorizontalContentAlignment="Center"/>
<Label x:Name="lOutB" Content="OutputB" Grid.Column="1" Margin="10,0,10,10" VerticalAlignment="Bottom" Height="26" IsEnabled="False" HorizontalContentAlignment="Center"/>
<Label x:Name="lOutC" Content="OutputC" Grid.Column="2" Margin="10,0,10,10" VerticalAlignment="Bottom" IsEnabled="False" HorizontalContentAlignment="Center" Height="26"/>
<Label x:Name="lOutD" Content="OutputD" Grid.Column="3" Margin="10,0,10,10" VerticalAlignment="Bottom" IsEnabled="False" HorizontalContentAlignment="Center" Height="26"/>
<Label x:Name="lIn1" Content="Input1" Margin="10,10,10,35" Grid.Row="5" VerticalAlignment="Bottom" Width="60" IsEnabled="False" HorizontalAlignment="Center" HorizontalContentAlignment="Center" Height="26"/>
<Label x:Name="lIn2" Content="Input2" Grid.Column="1" Margin="10,10,10,35" Grid.Row="5" VerticalAlignment="Bottom" IsEnabled="False" HorizontalContentAlignment="Center" Height="26"/>
<Label x:Name="lIn3" Content="Input3" Grid.Column="2" Margin="10,10,10,35" Grid.Row="5" VerticalAlignment="Bottom" IsEnabled="False" HorizontalContentAlignment="Center" Height="26"/>
<Label x:Name="lIn4" Content="Input4" Grid.Column="3" Margin="10,10,10,35" Grid.Row="5" VerticalAlignment="Bottom" IsEnabled="False" HorizontalContentAlignment="Center" Height="26"/>
<Button x:Name="bStart" Content="Start" HorizontalAlignment="Left" Margin="10" Grid.Row="4" VerticalAlignment="Bottom" Width="40" Background="#FF1BAC14" Height="22"/>
<Rectangle x:Name="rFrame" Grid.ColumnSpan="4" Fill="Black" Margin="0" Grid.Row="1" Stroke="Black"/>
<Image x:Name="iLcd"
Grid.ColumnSpan="4"
Margin="10"
Grid.Row="1"
Source="{Binding Path=LcdHal.CurrentBytes, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource BytesToImageConverter}}"
Stretch="Fill">
</Image>
<Image x:Name="iLogo" Source="Resources/MonoBrickLogo.jpg" Grid.Column="3" HorizontalAlignment="Right" Height="34" Margin="0,5,5,56" Grid.Row="5" VerticalAlignment="Top" Width="39" />
<Label x:Name="lEv3" Content="MonoBrick EV3" HorizontalAlignment="Left" Margin="5,0,0,0" Grid.Row="5" VerticalAlignment="Top" FontSize="20" Grid.ColumnSpan="2" Width="161" FontWeight="Bold" Foreground="White"/>
<Rectangle x:Name="rInput" Grid.ColumnSpan="4" Height="55" Margin="5,40,5,5" Grid.Row="5" Stroke="#FF747474" VerticalAlignment="Bottom" StrokeThickness="2"/>
<Rectangle x:Name="rOutput" Grid.ColumnSpan="4" Height="55" Margin="5,5,5,5" Grid.Row="0" Stroke="#FF747474" VerticalAlignment="top" StrokeThickness="2"/>
<!-- Add logo.jpg as resource, then Property.BuildAction of Logo has to be set to Resource, no other value -->
<!-- Source: http://stackoverflow.com/questions/8483002/image-shows-up-in-visual-studio-designer-but-not-during-run-time-->
</Grid>
</Window>
Loading