static Matrix *shared_matrix() { static Matrix *matrix = NULL; if (!matrix) { PanelConfiguration panelConfig; if (gOptions.panel_configuration_file.length()) { panelConfig.readConfigurationFile(gOptions.panel_configuration_file); } #ifdef USE_VIRTUAL_CANVAS matrix = new VirtualCanvas(panelConfig.rows, panelConfig.chainedDisplays, panelConfig.parallelDisplays); #else GPIO *io = new GPIO(); if (!io->Init()) { cerr << "Unable to initialize GPIO. Permissions?" << endl; return nullptr; } matrix = new RGBMatrix(io, panelConfig.rows, panelConfig.chainedDisplays, panelConfig.parallelDisplays); #endif } return matrix; }
int main(int argc, char *argv[]) { GPIO gpio; gpio.Init(); RGBMatrix matrix(&gpio); Visualizer *visualizer = new Visualizer(&matrix); int command[]={2,0,0,0,0,0,0}; //Array with length 7 to get Information from the Webfile socketConnection(); socketfunction(command); //Wait for the first command while(true) { Visualizer *visualizer = new Visualizer(&matrix); visualizer->setCommand(command); visualizer->Start(); // Start doing things. socketfunction(command); //change animation as needed visualizer->Stop(); } getchar(); close(sockfd); delete visualizer; }
int main(int argc, char *argv[]) { global_terminate = false; enabled = false; bool correct_luminance = true, screensaver = false, do_fork = false; int rows_on_display = 32, chained_displays = 1, pwm_bits = 0, brightness_in = 50, fps = 50; int listen_port = 3333; screensaver_t ss = SS_CLOCK; // FIXME commandline selectable std::string default_font = DEFAULT_FONT_FILE; int c = -1; while((c = getopt(argc, argv, "p:r:c:t:lsP:b:f:dF:h")) != -1) { switch(c) { case 'p': pwm_bits = atoi(optarg); break; case 'r': rows_on_display = atoi(optarg); break; case 'c': chained_displays = atoi(optarg); break; case 't': pwm_bits = atoi(optarg); break; case 'l': correct_luminance = !correct_luminance; break; case 's': screensaver = true; break; case 'P': listen_port = atoi(optarg); break; case 'b': brightness_in = atoi(optarg); break; case 'f': fps = atoi(optarg); break; case 'd': do_fork = true; break; case 'F': default_font = optarg; break; case 'h': help(); return 0; default: help(); error_exit(false, "option %c is not understood", c); } } signal(SIGINT, sigh); signal(SIGTERM, sigh); signal(SIGUSR1, toggle); srand(time(NULL)); font::init_fonts(); GPIO io; if (!io.Init()) error_exit(false, "Failed to initialized GPIO sub system"); srand(time(NULL)); RGBMatrix m(&io, rows_on_display, chained_displays, 1); if (pwm_bits > 0 && !m.SetPWMBits(pwm_bits)) error_exit(false, "Invalid range of pwm-bits"); if (correct_luminance) m.set_luminance_correct(true); std::atomic_int brightness(brightness_in); double_buffer_t db; db.w = m.width(); // change for different panel layout db.h = m.height(); int pixel_bytes = db.w * db.h * 3; db.data = new uint8_t[pixel_bytes]; db.brightness = &brightness; db.flag = db.need_update = false; db.screensaver = screensaver; db.font_name = default_font; pthread_rwlock_t clients_lock; pthread_rwlock_init(&clients_lock, NULL); std::map<std::string, disp_element_t *> clients; ThreadedCanvasManipulator *image_gen = new UpdateMatrix(&m, &db, &clients_lock, &clients, fps, ss); image_gen->Start(); if (do_fork && daemon(0, 0) == -1) error_exit(true, "Failed to daemon()"); printf("Go!\n"); main_loop(&db, &clients_lock, &clients, &brightness, &db.need_update, listen_port); terminate_threads(&clients_lock, &clients); global_terminate = true; image_gen->Stop(); // Stopping threads and wait for them to join. delete image_gen; font::uninit_fonts(); printf("END\n"); return 0; }