My Project
Loading...
Searching...
No Matches
MController.h
Go to the documentation of this file.
1#pragma once
2#include <Arduino.h>
3
5#include "MCConfiguration.h"
6#include "MCLedBase.h"
7#include "MCLocoAction.h"
9#include "MattzoWifiClient.h"
10
18
20{
21 public:
23
24 // Returns the current controller connection status.
26
27 // Mattzo Controller setup initialization method.
28 void Setup(MCConfiguration *config);
29
30 // Updates emergency brake based on the current controller connection status and controls leds.
31 void Loop();
32
33 // Loop is not running in setup but the led needs to be set to indicate searching for network (or something)
34 void setStatusLedInSetup(int powerPerc);
35
36 // Returns a boolean value indicating whether the e-brake flag is currently set or not.
37 bool GetEmergencyBrake();
38
39 // Sets the emergency brake flag to the given value.
40 void SetEmergencyBrake(const bool enabled);
41
42 // Executes the given action locally on this controller.
43 void Execute(MCLocoAction *action);
44
45 // Abstract method required for derived controller implementations to handle e-brake.
46 virtual void HandleSys(const bool ebrake) = 0;
47
48 // Abstract method required to handle the given trigger (if loco is under control of this controller).
49 virtual void HandleTrigger(int locoAddress, MCTriggerSource source, std::string eventType, std::string eventId, std::string value) = 0;
50
51 private:
52 // Initializes the pin channels.
53 void initChannelControllers();
54
55 // Returns the controller for the requested channel.
56 MCChannelController *findControllerByChannel(MCChannel *channel);
57
58 // Returns the led instance for the requested pin.
59 MCLedBase *findLedByPinNumber(int pin);
60
61 // Initializes an led instance, if it doesn't exist yet.
62 void initLed(int pwmChannel, int pin, bool inverted);
63
64 // Initializes a status led instance, if it doesn't exist yet.
65 void initStatusLed(int pwmChannel, int pin);
66
67 // List of references to leds attached to this controller.
68 std::vector<MCLedBase *> _espLeds;
69
70 // List of references to led controllers.
71 std::vector<MCChannelController *> _channelControllers;
72
73 // Boolean value indicating whether emergency brake is currently enabled or not.
74 bool _ebrake;
75
76 // Reference to the configuration of this controller.
77 MCConfiguration *_config;
78};
MCConnectionStatus
Definition MController.h:11
@ connecting_wifi
Definition MController.h:14
@ connecting_mqtt
Definition MController.h:15
@ uninitialized
Definition MController.h:12
@ connected
Definition MController.h:16
@ initializing
Definition MController.h:13
Definition MCChannelController.h:9
Definition MCChannel.h:7
Definition MCLedBase.h:4
Definition MCLocoAction.h:9
Definition MController.h:20
virtual void HandleTrigger(int locoAddress, MCTriggerSource source, std::string eventType, std::string eventId, std::string value)=0
void Loop()
Definition MController.cpp:45
void SetEmergencyBrake(const bool enabled)
Definition MController.cpp:121
void Execute(MCLocoAction *action)
Definition MController.cpp:126
void setStatusLedInSetup(int powerPerc)
Definition MController.cpp:103
static MCConnectionStatus GetConnectionStatus()
Definition MController.cpp:13
bool GetEmergencyBrake()
Definition MController.cpp:115
virtual void HandleSys(const bool ebrake)=0
void Setup(MCConfiguration *config)
Definition MController.cpp:35
MController()
Definition MController.cpp:9
MCTriggerSource
Definition enums.h:77
Definition MCConfiguration.h:8