Skip to content

Commit 3dbdb3a

Browse files
committed
Add cube config selections
1 parent c297d22 commit 3dbdb3a

File tree

2 files changed

+57
-15
lines changed

2 files changed

+57
-15
lines changed

lib/cube/cube.cpp

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@
44
const __attribute__((section(".rodata_custom_desc"))) CubePartition cubePartition = {CUBE_MAGIC_COOKIE};
55

66
// Create a new Cube object with optional devMode
7-
Cube::Cube() : serial(String(ESP.getEfuseMac() % 0x1000000, HEX)),
8-
currentPattern(patterns::snake),
9-
wifiReady(false),
10-
server(80),
11-
dashboard(&server),
12-
otaToggle(&dashboard, BUTTON_CARD, "OTA Update Enabled"),
13-
GHUpdateToggle(&dashboard, BUTTON_CARD, "Github Update Enabled"),
14-
developmentToggle(&dashboard, BUTTON_CARD, "Use Development Builds"),
15-
signedFWOnlyToggle(&dashboard, BUTTON_CARD, "Signed FW only"),
16-
fwVersion(&dashboard, "Firmware Version", FW_VERSION),
17-
brightnessSlider(&dashboard, SLIDER_CARD, "Brightness:", "", 0, 255)
18-
7+
Cube::Cube() : serial(String(ESP.getEfuseMac() % 0x1000000, HEX)),
8+
currentPattern(patterns::snake),
9+
wifiReady(false),
10+
server(80),
11+
dashboard(&server),
12+
otaToggle(&dashboard, BUTTON_CARD, "OTA Update Enabled"),
13+
GHUpdateToggle(&dashboard, BUTTON_CARD, "Github Update Enabled"),
14+
developmentToggle(&dashboard, BUTTON_CARD, "Use Development Builds"),
15+
signedFWOnlyToggle(&dashboard, BUTTON_CARD, "Signed FW only"),
16+
fwVersion(&dashboard, "Firmware Version", FW_VERSION),
17+
brightnessSlider(&dashboard, SLIDER_CARD, "Brightness:", "", 0, 255),
18+
latchSlider(&dashboard, SLIDER_CARD, "Latch Blanking:", "", 1, 4),
19+
use20MHzToggle(&dashboard, BUTTON_CARD, "Use 20MHz Clock"),
20+
rebootButton(&dashboard, BUTTON_CARD, "Reboot Cube"),
21+
resetWifiButton(&dashboard, BUTTON_CARD, "Reset Wifi")
1922
{
2023
}
2124

@@ -67,11 +70,15 @@ void Cube::initDisplay()
6770
this->printf("Configuring HUB_75\n");
6871
HUB75_I2S_CFG::i2s_pins _pins = {R1_PIN, G1_PIN, B1_PIN, R2_PIN, G2_PIN, B2_PIN, A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, LAT_PIN, OE_PIN, CLK_PIN};
6972
HUB75_I2S_CFG mxconfig(PANEL_WIDTH, PANEL_HEIGHT, PANELS_NUMBER, _pins);
70-
mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M;
73+
if(cubePrefs.use20MHz) {
74+
mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_20M;
75+
} else {
76+
mxconfig.i2sspeed = HUB75_I2S_CFG::HZ_10M;
77+
}
7178
mxconfig.clkphase = false;
7279
dma_display = new MatrixPanel_I2S_DMA(mxconfig);
7380
setBrightness(this->cubePrefs.brightness);
74-
dma_display->setLatBlanking(2);
81+
dma_display->setLatBlanking(cubePrefs.latchBlanking);
7582

7683
// Allocate memory and start DMA display
7784
if (not dma_display->begin())
@@ -84,7 +91,6 @@ void Cube::initWifi()
8491
pinMode(WIFI_LED, OUTPUT);
8592
digitalWrite(WIFI_LED, 0);
8693
this->printf("Connecting to WiFi...\n");
87-
WiFiManager wifiManager;
8894
wifiManager.setHostname("cube");
8995
wifiManager.setClass("invert");
9096
wifiManager.autoConnect("Cube");
@@ -131,11 +137,40 @@ void Cube::initUI()
131137
this->setBrightness(value);
132138
this->brightnessSlider.update(value);
133139
this->dashboard.sendUpdates(); });
140+
latchSlider.attachCallback([&](int value)
141+
{
142+
this->dma_display->setLatBlanking(value);
143+
this->cubePrefs.latchBlanking = value;
144+
this->updatePrefs();
145+
this->latchSlider.update(value);
146+
this->dashboard.sendUpdates(); });
147+
use20MHzToggle.attachCallback([&](bool value)
148+
{
149+
this->cubePrefs.use20MHz = value;
150+
this->updatePrefs();
151+
this->use20MHzToggle.update(value);
152+
this->dashboard.sendUpdates(); });
153+
rebootButton.attachCallback([&](bool value)
154+
{
155+
this->printf("Rebooting...");
156+
ESP.restart();
157+
this->dashboard.sendUpdates(); });
158+
resetWifiButton.attachCallback([&](bool value)
159+
{
160+
this->printf("Resetting WiFi...");
161+
wifiManager.resetSettings();
162+
ESP.restart();
163+
this->dashboard.sendUpdates(); });
134164
this->otaToggle.update(this->cubePrefs.ota);
135165
this->developmentToggle.update(this->cubePrefs.development);
136166
this->GHUpdateToggle.update(this->cubePrefs.github);
137167
this->brightnessSlider.update(this->cubePrefs.brightness);
138168
this->signedFWOnlyToggle.update(this->cubePrefs.signedFWOnly);
169+
this->latchSlider.update(this->cubePrefs.latchBlanking);
170+
this->use20MHzToggle.update(this->cubePrefs.use20MHz);
171+
this->rebootButton.update(true);
172+
this->resetWifiButton.update(true);
173+
139174
dashboard.sendUpdates();
140175
}
141176

lib/cube/cube.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ struct CubePrefs
5858
bool ota = 0;
5959
bool github = 1;
6060
bool signedFWOnly = 1;
61+
uint8_t latchBlanking = 2;
62+
bool use20MHz = 0;
6163
void print(String prefix) {
6264
Serial.printf("%s\nBrightness: %d\nDevelopment: %d\nOTA: %d\nGithub: %d\nSigned FW Only: %d\n", prefix.c_str(), brightness, development, ota, github, signedFWOnly);
6365
}
@@ -84,6 +86,7 @@ class Cube {
8486
void printf(const char *format, ...);
8587

8688
private:
89+
WiFiManager wifiManager;
8790
CubePrefs cubePrefs;
8891
String serial;
8992
patterns currentPattern;
@@ -96,6 +99,10 @@ class Cube {
9699
Card signedFWOnlyToggle;
97100
Statistic fwVersion;
98101
Card brightnessSlider;
102+
Card latchSlider;
103+
Card use20MHzToggle;
104+
Card rebootButton;
105+
Card resetWifiButton;
99106
TaskHandle_t checkForUpdatesTask;
100107
TaskHandle_t checkForOTATask;
101108
TaskHandle_t showPatternTask;

0 commit comments

Comments
 (0)