Compare commits
5 commits
439949f41f
...
96143d0189
Author | SHA1 | Date | |
---|---|---|---|
|
96143d0189 | ||
|
28d971bf8f | ||
|
8660cb5225 | ||
|
f027fb2034 | ||
|
aa4ca79376 |
7 changed files with 200 additions and 12 deletions
|
@ -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();
|
||||
}
|
|
@ -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
BIN
yaml parse test/QRFace.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 799 B |
BIN
yaml parse test/corruptFace.png
Normal file
BIN
yaml parse test/corruptFace.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 327 B |
Binary file not shown.
|
@ -175,6 +175,7 @@ class RenderingLayer:
|
|||
def __init__(self, animations, frame_rate=40):
|
||||
self.animations = animations
|
||||
self.current_point_array = []
|
||||
self.current_animation = {}
|
||||
self.current_animation_action = {}
|
||||
self.frame_rate = frame_rate # Set the desired frame rate
|
||||
self.frame_duration = 1.0 / frame_rate # Calculate the frame duration
|
||||
|
@ -189,6 +190,7 @@ class RenderingLayer:
|
|||
self.play_animation(animation)
|
||||
|
||||
def play_animation(self, animation):
|
||||
self.current_animation = animation
|
||||
if len(self.animation_queue) > 0:
|
||||
print("Stopping current animation...")
|
||||
# Replace the currently playing animation with the new one
|
||||
|
@ -232,7 +234,7 @@ class RenderingLayer:
|
|||
imagingtime = 0
|
||||
interpolatetime = 0
|
||||
transitionFrameCount = 1
|
||||
|
||||
offscreen_canvas = matrix.CreateFrameCanvas()
|
||||
|
||||
while True:
|
||||
|
||||
|
@ -240,7 +242,7 @@ class RenderingLayer:
|
|||
|
||||
if len(self.animation_queue) > 0:
|
||||
current_animation_action = self.animation_queue.pop(0)
|
||||
print("update action is: " + current_animation_action.get('type'))
|
||||
#print("update action is: " + current_animation_action.get('type'))
|
||||
|
||||
|
||||
# Render the next frame in the queue
|
||||
|
@ -248,7 +250,7 @@ class RenderingLayer:
|
|||
new_image = generate_image_from_point_array(current_animation_action.get('point_array'), 128, 32)
|
||||
|
||||
self.current_point_array = current_animation_action.get('point_array')
|
||||
print("image generated")
|
||||
#print("image generated")
|
||||
|
||||
elif current_animation_action.get('type') == "transition":
|
||||
|
||||
|
@ -321,15 +323,20 @@ class RenderingLayer:
|
|||
else:
|
||||
print("unknown action: ", current_animation_action)
|
||||
|
||||
print("setting image to canvas")
|
||||
offscreen_canvas = matrix.CreateFrameCanvas()
|
||||
#print("setting image to canvas")
|
||||
offscreen_canvas.SetImage(new_image, unsafe=False)
|
||||
print("pushing image to matrix")
|
||||
#print("pushing image to matrix")
|
||||
matrix.SwapOnVSync(offscreen_canvas)
|
||||
print("pushing image done")
|
||||
#print("pushing image done")
|
||||
|
||||
# Save the image to a file with the desired format and file name
|
||||
# new_image.save("output/frameNumber"+str(frameCount)+".png")
|
||||
else:
|
||||
#print("buffer empty")
|
||||
if self.current_animation.get('repeat', False):
|
||||
#print("repeating")
|
||||
self.play_animation(self.current_animation)
|
||||
|
||||
frameCount += 1
|
||||
# new_image.save("output/frameNumber"+str(frameCount)+".png")
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ animations:
|
|||
|
||||
# Define the trigger for this animation.
|
||||
# In this case, it triggers when a button is pressed.
|
||||
trigger: Butn_0001_0001 #Button 1 pressed
|
||||
trigger: Butn_1000_0001 #Button 1 pressed
|
||||
|
||||
# Specify whether this animation can be overridden by another animation.
|
||||
overrideable: true
|
||||
|
@ -43,6 +43,9 @@ animations:
|
|||
- type: transition
|
||||
to_file: eyesClosed_neutral.png
|
||||
duration: 10
|
||||
- type: image
|
||||
source_file: eyesClosed_neutral.png
|
||||
duration: 1
|
||||
|
||||
- name: set confusion
|
||||
description: Animation to be confused
|
||||
|
@ -56,6 +59,42 @@ animations:
|
|||
- type: transition
|
||||
to_file: dizzyFace.png
|
||||
duration: 10
|
||||
- type: image
|
||||
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
|
||||
|
@ -69,6 +108,9 @@ animations:
|
|||
- type: transition
|
||||
to_file: angryFace.png
|
||||
duration: 10
|
||||
- type: image
|
||||
source_file: angryFace.png
|
||||
duration: 1
|
||||
|
||||
- name: set love
|
||||
description: Animation for love eyes
|
||||
|
@ -82,12 +124,15 @@ animations:
|
|||
- type: transition
|
||||
to_file: loveFace.png
|
||||
duration: 10
|
||||
- type: image
|
||||
source_file: loveFace.png
|
||||
duration: 1
|
||||
|
||||
- name: reset to continuous blink
|
||||
description: Animation for blinking
|
||||
loop_count: 0
|
||||
|
||||
trigger: Butn_0004_0001
|
||||
repeat: true
|
||||
trigger: Butn_0005_0001
|
||||
|
||||
overrideable: true
|
||||
|
||||
|
@ -112,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
|
||||
|
||||
|
@ -138,6 +183,10 @@ animations:
|
|||
overrideable: true # blink can be interupted at any time
|
||||
|
||||
graphics:
|
||||
- type: image # hold eye closed
|
||||
source_file: neutral.png
|
||||
duration: 40
|
||||
|
||||
- type: transition # close the eye from whatever the current state
|
||||
to_file: eyesClosed_neutral.png
|
||||
duration: 6
|
||||
|
|
Loading…
Add table
Reference in a new issue