Skip to content

Commit dd423ba

Browse files
committed
start mic task immediately
1 parent 4e2b2b9 commit dd423ba

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

noisemeter-device/noisemeter-device.ino

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,6 @@ constexpr auto OTA_INTERVAL_SEC = HR_TO_SEC(24);
4949
/** Maximum number of data packets to retain when WiFi is unavailable. */
5050
constexpr auto MAX_SAVED_PACKETS = DAY_TO_SEC(14) / UPLOAD_INTERVAL_SEC;
5151

52-
/** SPLMeter instance to manage decibel level measurement. */
53-
static SPLMeter SPL;
5452
/** Storage instance to manage stored credentials. */
5553
static Storage Creds;
5654
/** Linked list of completed data packets.
@@ -104,6 +102,13 @@ void setup()
104102
pinMode(PIN_BUTTON, INPUT_PULLUP);
105103

106104
SERIAL.begin(115200);
105+
106+
if (xTaskCreate(measurementHandler, "dba", 1024, nullptr,
107+
uxTaskPriorityGet(nullptr), &measurementTask) == pdFAIL)
108+
{
109+
SERIAL.println("xTaskCreate failed!");
110+
}
111+
107112
delay(2000);
108113
SERIAL.println();
109114
SERIAL.print("Noisemeter ");
@@ -117,9 +122,6 @@ void setup()
117122
SERIAL.println(Creds);
118123
#endif
119124

120-
SPL.initMicrophone();
121-
packets.emplace_front();
122-
123125
#ifndef UPLOAD_DISABLED
124126
bool isAPNeeded = false;
125127

@@ -161,19 +163,13 @@ void setup()
161163
#endif // !UPLOAD_DISABLED
162164

163165
digitalWrite(PIN_LED1, HIGH);
164-
165-
if (xTaskCreate(measurementHandler, "dba", 1024, nullptr,
166-
uxTaskPriorityGet(nullptr), &measurementTask) == pdFAIL)
167-
{
168-
SERIAL.println("xTaskCreate failed!");
169-
}
170166
}
171167

172168
void loop()
173169
{
174170
#ifndef UPLOAD_DISABLED
175171
static int wakeupCount = 0;
176-
172+
177173
vTaskDelay(pdMS_TO_TICKS(SEC_TO_MS(UPLOAD_INTERVAL_SEC)));
178174

179175
packets.front().timestamp = Timestamp();
@@ -242,6 +238,11 @@ void loop()
242238

243239
void measurementHandler(void *)
244240
{
241+
static SPLMeter SPL; // Large object, must be static
242+
243+
SPL.initMicrophone();
244+
packets.emplace_front();
245+
245246
while (1) {
246247
if (const auto db = SPL.readMicrophoneData(); db) {
247248
packets.front().add(*db);

0 commit comments

Comments
 (0)