BSA – WPF First Look

This is the WPF version of BSA after a few hours of work. It’s not much to look at, but I will focus on BSA itself and not the dark theme/cool look this time. Firstly I need to learn WPF so I can generate code for it anyway – but, I also expect to find a drop-in library that will change the look with a few hours work later. Lets see how fast I can catch up with 3+ months of QML work – that is the only thing that matters. So far I am impressed over how easy it is to learn WPF compared to QML.

BSA – C#/WPF .NET 5

Most of my focus is on SW for the time being, and it is sadly less interesting to write about yet. My BSA project is ambiguous specially since I keep switching development platform.

Back in the early days I did vector graphics on DOS. The challenge then was that you needed to even develop raster graphics functions yourself. My first 2D drawing was on Windows 95 using C++/MFC. That was a great success, but after that I basically stopped doing UI for a long time. I did a test using GDI+, Lazarus, Qt and even C#/Forms before I finally had a chance to work with Qt/QML.

Qt/QML is so far the best solution in terms of the result, but I am concerned that QML is so slow to develop with, so I want to try yet another solution – C#/WPF and .NET 5.

The main difference between QML and WPF in 2021 is that Visual Studio actually work as it is supposed to – it is a far better integration to XAML and C# than QML is. The debugger work properly and you only code in XAML and C#.

The second difference is 3rd party libraries. In QML they are expensive if they exist at all, while in Visual Studio you have access to ca 235,000 libraries with a single click.

Something that is not different is that you need to modify a lot of controls to have a dark theme etc, but you have the advantage that it’s a lot of 3rd parties that has done this already.

My WPF version of BSA don’t look as cool as my QML version yet, but just wait.

I have coded in C# before and was tempted to develop BSA in Forms since .NET 4.6.2, but .NET 5 and WPF seems to be much faster to work with than QML. My QML version is not lost because I will generate code for QML regardless. And I need to generate code for C#/WPF .NET 5 as well. And don’t worry, I will pick up Lazaruz as well at some point.

BSA – HMI Gauge Editor

This simple drawing illustrate how I can create a gauge with several separate layers. In this case I draw a background and a needle on top of that. The final gauge is illustrated at top. This is exacly how I plan to embed a gauge editor in BSA – by using a table with x layers where the user can draw (or code) each layer separately and watch the result. This is an easy way of creating gauges where you also can use gauges within gauges.

In this example I scale the rotation of the needle so that input value match the scale. But, I could easily rotate or change something else – meaning we create a system to scale input values to position, rotation etc so we can animate any part of the gauge. It’s a few details I need to experiment with, but gauges are important in my worlds and this system should allow you all to create your own gauges easely.

Once created the gauge should be visible in the toolbar and be available for usage – which means I need tp export properties to make a consolidated property list. For gauges build this way I plan an in-line editor where you can create local adaptions or modify the library directly from the place you use the gauge. I think this will be awesome, but it will require some experimentation and try & fail adaptions as we go.

High Precision Posision System

This board can be purchased from Sparkfun for 215.- USD and is basically a breakout board for ZED-F9P from ublox. ZED-F9P can be purchased for 148.- USD in quantum of 10 units, but I only wanted two of these boards for now for my robot project.

What is important with this is the 10mm precision on the GPS. You are reading right – 10 milli meters (1 cm) accuracy. This is also why it is so pricy yet, but I expect it will get competition as we move forward and drop in price.

I have not tested this yet, but to achieve 10mm I will need two of these and set up a RTK system. RTK means you have (1) GPS on the vehicle and a (2) a second GPS on a fixed base station. As the base station know it’s position it can measure error in position caused by athmosferic conditions or weather and send that as correction data to the mobile unit. This is stated to be working for up to 50km, but I am happy with 5-10km as that is the practical range of LoRa units.

Myself I will only be running a small robot or garden machine around mostly for position testing.

I will return to this unit later. For now I want to focus on my HMI project + wait for better weather 🙂 because I basically need HMI for everything I do.

BSA – PLD Events Quick Guide

This example is a valid Plain Logic Diagram. Since the start and exit symbols are drawn on the same diagram this will count as a single diagram then it is re-used. It will be a block with 3 entry points and 3 possible events. Ignore the fact that Start3 and Exit3 is a separate diagram – if they are drawn on the same page they are seen as one. Also notice that I have added a circle and a circle with cross adapted from UML State Diagrams.

This next diagram (above) adds in a formal state definition as drawn in SDL (Specification and Description Language). The “operation” represent something we do – mostly sending an outgoing event/message. State will wait forever for Event1 or Event2 to happen. All other events are ignored. Event1 and Event2 only visualize the events we are waiting for. PLD do not require you to be so formal in defining your state-machine. State do however have a second function as it act as a goto-label. If you rename one of the exit symbols to the same name as “State” it will goto that state and in effect loop.

Events and Operations can be visualized in 2 different direction and with a color band to differentiate various protocols. These are only visual gimmics to help readability of a diagram.

PLD allows some simplifications. The first is that you don’t need that State symbol if your not going to use the goto functionality. You can simply add the events straight on the operations or any other symbol. This does the same, but simplifies the diagram a bit.

This next diagram (above) takes it all out as we display text only, not the events symbols.

This last one assume you call a function foo() wich will return Ok or Error. PLD allows events to be:

  1. Static, meaning they are hard-coded with  jump to a error-handler diagram.
  2. Optionally, meaning they have a default behavior the user can override.
  3. Mandatory, meaning the user MUST override.

