MVVM & Microcontrollers

hfaun 1 Reputation point

I am creating an application that can control a micro controller. So the GUI allows me to say things like

  • Define if a particular pin is an input pin or output pin. So there is a combo box with [In, Out] values.
  • Integer (or other) text fields that define parameter values that the micro controller should use.
  • A button that allows me to execute certain routines on the micro controller.

I wanted to use the View-Model-ViewModel concept for this. However, I am kind of struggling with what my model should be. Initially I created a model that holds different variables like

public class MyModel : ModelBase {
    bool pin4IsInput;
    int inputValue1;
    public bool Pin4IsInput {
        get { return pin4IsInput; }
        set { SetProperty(ref pin4IsInput, value); }

The problem is that this really isn't the source of the data. For instance the information if pin4 is an input or output really resides on the micro controller. So this becomes complicated for the VM. When it wants to set pin4 as an input it has to send a command to the micro controller to set pin4 as input. It also has to update the model. When the VM wants to know the status it can't always query the model because some information is volatile. For instance querring if the function I started on the micro control is finished or not has to come from the micro contoller. I can't get that from the model.

Considering the above, the model is kind of useless. Now I could make the micro controller itself the model. However, now the logic to control the micro controller moves into the model. It really shouldn't be there, though. This should be in the VM. Is this just one of those situations where an exception should be made? Or is there another way to approach this?

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,709 questions
{count} votes