Skip to content

Commit 8a1ab3e

Browse files
committed
Fixed Mic Spectrum and Recorder and Orange LED
#1271
1 parent 87349af commit 8a1ab3e

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/core/led_control.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ void setLedColorConfig() {
159159
else if (bruceConfig.ledColor == CRGB::Red) idx = 3;
160160
else if (bruceConfig.ledColor == CRGB::Green) idx = 4;
161161
else if (bruceConfig.ledColor == CRGB::Blue) idx = 5;
162-
else if (bruceConfig.ledColor == LED_COLOR_WHEEL) idx = 6; // colorwheel
162+
else if (bruceConfig.ledColor == CRGB::Orange) idx = 6;
163+
else if (bruceConfig.ledColor == LED_COLOR_WHEEL) idx = 7; // colorwheel
163164
else idx = 7; // custom color
164165

165166
options = {
@@ -169,12 +170,13 @@ void setLedColorConfig() {
169170
{"Red", [=]() { bruceConfig.setLedColor(CRGB::Red); }, bruceConfig.ledColor == CRGB::Red },
170171
{"Green", [=]() { bruceConfig.setLedColor(CRGB::Green); }, bruceConfig.ledColor == CRGB::Green },
171172
{"Blue", [=]() { bruceConfig.setLedColor(CRGB::Blue); }, bruceConfig.ledColor == CRGB::Blue },
173+
{"Orange", [=]() { bruceConfig.setLedColor(CRGB::Orange); }, bruceConfig.ledColor == CRGB::Orange},
172174
{"Color Wheel",
173175
[=]() { bruceConfig.setLedColor(LED_COLOR_WHEEL); },
174176
bruceConfig.ledColor == LED_COLOR_WHEEL },
175177
};
176178

177-
if (idx == 7) options.emplace_back("Custom Color", [=]() { backToMenu(); }, true);
179+
if (idx == 8) options.emplace_back("Custom Color", [=]() { backToMenu(); }, true);
178180
addOptionToMainMenu();
179181

180182
loopOptions(options, idx);

src/modules/others/mic.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,14 +206,16 @@ void mic_test() {
206206
}
207207
Serial.println("Mic Spectrum start");
208208
InitI2SMicroPhone();
209-
210209
// Alloc buffers in PSRAM if available
211-
i2s_buffer = (int8_t *)heap_caps_malloc(FFT_SIZE * sizeof(int16_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
212-
fftHistory =
213-
(uint8_t *)heap_caps_malloc(HISTORY_LEN * SPECTRUM_HEIGHT, MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
214-
210+
if (psramFound()) {
211+
i2s_buffer = (int8_t *)ps_malloc(FFT_SIZE * sizeof(int16_t));
212+
fftHistory = (uint8_t *)ps_malloc(HISTORY_LEN * SPECTRUM_HEIGHT);
213+
} else {
214+
i2s_buffer = (int8_t *)malloc(FFT_SIZE * sizeof(int16_t));
215+
fftHistory = (uint8_t *)malloc(HISTORY_LEN * SPECTRUM_HEIGHT);
216+
}
215217
if (!i2s_buffer || !fftHistory) {
216-
Serial.println("Fail to alloc buffers, exiting");
218+
displayError("Fail to alloc buffers, exiting", true);
217219
return;
218220
}
219221

@@ -297,7 +299,13 @@ void mic_record() {
297299
}
298300
InitI2SMicroPhone();
299301

300-
i2s_buffer = (int8_t *)heap_caps_malloc(FFT_SIZE * sizeof(int16_t), MALLOC_CAP_SPIRAM | MALLOC_CAP_8BIT);
302+
// Alloc buffers in PSRAM if available
303+
if (psramFound()) i2s_buffer = (int8_t *)ps_malloc(FFT_SIZE * sizeof(int16_t));
304+
else i2s_buffer = (int8_t *)malloc(FFT_SIZE * sizeof(int16_t));
305+
if (!i2s_buffer) {
306+
displayError("Fail to alloc buffers, exiting", true);
307+
return;
308+
}
301309

302310
FS *fs = nullptr;
303311
if (!getFsStorage(fs) || fs == nullptr) {

0 commit comments

Comments
 (0)