Error and Timeout are usually coded as Optional, while OK is Mandatory.

This allows you to code advanced diagrams with error processing, but avoid that error handling takes over your diagrams.

Visual Studio MFC

This is just an auto-generated demo (new application) using Visual Studio/MFC. I use Visual Studio Community so you can download this and try for yourself. I switched from DOS to Windows back in early 90’s using Windows SDK and C at first – I remember the day I got my hands on Visual C++ 1.0 and the first version of MFC – it was a big difference. The best part was the debugger that set a new standard.

The content of the views about are demos – not functional, but the components are very real. You see a TreeView at left and a very good Property Editor at left + what you don’t see is a very good docking system. The app mimic an earlier version of Visual Studio.

Graphics in MFC is GDI by default, but you can use GDI+ with a trick – meaning modern precentation graphics through CPU.

Comparing MFC to Qt I would chose MFC any day, but Visual Studio only have C#/WPF that can compete with Qt/QML.

And as for MFC – I have used this for years as a Windows GUI developer, but it is few that uses this today – firstly it has a steep learning curve so few know it. But, Microsoft don’t focus on this anymore sot it is more or less abandoned. It does not receive the wealth of new components and infrastructure as .NET does.

Comparing Qt/QML to .NET/Core + WPF – I don’t know. C# is much easier to develop with than QML, but I have never dug into the WPF side. The reason I currently work on QML is the access to the GPU’s. QML is easy to work with on graphics, but bindings to C++ makes it difficult unless you want to develope everything in JavaScript. The main drawback with QML is that you don’t get a flying start as the one above – but, that will change soon.

MFC brings back many good memories about things that worked as expected – I will not claim that it is easy to code in, but it is no worse than Qt to be gentle.

The challenge however is that this is Windows Desctop only and for that it is great – but, applications these days needs to be precent on Web, Windows, Linux, iMac, tablets and phones – and it will be interesting to see if Qt/QML delivers on those.

The demo above have some important learnings – Wizards & Templates to get started is worth a few days, but their not the ones getting the job done as you work day by day, month after month on a system. The Property Editor is a good source for ideas, but not everything is perfect. I will do better. As for docking system – Wait & See.

ST/STM32 SW Quality

I have written about this issue before, but ST never fail to suprice me on their SW quality – crap that don’t work: Bugs, bugs and bugs!

I updated STM32CubeIDE to version 1.6.0 yesterday and discovered that the IDE fail to load the images – I had to default to STM32-Link Utility to be able to load the image. Reading on other peoples work I see that I now need to download OpenOCD.

I wanted to test a USBCAN created with STM32F105RB and auto-created a project using the newest HAL driver from ST – guess what – it does not compile, so I tried 1.8.2 and it does not compile, but finally 1.8.1 compiled out of the box – this is serious crap!

The third error is the USB. USB work straight up on other MCU’s, but not on STM32F105fRB – I can’t rule out that this is a HW fault yet, but I have this working on STM32F405RG so I think the answer is that I ditch STM32F105 from my designs.

Don’t take me wrong – I am a big fan of ST MCU’s, but I am a bigger fan of things that actually works out of the box and it’s been far to many critical issues with ST’s software quality over the years. This is not exacly the first entry I make about ST and their SW quality. They are not at the lever they need to be on!

STM32CubeIDE is great – they had one of the best debuggers I have seen. I use OpenOCD on different projects, so it will be interesting to see how this works out – but, ST’s debugger seemed to work much better with debugging on multiple projects – that was before they screwed it up. I actually re-installed from scratch yesterday as well. I will dig into OpenOCD latar,

BSA – Color Palettes

Setting up all the colors needed for controls is actually a bit of job because you need a set of colors for (1) Normal display, (2) Mouse Hover, (3) different states. In this case I show a button so I need Pressed. And for each set I need background, text and border etc. So, if you see only a few properties now – just wait.

I need all the properties available, but at the same time I don’t want to fiddle with them. So, what I will do is to set up a Palette system where you chose the value “Palette” meaning that colors are preset in a global paletter that support global themes. So if you want to change a color you can either change the Palette – in which case you change it for all objects, or you can set the color directly as shown above. In the later case you change it for “this” control only. But, at the end of the day I just want to drop in controls and not worry about fiddly details like colors – I just chose a theme for my application.

BSA – Text Edit 2

My previous entry raised the issue about how to edit multi-line text. The illustrations below show one possibility.

In this case I illustrate a description – something I want on every object. This is a normal property, but since it is a multi-line text it servers little purpose to display it on a few characters like a normal property. A possible solution is shown below.

As you expand the property to edit it I can pop out a small mini-editor to make it easier to edit this exact property type. As editing is done we collapse it back in. The only drawback is that we now need to expand the text field every time we want to read it – which make it less available/readable. But, it’s an idea.

BSA – Text Edit

This shows the Note – the Note is a tool allowing you to write text with a Note border around it and it can be linked to obkects with lines etc – a handy way to make comments.

However – how do we edit the note? (1) display the full note, while (2) display the property editor version – ok it will look better once I allow multi-line text in the editor, but that is not the point – how should we edit the content of that note?

The answer is straight forward – directly in (1)! Double click on the node and you go into inline edit mode. This is one example where editing in the Property Editor makes no sense because an inline editor will be so more awesome. And even better is that while we edit we can as well show specialized text tools and even capabilities to add images inside text etc.