added new render mode test, and added code for the esp to handle multiple pin shorts
This commit is contained in:
parent
57917505ed
commit
22a25532ba
7 changed files with 383 additions and 14 deletions
|
|
@ -8,7 +8,8 @@ const char* mqttServer = "10.1.13.173";
|
|||
const int mqttPort = 1883;
|
||||
const char* mqttTopic = "test";
|
||||
|
||||
const int gpioPin = 25; // GPIO pin to check for shorting
|
||||
const int gpioPins[] = {25, 26, 27, 14}; // GPIO pins to check for shorting
|
||||
const unsigned int numPins = sizeof(gpioPins) / sizeof(gpioPins[0]);
|
||||
const unsigned long debounceDelay = 50; // Debounce delay in milliseconds
|
||||
|
||||
WiFiClient wifiClient;
|
||||
|
|
@ -16,9 +17,7 @@ PubSubClient mqttClient(wifiClient);
|
|||
|
||||
TaskHandle_t mqttTaskHandle = NULL;
|
||||
|
||||
Bounce debouncer = Bounce();
|
||||
|
||||
volatile int pressCounter = 0;
|
||||
Bounce debouncers[numPins];
|
||||
|
||||
void setupWiFi() {
|
||||
WiFi.begin(ssid, password);
|
||||
|
|
@ -54,25 +53,30 @@ void mqttTask(void* parameter) {
|
|||
ulTaskNotifyTake(pdTRUE, portMAX_DELAY); // Wait for notification
|
||||
|
||||
if (mqttClient.connected()) {
|
||||
String message = "GPIO pin shorted! Count: " + String(pressCounter);
|
||||
mqttClient.publish(mqttTopic, message.c_str());
|
||||
Serial.println("Message sent to MQTT server");
|
||||
pressCounter++;
|
||||
for (unsigned int i = 0; i < numPins; i++) {
|
||||
if (debouncers[i].fell()) {
|
||||
String message = "Pin shorted: " + String(gpioPins[i]);
|
||||
mqttClient.publish(mqttTopic, message.c_str());
|
||||
Serial.println("Message sent to MQTT server");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(gpioPin, INPUT_PULLUP);
|
||||
|
||||
debouncer.attach(gpioPin);
|
||||
debouncer.interval(debounceDelay);
|
||||
|
||||
setupWiFi();
|
||||
mqttClient.setServer(mqttServer, mqttPort);
|
||||
mqttClient.setCallback(callback);
|
||||
|
||||
for (unsigned int i = 0; i < numPins; i++) {
|
||||
pinMode(gpioPins[i], INPUT_PULLUP);
|
||||
debouncers[i].attach(gpioPins[i]);
|
||||
debouncers[i].interval(debounceDelay);
|
||||
}
|
||||
|
||||
xTaskCreatePinnedToCore(
|
||||
mqttTask, // Task function
|
||||
"mqttTask", // Task name
|
||||
|
|
@ -90,8 +94,19 @@ void loop() {
|
|||
}
|
||||
mqttClient.loop();
|
||||
|
||||
debouncer.update();
|
||||
if (debouncer.fell()) {
|
||||
for (unsigned int i = 0; i < numPins; i++) {
|
||||
debouncers[i].update();
|
||||
}
|
||||
|
||||
bool anyPinShorted = false;
|
||||
for (unsigned int i = 0; i < numPins; i++) {
|
||||
if (debouncers[i].fell()) {
|
||||
anyPinShorted = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (anyPinShorted) {
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
vTaskNotifyGiveFromISR(mqttTaskHandle, &xHigherPriorityTaskWoken);
|
||||
if (xHigherPriorityTaskWoken == pdTRUE) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue