#include "messageQueue.h"
MessageQueue dataQueue;
// --- Task 1: The Producer (Sensor Reader) ---
void producer_task() {
static unsigned long lastReadTime = 0;
const long READ_INTERVAL = 1000; // Read every 1 second
if (millis() - lastReadTime >= READ_INTERVAL) {
lastReadTime = millis();
SensorMessage data;
data.temperature = (float)random(200, 300) / 10.0; // Mock sensor data
data.sensorID = 1;
if (dataQueue.send(data)) {
Serial.print("PRODUCER: Sent temp: ");
Serial.println(data.temperature);
} else {
Serial.println("PRODUCER: ERROR - Queue full!");
}
}
}
// --- Task 2: The Consumer (Display Updater) ---
void consumer_task() {
SensorMessage receivedData;
// Check the queue for new messages without blocking
if (dataQueue.receive(receivedData)) {
// Only run display update logic when new data is available
Serial.print("CONSUMER: Received and processing temp: ");
Serial.println(receivedData.temperature);
// digitalWrite(DISPLAY_PIN, HIGH); // Display update logic here
}
}
void setup() {
Serial.begin(9600);
// pinMode(DISPLAY_PIN, OUTPUT);
randomSeed(analogRead(0));
}
void loop() {
// Both tasks are called on every loop, running non-blocking checks.
producer_task();
consumer_task();
// Other high-priority code (like the State Machine) runs here as well!
// fsm.run();
}