-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixMiniR4.cpp
More file actions
129 lines (114 loc) · 3.69 KB
/
MatrixMiniR4.cpp
File metadata and controls
129 lines (114 loc) · 3.69 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
122
123
124
125
126
127
128
129
/**
* @file MatrixMiniR4.cpp
* @brief Implementation of the MatrixMiniR4 class for initializing and controlling hardware modules.
*
* This file contains the implementation of the MatrixMiniR4 class, which manages various hardware components
* such as motors, servos, LEDs, and displays. The `begin` method initializes these components, configures the
* OLED display, and sets up the MJ2 gamepad interface. If the initialization fails, it displays an error message
* on the OLED and sounds a buzzer.
*
* @note The initialization sequence includes waiting for motors and servos controller to be ready and displaying an error
* message if the MMLower initialization fails.
*
* @see MatrixMiniR4.h
*/
#include "MatrixMiniR4.h"
#include "Modules/MMLower.h"
MatrixMiniR4::MatrixMiniR4() {}
/**
* @brief Initialize the MatrixMiniR4 system and its components.
*
* This function initializes the MMLower (STM32) system, sets up the RGB LED and buzzer,
* and pre init for all DC motors and servos =. It also configures the
* OLED display and the MJ2 gamepad.
*
* @return true if initialization was successful, false otherwise.
*/
bool MatrixMiniR4::begin()
{
MMLower::RESULT result = mmL.Init();
LED.begin(7);
LED.setColor(1, 0, 0, 0);
LED.setColor(2, 0, 0, 0);
Buzzer.begin(6);
Motion.begin();
while (!M1.begin());
while (!M2.begin());
while (!M3.begin());
while (!M4.begin());
RC1.begin();
RC2.begin();
RC3.begin();
RC4.begin();
OLED = Adafruit_SSD1306(128, 32, &Wire1, -1);
OLED.begin(SSD1306_SWITCHCAPVCC, MATRIXMINIR4_OLED_ADDRESS);
OLED.setTextColor(SSD1306_WHITE); //Default Color White
OLED.clearDisplay();
OLED.display();
/* CLK: D3R(11) , CMD: D2R(4) , SET: D3L(12) , DAT: D2L(5) */
PS2.config_gamepad(11, 4, 12, 5, false, false);
//Check the Init is ok or not.
if (result != MMLower::RESULT::OK) {
OLED.setCursor(4, 8);
OLED.setTextSize(2);
OLED.print(F("Init Error"));
OLED.display();
while (true) {
for (uint8_t i = 0; i < 3; i++) {
Buzzer.Tone(700, 100);
delay(100);
Buzzer.NoTone();
delay(100);
}
delay(3000);
}
}
delay(200);
//Check the FW version is outdated or not.
String FWVersion_S;
MMLower::RESULT resultFWCheck = mmL.GetFWVersion(FWVersion_S);
if (resultFWCheck == MMLower::RESULT::OK) {
uint8_t FWmajorVersion, FWminorVersion;
uint8_t FWVersion_dotIndex = FWVersion_S.indexOf('.');
if (FWVersion_dotIndex != -1) {
FWmajorVersion = FWVersion_S.substring(0, FWVersion_dotIndex).toInt();
FWminorVersion = FWVersion_S.substring(FWVersion_dotIndex + 1).toInt();
if (FWmajorVersion < 6 || (FWmajorVersion == 6 && FWminorVersion < 0)) {
for (uint8_t i = 0; i < 3; i++) {
Buzzer.Tone(550, 100);
delay(60);
Buzzer.NoTone();
delay(60);
}
unsigned long lastUpdate = millis();
bool showFirst = true;
OLED.clearDisplay();
OLED.setTextSize(1);
while (BTN_DOWN.getState() == false) {
if (millis() - lastUpdate >= 3000) {
lastUpdate = millis();
showFirst = !showFirst;
}
OLED.clearDisplay();
if (showFirst) {
OLED.setCursor(11, 5);
OLED.print(F("Firmware Outdated!"));
OLED.setCursor(11, 18);
OLED.print(F(" Required: v6.0+ "));
} else {
OLED.setCursor(11, 5);
OLED.print(F(" Open MATRIXblock "));
OLED.setCursor(6, 18);
OLED.print(F("File->FirmwareUpdate"));
}
OLED.display();
delay(1);
}
OLED.clearDisplay();
OLED.display();
}
}
}
return true;
}
MatrixMiniR4 MiniR4; ///< The MiniR4 Main Object.