Mydin-classes-diagram
About this section
Before reading the classes documentation, it may be opportune to understand how the MyDin core is designed.
That will help to understand how the code works and where are located the key items when programming your MyDin project with MicroPython.
Class diagram
Here a short description of the main classes and their responsibilities:
- DinControler : Base class responsible for starting the asynchronous execution. It puts every mechanism in place to initiate the setup then start asynchronous tasks including the user_loop task. A this level, the DinCOntroler doesn't know anything about the underlaying microcontroler used. DinControler also takes care of the process termination.
- PicoControler : Base class for myDin solution based on Raspberry-Pi Pico microcontroler. PicoControler inherits of DinControler (and all its behavior). At the PicoContoler level, we can create object related to microcontroler hardware that will be shared accross all the descendant classes. At the PicoControler level we can define the common I2C bus, RTC clock, internal temperature sensor, watchdog and e.
- Pico3Mod : Specialized implementation of the PicoControler for a 3 modules size DIN. As the microcontroler is now placed on a PCB with fixed dimensions and obvious placement constraints (due to the 3 modules Din) then the specific hardware design like buttons, LEDs, interface connectors can be defined by this class. This class also defines the interface between the controler and the 3 modules backplane.
- Pico6Mod : Another specialized implementation of the PicoControler for a 6 modules size DIN. Thanks to additional place available, it is also possible to add a LCD/OLED display, mini-joystick aside the usual interface.
- TwoRelay3Mod is a specialized Backplane implementation for a 3 modules DIN. Backplane 3 modules shares a common interface with the 3 modules Controler (Pico3Mod and any 3 modules Controler will use exactly the same interface).
The attach( controler ) method is called by configure() to expose the backplane properties into the controler object.
DinControler
Header
Details about DinControler class are available at "asynchronous tasks" details. Here is the process behind the run() method.
Attributes
backplane : object
Reference to the backplane instance created by the configure() function. The backplane is an instance of type BackplaneClass.
is_async : boolean
True when the DinControler is running asyncio code otherwise, the DinControler is running "procedural" code.
This property is set to True by the run() method.
loop_exception : object
If an exception is raised by the userloop during asynchronous execution then the run() exits and loop_exception contains a reference to the catched exception.
When the userloop exits for another reason (eg: APP_RUN=STOP) then the loop_exception should still be None.
Remark: loop_exception is set to None when run() starts.
loop_time_ms : int
Being configured to 20 milliseconds, this async.sleep_ms() time is inserted after each userloop iteration. It allows other tasks to get execution time.
The value of loop_time_ms can be ajusted to provide more time to other tasks.
Methods
__init__()
Constructor of the DinControler class. This constructor is not called directly, the DinControler class is used as a based call for a given MCU category class (RP2040, ESP32, ...).
def __init__( self, BackplaneClass, RunApp_pin ):
- BackplaneClass : Class of the backplane to be associated with the controler (eg: TwoRelay3Mod).
- RunApp_pin : identification of the input pin to be used as RUN_APP swich. It will be configured with Internal Pullup. Software will not start (or will stop) when the pin is tied to ground.
__setup__()
Setup the userloop and other key parameter for an asynchronous code execution with run(). The userloop is the main user code repetitively executed by the asynchronous execution.
def setup( self, setup=None, loop=None, on_tasks_create=None ):
- setup : xxx
- loop : xxx
- on_task_create : cccc