-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhub.cpp
More file actions
121 lines (101 loc) · 3.02 KB
/
hub.cpp
File metadata and controls
121 lines (101 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "hub.h"
#include <stdint.h>
#include "Lpf2Hub.h"
#include "menu.h"
#include "display.h"
static Lpf2Hub PUHub[2];
static byte PUport[4] = {(byte)PoweredUpHubPort::A, (byte)PoweredUpHubPort::B, (byte)PoweredUpHubPort::A, (byte)PoweredUpHubPort::B };
static InitState HubInitState[2] = {notConnected, notConnected};
static hubType type[2] = {noHub, noHub};
Lpf2Hub *getHub(uint8_t port)
{
if (type[0] == type[1] == PoweredUpHub && port > 1)
{
return &PUHub[1];
}
else
{
return &PUHub[0];
}
}
hubType getHubType(uint8_t hub)
{
return type[hub];
}
byte getHubPort(uint8_t port)
{
return PUport[port];
}
void connectedHub(uint8_t i)
{
if (!PUHub[i].isConnected())
{
PUHub[i].init();
}
}
void configureHub (uint8_t id)
{
HubInitState[id] = Configured;
}
void tryConnectHubs()
{
if (PUHub[0].isConnecting())
{
if (PUHub[0].getHubType() == HubType::POWERED_UP_HUB)
{
PUHub[0].connectHub();
PUHub[0].setLedColor(GREEN);
Serial.println("powered up hub 1 connected.");
PUHub[0].setLedColor(GREEN);
display_set(1, 0, 0, 255, 0);
display_set(2, 0, 0, 255, 0, true);
PUport[0] = (byte)PoweredUpHubPort::A;
PUport[1] = (byte)PoweredUpHubPort::B;
type[0] = PoweredUpHub;
PUHub[0].activatePortDevice(PUport[0], tachoMotorCallback);
PUHub[0].activatePortDevice(PUport[1], tachoMotorCallback);
setSubStateMax(Menu2);
connectedHub(1);
}
else if (PUHub[0].getHubType() == HubType::CONTROL_PLUS_HUB)
{
PUHub[0].connectHub();
PUHub[0].setLedColor(GREEN);
Serial.println("control plus hub connected.");
PUHub[0].setLedColor(GREEN);
display_set(1, 0, 0, 255, 0);
display_set(2, 0, 0, 255, 0);
display_set(3, 0, 0, 255, 0);
display_set(4, 0, 0, 255, 0, true);
// Switch Port Configuration to Control+
PUport[0] = (byte)ControlPlusHubPort::A;
PUport[1] = (byte)ControlPlusHubPort::B;
PUport[2] = (byte)ControlPlusHubPort::C;
PUport[3] = (byte)ControlPlusHubPort::D;
type[0] = ControlPlusHub;
PUHub[0].activatePortDevice(PUport[0], tachoMotorCallback);
PUHub[0].activatePortDevice(PUport[1], tachoMotorCallback);
PUHub[0].activatePortDevice(PUport[2], tachoMotorCallback);
PUHub[0].activatePortDevice(PUport[3], tachoMotorCallback);
setSubStateMax(Menu4);
}
}
else if (PUHub[1].isConnecting())
{
if (PUHub[1].getHubType() == HubType::POWERED_UP_HUB)
{
PUHub[1].connectHub();
PUHub[1].setLedColor(GREEN);
Serial.println("powered up hub 2 connected.");
PUHub[1].setLedColor(GREEN);
display_set(3, 0, 0, 255, 0);
display_set(4, 0, 0, 255, 0, true);
PUport[2] = (byte)PoweredUpHubPort::A;
PUport[3] = (byte)PoweredUpHubPort::B;
type[1] = PoweredUpHub;
PUHub[2].activatePortDevice(PUport[0], tachoMotorCallback);
PUHub[3].activatePortDevice(PUport[1], tachoMotorCallback);
setSubStateMax(Menu4);
}
}
}