jlpdiez / Base-MVC-for-Platformio

Barebones project that implements the MVC pattern under Platformio ecosystem

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Base MVC project for development under Platformio

C++ Arduino Platform Codacy Badge Build Status License: GPL v3

This is a barebones project used as base to develop projects under the Platformio ecosystem. Some features include:

  • Implements the Model-View-Controller pattern.
  • Built using Platformio folder structure. There are some different example configurations under platformio.ini
  • Uses git submodules for external libraries. To add them do git submodule init. See .gitmodules
  • Is Travis CI enabled .travis.yml. There's also another Travis script that manually downloads external libraries instead of relying on git submodules .travisExplicitLibraries.yml

Model View Controller Implementation

You can read about the pattern on Wikipedia. Basically, you decouple the logic part from the user interaction which has multiple benefits.

MVC Diagram

  • Model manages the data, logic and rules of the system. Extends ObservablePattern class.
  • View displays the model data. You can have various different Views on a system as long as every one of them extend ObserverPattern class.
  • Controller Accepts the input and converts it to commands for the Model.
  • Events Events the messages the Model passes to the View(s).

Setting up:

//Object creations in main .ino
Model model;
//The Controller knows about the Model
Controller controller(&model);
//The View knows about the Controller
SerialUI serialUI(&controller);
//Attach view in main .ino
model.attachObserver(&serialUI);
//You could also detach with
model.detachObserver(&serialUI);

Flow of interactions:

//Change the Model from the Controller
_model->someMethod(someVars);
//The Model does some stuff and creates an Event to warn the Views it has changed
EventWhatever event(someMoreVars);
notifyObservers(&event);
//The Views receive the Event and processes it whithin
void update(Event *const);

About

Barebones project that implements the MVC pattern under Platformio ecosystem


Languages

Language:C++ 100.0%