My Project
Loading...
Searching...
No Matches
BLELocomotive.h
Go to the documentation of this file.
1#pragma once
2
3#include <Arduino.h>
4
5#include "BLEHub.h"
7#include "MCLedBase.h"
8#include "MController.h"
9
11{
12 public:
14
15 // List of references to hubs inside this loco.
16 std::vector<BLEHub *> Hubs;
17
18 // Returns a boolean value indicating whether we are connected to all BLE hubs.
19 bool AllHubsConnected();
20
21 // Sets the given target speed for all motor channels for all hubs.
22 void Drive(const int16_t minSpeed, const int16_t pwrPerc);
23
24 // Triggers the given event for this loco.
25 void TriggerEvent(MCTriggerSource source, std::string eventType, std::string eventId, std::string value);
26
27 // Makes all channels on all hubs with lights attached blink for the given duration.
28 void BlinkLights(int durationInMs);
29
30 // Sets a new color for hubs that have an onboard LED.
31 void SetHubLedColor(HubLedColor color);
32
33 // If true, immediately sets the current speed for all channels on all hubs to zero and makes all loco lights blink.
34 // If false, releases the emergency brake, returning the loco to normal operations.
35 void SetEmergencyBrake(const bool enabled);
36
37 // Returns the loco name.
38 std::string GetLocoName();
39
40 // Returns the loco address.
41 uint GetLocoAddress();
42
43 // Returns the number of hubs in the loco.
44 uint GetHubCount();
45
46 // Returns the hub at the given index.
47 BLEHub *GetHub(uint index);
48
49 private:
50 // Initialized the leds inside this loco.
51 // void initLights();
52
53 // Initialized the hubs inside this loco.
54 void initHubs();
55
56 void handleConnectCallback(bool connected);
57
58 // If true, immediately sets the current speed for all channels on all hubs to zero and makes all loco lights blink.
59 // If false, releases the manual brake, returning the loco to normal operations.
60 void setManualBrake(const bool enabled);
61
62 // Returns a reference to a hub by its address.
63 BLEHub *getHubByAddress(std::string address);
64
65 // Returns a list of references to functions of the given type configured for this loco.
66 // std::vector<MCFunctionBinding *> getFunctions(MCFunction f);
67
68 // Returns a list of references to leds inside this loco.
69 std::vector<MCLedBase *> _espLeds;
70
71 // Reference to the configuration of this loco.
73
74 // Reference to the controller controling this loco.
75 MController *_controller;
76};
@ connected
Definition MController.h:16
Definition BLEHub.h:56
Definition BLELocomotiveConfiguration.h:7
Definition BLELocomotive.h:11
bool AllHubsConnected()
Definition BLELocomotive.cpp:15
std::vector< BLEHub * > Hubs
Definition BLELocomotive.h:16
std::string GetLocoName()
Definition BLELocomotive.cpp:118
uint GetLocoAddress()
Definition BLELocomotive.cpp:123
void SetEmergencyBrake(const bool enabled)
Definition BLELocomotive.cpp:110
void SetHubLedColor(HubLedColor color)
Definition BLELocomotive.cpp:96
void Drive(const int16_t minSpeed, const int16_t pwrPerc)
Definition BLELocomotive.cpp:26
void BlinkLights(int durationInMs)
Definition BLELocomotive.cpp:82
uint GetHubCount()
Definition BLELocomotive.cpp:128
BLEHub * GetHub(uint index)
Definition BLELocomotive.cpp:133
BLELocomotive(BLELocomotiveConfiguration *config, MController *controller)
Definition BLELocomotive.cpp:9
void TriggerEvent(MCTriggerSource source, std::string eventType, std::string eventId, std::string value)
Definition BLELocomotive.cpp:56
Definition MController.h:20
HubLedColor
Definition enums.h:40
MCTriggerSource
Definition enums.h:77
MTC4BTController * controller
Definition main.cpp:17