My Project
Loading...
Searching...
No Matches
MCChannelController.h
Go to the documentation of this file.
1#pragma once
2
3#include <Arduino.h>
4
5#include "MCChannelConfig.h"
6
7// Channel controller
9{
10 public:
12
13 // Returns the current hub led color.
15
16 // Sets a new hub led color.
17 void SetHubLedColor(HubLedColor color);
18
19 // Returns the device attached to the channel.
21
22 // Returns the channel controlled by this controller.
24
25 // Set the min pwr percentage. When a pwr percentage is set below this value, we either set current pwr to zero (when decreasing power) or to the given value (when increasing power).
26 void SetMinPwrPerc(int16_t minPwrPerc);
27
28 // Gets the current target pwr percentage (sign indicates direction: >0: forward, <0: backwards).
29 int16_t GetTargetPwrPerc();
30
31 // Sets a new target pwr percentage (sign indicates direction: >0: forward, <0: backwards).
32 void SetTargetPwrPerc(int16_t targetPwrPerc);
33
34 // Returns the current pwr percentage (sign indicates direction: >0: forward, <0: backwards).
35 int16_t GetCurrentPwrPerc();
36
37 // Sets the current pwr percentage (directly) to the specified value (sign indicates direction: >0: forward, <0: backwards).
38 void SetCurrentPwrPerc(int16_t currentPwrPerc);
39
40 // Updates the current pwr percentage one step towards the target pwr (to be used in a loop).
42
43 // Returns the absolute current pwr percentage (no direction indication).
44 uint8_t GetAbsCurrentPwrPerc();
45
46 // Returns a boolean value indicating whether we're driving forward or not.
47 bool IsDrivingForward();
48
49 void Blink();
50
51 // Sets the current manual brake status.
52 void ManualBrake(bool enabled);
53
54 // Sets the current e-brake status.
55 void EmergencyBrake(bool enabled);
56
57 private:
58 // Returns a boolean value indicating whether the channel is currently accelarating in either direction.
59 bool isAccelarating();
60
61 // Returns a boolean value indicating whether the channel has reached its target pwr percentage.
62 bool isAtTargetPwrPerc();
63
64 // Return the normalized pwr value, bounded by the min and max channel pwr.
65 int16_t normalizePwrPerc(int16_t pwrPerc);
66
67 // Reference to the configuration of the channel controlled by this channel controller.
68 MCChannelConfig *_config;
69
70 bool _mbrake;
71 bool _ebrake;
72 ulong _blinkUntil;
73 unsigned long _lastUpdate = 0;
74 int16_t _minPwrPerc;
75 int16_t _targetPwrPerc;
76 int16_t _currentPwrPerc;
77 HubLedColor _hubLedColor = HubLedColor::BLACK; // off
78
79 // The following (derived) class can access private members of MCChannelController.
81 friend class MCPinController;
82};
Definition BLEHubChannelController.h:10
Definition MCChannelConfig.h:8
Definition MCChannelController.h:9
void EmergencyBrake(bool enabled)
Definition MCChannelController.cpp:156
DeviceType GetAttachedDevice()
Definition MCChannelController.cpp:32
void ManualBrake(bool enabled)
Definition MCChannelController.cpp:151
bool UpdateCurrentPwrPerc()
Definition MCChannelController.cpp:90
void SetCurrentPwrPerc(int16_t currentPwrPerc)
Definition MCChannelController.cpp:85
int16_t GetCurrentPwrPerc()
Definition MCChannelController.cpp:59
void SetTargetPwrPerc(int16_t targetPwrPerc)
Definition MCChannelController.cpp:52
uint8_t GetAbsCurrentPwrPerc()
Definition MCChannelController.cpp:141
MCChannelController(MCChannelConfig *config)
Definition MCChannelController.cpp:9
void SetHubLedColor(HubLedColor color)
Definition MCChannelController.cpp:27
HubLedColor GetHubLedColor()
Definition MCChannelController.cpp:22
bool IsDrivingForward()
Definition MCChannelController.cpp:146
void SetMinPwrPerc(int16_t minPwrPerc)
Definition MCChannelController.cpp:42
MCChannel * GetChannel()
Definition MCChannelController.cpp:37
int16_t GetTargetPwrPerc()
Definition MCChannelController.cpp:47
Definition MCChannel.h:7
Definition MCPinController.h:9
HubLedColor
Definition enums.h:40
@ BLACK
Definition enums.h:41
DeviceType
Definition enums.h:20