update
This commit is contained in:
@@ -97,7 +97,6 @@ import os
|
|||||||
import traceback
|
import traceback
|
||||||
import sys
|
import sys
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import RPi.GPIO as GPIO
|
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
@@ -130,31 +129,7 @@ uSpot_profile_id = 1
|
|||||||
conn = sqlite3.connect("/var/www/moduleair_pro_4g/sqlite/sensors.db")
|
conn = sqlite3.connect("/var/www/moduleair_pro_4g/sqlite/sensors.db")
|
||||||
cursor = conn.cursor()
|
cursor = conn.cursor()
|
||||||
|
|
||||||
def blink_led(pin, blink_count, delay=1):
|
|
||||||
"""
|
|
||||||
Blink an LED on a specified GPIO pin.
|
|
||||||
|
|
||||||
Args:
|
|
||||||
pin (int): GPIO pin number (BCM mode) to which the LED is connected.
|
|
||||||
blink_count (int): Number of times the LED should blink.
|
|
||||||
delay (float): Time in seconds for the LED to stay ON or OFF (default is 1 second).
|
|
||||||
"""
|
|
||||||
# GPIO setup
|
|
||||||
GPIO.setwarnings(False)
|
|
||||||
GPIO.setmode(GPIO.BCM) # Use BCM numbering
|
|
||||||
GPIO.setup(pin, GPIO.OUT) # Set the specified pin as an output
|
|
||||||
|
|
||||||
try:
|
|
||||||
for _ in range(blink_count):
|
|
||||||
GPIO.output(pin, GPIO.HIGH) # Turn the LED on
|
|
||||||
#print(f"LED on GPIO {pin} is ON")
|
|
||||||
time.sleep(delay) # Wait for the specified delay
|
|
||||||
GPIO.output(pin, GPIO.LOW) # Turn the LED off
|
|
||||||
#print(f"LED on GPIO {pin} is OFF")
|
|
||||||
time.sleep(delay) # Wait for the specified delay
|
|
||||||
finally:
|
|
||||||
GPIO.cleanup(pin) # Clean up the specific pin to reset its state
|
|
||||||
print(f"GPIO {pin} cleaned up")
|
|
||||||
|
|
||||||
#get config data from SQLite table
|
#get config data from SQLite table
|
||||||
def load_config_sqlite():
|
def load_config_sqlite():
|
||||||
@@ -758,9 +733,6 @@ try:
|
|||||||
print("Operation not allowed. This may require a different configuration.")
|
print("Operation not allowed. This may require a different configuration.")
|
||||||
# Actions spécifiques pour ce type d'erreur
|
# Actions spécifiques pour ce type d'erreur
|
||||||
|
|
||||||
# Clignotement LED rouge en cas d'erreur
|
|
||||||
led_thread = Thread(target=blink_led, args=(24, 5, 0.5))
|
|
||||||
led_thread.start()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# 2.Si la réponse contient une réponse HTTP valide
|
# 2.Si la réponse contient une réponse HTTP valide
|
||||||
@@ -775,10 +747,7 @@ try:
|
|||||||
print("*****")
|
print("*****")
|
||||||
print('<span style="color: red;font-weight: bold;">ATTENTION: HTTP operation failed</span>')
|
print('<span style="color: red;font-weight: bold;">ATTENTION: HTTP operation failed</span>')
|
||||||
print("*****")
|
print("*****")
|
||||||
print("Blink red LED")
|
|
||||||
# Run LED blinking in a separate thread
|
|
||||||
led_thread = Thread(target=blink_led, args=(24, 5, 0.5))
|
|
||||||
led_thread.start()
|
|
||||||
|
|
||||||
# Get error code
|
# Get error code
|
||||||
print("Getting error code (11->Server connection error, 73->Secure socket connect error)")
|
print("Getting error code (11->Server connection error, 73->Secure socket connect error)")
|
||||||
@@ -820,9 +789,7 @@ try:
|
|||||||
else:
|
else:
|
||||||
# Si la commande HTTP a réussi
|
# Si la commande HTTP a réussi
|
||||||
print('<span class="badge text-bg-success">✅✅HTTP operation successful.</span>')
|
print('<span class="badge text-bg-success">✅✅HTTP operation successful.</span>')
|
||||||
print("Blink blue LED")
|
|
||||||
led_thread = Thread(target=blink_led, args=(23, 5, 0.5))
|
|
||||||
led_thread.start()
|
|
||||||
|
|
||||||
#4. Read reply from server
|
#4. Read reply from server
|
||||||
print("Reply from server:")
|
print("Reply from server:")
|
||||||
@@ -906,10 +873,7 @@ try:
|
|||||||
#on a peut etre une ERROR de type "+CME ERROR: No connection to phone"
|
#on a peut etre une ERROR de type "+CME ERROR: No connection to phone"
|
||||||
else:
|
else:
|
||||||
print('<span style="color: red;font-weight: bold;">No UUHTTPCR response</span>')
|
print('<span style="color: red;font-weight: bold;">No UUHTTPCR response</span>')
|
||||||
print("Blink red LED")
|
|
||||||
# Run LED blinking in a separate thread
|
|
||||||
led_thread = Thread(target=blink_led, args=(24, 5, 0.5))
|
|
||||||
led_thread.start()
|
|
||||||
#Vérification de l'erreur
|
#Vérification de l'erreur
|
||||||
print("Getting type of error")
|
print("Getting type of error")
|
||||||
# Split the response into lines and search for "+CME ERROR:"
|
# Split the response into lines and search for "+CME ERROR:"
|
||||||
|
|||||||
BIN
matrix/test_forms_infinite
Normal file
BIN
matrix/test_forms_infinite
Normal file
Binary file not shown.
136
matrix/test_forms_infinite.cc
Normal file
136
matrix/test_forms_infinite.cc
Normal file
@@ -0,0 +1,136 @@
|
|||||||
|
/*
|
||||||
|
|
||||||
|
__ __ _ _____ ____ _____ __
|
||||||
|
| \/ | / \|_ _| _ \|_ _\ \/ /
|
||||||
|
| |\/| | / _ \ | | | |_) || | \ /
|
||||||
|
| | | |/ ___ \| | | _ < | | / \
|
||||||
|
|_| |_/_/ \_\_| |_| \_\___/_/\_\
|
||||||
|
|
||||||
|
|
||||||
|
Script to display a simple square on the matrix LED
|
||||||
|
|
||||||
|
Pour compiler:
|
||||||
|
g++ -Iinclude -Llib test_forms_infinite.cc -o test_forms_infinite -lrgbmatrix
|
||||||
|
|
||||||
|
Pour le lancer:
|
||||||
|
sudo /var/www/moduleair_pro_4g/matrix/test_forms_infinite
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "led-matrix.h"
|
||||||
|
#include "graphics.h"
|
||||||
|
#include <signal.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdlib> // For rand()
|
||||||
|
#include <ctime> // For time()
|
||||||
|
|
||||||
|
using rgb_matrix::RGBMatrix;
|
||||||
|
using rgb_matrix::Canvas;
|
||||||
|
using rgb_matrix::Color;
|
||||||
|
|
||||||
|
// Global flag that can be used to exit the loop
|
||||||
|
volatile bool running = true;
|
||||||
|
|
||||||
|
// Signal handler to catch Ctrl+C
|
||||||
|
static void InterruptHandler(int signo) {
|
||||||
|
running = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
RGBMatrix::Options defaults;
|
||||||
|
|
||||||
|
defaults.hardware_mapping = "moduleair_pinout";
|
||||||
|
defaults.rows = 64;
|
||||||
|
defaults.cols = 128;
|
||||||
|
defaults.chain_length = 1;
|
||||||
|
defaults.parallel = 1;
|
||||||
|
defaults.row_address_type = 3;
|
||||||
|
defaults.show_refresh_rate = true;
|
||||||
|
defaults.brightness = 100;
|
||||||
|
defaults.pwm_bits = 1;
|
||||||
|
defaults.panel_type = "FM6126A";
|
||||||
|
defaults.disable_hardware_pulsing = false;
|
||||||
|
|
||||||
|
// Set up signal handler for clean exit
|
||||||
|
signal(SIGTERM, InterruptHandler);
|
||||||
|
signal(SIGINT, InterruptHandler);
|
||||||
|
|
||||||
|
// Seed the random number generator
|
||||||
|
srand(time(NULL));
|
||||||
|
|
||||||
|
Canvas *canvas = RGBMatrix::CreateFromFlags(&argc, &argv, &defaults);
|
||||||
|
if (canvas == NULL)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
// Get canvas dimensions for position constraints
|
||||||
|
int canvas_width = canvas->width();
|
||||||
|
int canvas_height = canvas->height();
|
||||||
|
|
||||||
|
// Square properties
|
||||||
|
int square_size = 8; // Size of the square (8x8)
|
||||||
|
int current_x = 10; // Initial X position
|
||||||
|
int current_y = 10; // Initial Y position
|
||||||
|
|
||||||
|
// Create an array of colors to cycle through
|
||||||
|
std::vector<Color> colors = {
|
||||||
|
Color(255, 0, 0), // Red
|
||||||
|
Color(0, 255, 0), // Green
|
||||||
|
Color(0, 0, 255), // Blue
|
||||||
|
Color(255, 255, 0), // Yellow
|
||||||
|
Color(0, 255, 255), // Cyan
|
||||||
|
Color(255, 0, 255), // Magenta
|
||||||
|
Color(255, 255, 255), // White
|
||||||
|
Color(255, 127, 0), // Orange
|
||||||
|
Color(127, 0, 255) // Purple
|
||||||
|
};
|
||||||
|
|
||||||
|
int color_index = 0;
|
||||||
|
time_t last_change = time(NULL);
|
||||||
|
|
||||||
|
// Draw initial square
|
||||||
|
Color current_color = colors[color_index];
|
||||||
|
for (int x = current_x; x < current_x + square_size; ++x) {
|
||||||
|
for (int y = current_y; y < current_y + square_size; ++y) {
|
||||||
|
canvas->SetPixel(x, y, current_color.r, current_color.g, current_color.b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run indefinitely until interrupted
|
||||||
|
while (running) {
|
||||||
|
// Check if it's time to change color and position (every 2 seconds)
|
||||||
|
time_t now = time(NULL);
|
||||||
|
if (now - last_change >= 2) {
|
||||||
|
// Clear the previous square
|
||||||
|
for (int x = current_x; x < current_x + square_size; ++x) {
|
||||||
|
for (int y = current_y; y < current_y + square_size; ++y) {
|
||||||
|
canvas->SetPixel(x, y, 0, 0, 0); // Clear to black
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move to the next color
|
||||||
|
color_index = (color_index + 1) % colors.size();
|
||||||
|
current_color = colors[color_index];
|
||||||
|
|
||||||
|
// Generate new random position, ensuring the square stays fully on screen
|
||||||
|
current_x = rand() % (canvas_width - square_size);
|
||||||
|
current_y = rand() % (canvas_height - square_size);
|
||||||
|
|
||||||
|
// Draw the square with the new color at the new position
|
||||||
|
for (int x = current_x; x < current_x + square_size; ++x) {
|
||||||
|
for (int y = current_y; y < current_y + square_size; ++y) {
|
||||||
|
canvas->SetPixel(x, y, current_color.r, current_color.g, current_color.b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
last_change = now;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Small sleep to prevent using 100% CPU
|
||||||
|
usleep(100000); // 100ms sleep
|
||||||
|
}
|
||||||
|
|
||||||
|
// Clean up when interrupted
|
||||||
|
canvas->Clear();
|
||||||
|
delete canvas;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user