Added corrupt and QR code faces and .png and in the yaml.

This commit is contained in:
Roy-vl 2024-06-24 20:44:44 +02:00
parent 28d971bf8f
commit 96143d0189
5 changed files with 167 additions and 2 deletions

View file

@ -0,0 +1,132 @@
#include <WiFi.h>
#include <PubSubClient.h>
#include "Button2.h"
const int mainTriggerPin = 25; // GPIO pins to check for shorting and wake-up
Button2 mainTriggerButton;
const char* ssid = "ProotAP";
const char* password = "prootproot!";
const char* mqttServer = "192.168.10.1";
const int mqttPort = 1883;
const char* mqttTopic = "test";
WiFiClient wifiClient;
PubSubClient mqttClient(wifiClient);
TaskHandle_t mqttTaskHandle = NULL;
void setupWiFi() {
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi...");
}
Serial.println("Connected to WiFi");
}
void callback(char* topic, byte* payload, unsigned int length) {
// This function is called when a message is received from the MQTT server
// Add your desired code here to handle the received message
}
void reconnectMQTT() {
while (!mqttClient.connected()) {
Serial.println("Connecting to MQTT server...");
if (mqttClient.connect("ESP32Client")) {
Serial.println("Connected to MQTT server");
mqttClient.subscribe(mqttTopic);
} else {
Serial.print("MQTT connection failed, rc=");
Serial.print(mqttClient.state());
Serial.println(" Retrying in 5 seconds...");
delay(5000);
}
}
}
void setup() {
Serial.begin(115200);
delay(50);
setupWiFi();
mqttClient.setServer(mqttServer, mqttPort);
mqttClient.setCallback(callback);
mainTriggerButton.begin(mainTriggerPin);
mainTriggerButton.setDebounceTime(2);
mainTriggerButton.setLongClickTime(250);
mainTriggerButton.setClickHandler(mainTriggerHandler);
mainTriggerButton.setLongClickHandler(mainTriggerHandler); // this will only be called upon release
// mainTriggerButton.setLongClickDetectedHandler(mainTriggerHandler); // this will only be called upon detection
mainTriggerButton.setDoubleClickHandler(mainTriggerHandler);
mainTriggerButton.setTripleClickHandler(mainTriggerHandler);
//xTaskCreatePinnedToCore(
// mqttTask, // Task function
// "mqttTask", // Task name
// 4096, // Stack size (bytes)
// NULL, // Task parameter
// 1, // Task priority
// &mqttTaskHandle, // Task handle
// 1 // Task core (0 or 1)
//);
}
int lastInput = 0;
String message = "";
void mainTriggerHandler(Button2& btn) {
switch (btn.getType()) {
case single_click:
Serial.print("single ");
if (lastInput < 5){
lastInput = lastInput + 1;
} else {
lastInput = 1;
}
message = "Butn_000" + String(lastInput) + "_0001";
mqttClient.publish(mqttTopic, message.c_str());
break;
case double_click:
Serial.print("double ");
message = "Butn_0003_0001";
lastInput = 3;
mqttClient.publish(mqttTopic, message.c_str());
break;
case triple_click:
Serial.print("triple ");
message = "Butn_0002_0001";
lastInput = 2;
mqttClient.publish(mqttTopic, message.c_str());
break;
case long_click:
Serial.print("long");
message = "Butn_0004_0001";
lastInput = 4;
mqttClient.publish(mqttTopic, message.c_str());
break;
}
Serial.print("click");
Serial.print(" (");
Serial.print(btn.getNumberOfClicks());
Serial.println(")");
Serial.println("sent: " + message);
}
void loop() {
if (!mqttClient.connected()) {
reconnectMQTT();
}
mainTriggerButton.loop();
mqttClient.loop();
}

View file

@ -4,7 +4,7 @@
const char* ssid = "ProotAP";
const char* password = "prootproot!";
const char* mqttServer = "10.1.1.15";
const char* mqttServer = "192.168.10.1";
const int mqttPort = 1883;
const char* mqttTopic = "test";

BIN
yaml parse test/QRFace.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 799 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 327 B

View file

@ -63,6 +63,39 @@ animations:
source_file: dizzyFace.png
duration: 1
- name: set corrupt
description: Animation to be corrupt
loop_count: 1
trigger: Butn_0006_0001
overrideable: true
graphics:
- type: transition
to_file: corruptFace.png
duration: 10
- type: image
source_file: corruptFace.png
duration: 1
- name: set QR
description: Animation to be confused
loop_count: 1
trigger: Butn_0007_0001
overrideable: true
graphics:
- type: transition
to_file: QRFace.png
duration: 10
- type: image
source_file: QRFace.png
duration: 1
- name: set angry
description: Animation to be confused
loop_count: 1
@ -124,7 +157,7 @@ animations:
description: Animation for a blink
loop_count: 1
trigger: blinkTimer #Button 2 pressed
trigger: blinkTimer # frigeer to be set by timer, not currently in use
overrideable: true # blink can be interupted at any time