/* __ __ _ _____ ____ _____ __ | \/ | / \|_ _| _ \|_ _\ \/ / | |\/| | / _ \ | | | |_) || | \ / | | | |/ ___ \| | | _ < | | / \ |_| |_/_/ \_\_| |_| \_\___/_/\_\ Script to display a simple square on the matrix LED sudo /var/www/moduleair_pro_4g/matrix/test_forms_noFail --led-no-hardware-pulse Pour compiler: g++ -Iinclude -Llib test_forms_noFail.cc -o test_forms_noFail -lrgbmatrix */ #include "led-matrix.h" #include "graphics.h" #include #include #include using rgb_matrix::RGBMatrix; using rgb_matrix::Canvas; volatile bool running = true; 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 handlers for clean exit signal(SIGTERM, InterruptHandler); signal(SIGINT, InterruptHandler); // Try creating the matrix with a few attempts Canvas *canvas = NULL; int attempts = 0; while (canvas == NULL && attempts < 3) { canvas = RGBMatrix::CreateFromFlags(&argc, &argv, &defaults); if (canvas == NULL) { fprintf(stderr, "Creating canvas failed, attempt %d/3. Retrying...\n", attempts + 1); attempts++; usleep(500000); // Wait 500ms before retry } } if (canvas == NULL) { fprintf(stderr, "Failed to create canvas after multiple attempts.\n"); return 1; } // Always clear the canvas first to reset any previous state canvas->Clear(); usleep(100000); // Small delay after clearing rgb_matrix::Color red(255, 0, 0); // Red color // Define the top-left corner of the square int start_x = 10; // X coordinate int start_y = 10; // Y coordinate int square_size = 8; // Size of the square (8x8) // Draw a filled square for (int x = start_x; x < start_x + square_size; ++x) { for (int y = start_y; y < start_y + square_size; ++y) { canvas->SetPixel(x, y, red.r, red.g, red.b); } } // Keep running until signaled int seconds = 0; while (running && seconds < 10) { sleep(1); seconds++; } // Always ensure we clean up canvas->Clear(); usleep(100000); // Small delay after clearing delete canvas; fprintf(stderr, "Display completed successfully.\n"); return 0; }