#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include "anzeige.h" #include "fonts.h" #include "input_gadgets.h" #include "multiplexer.h" void drop_privileges(); void handle_signals(int signo); t_scroll_data scroll_data; t_input_thread input_threads[THREAD_IDX_MAX]; int main(int argc, char **argv) { int ret_val; memset(&scroll_data, 0, sizeof(t_scroll_data)); memset(&input_threads, 0, sizeof(t_input_thread) * THREAD_IDX_MAX); // Set up gpi pointer for direct register access ret_val = multiplexer_setup_root(); if (ret_val) return ret_val; // Drop root privileges drop_privileges(); // set up / register signal handler struct sigaction new_action, old_action; new_action.sa_handler = handle_signals; sigemptyset (&new_action.sa_mask); new_action.sa_flags = 0; const int fetch_signals[4] = { SIGINT, SIGHUP, SIGTERM, SIGUSR1 }; for (int i = 0; i < sizeof(fetch_signals)/sizeof(fetch_signals[0]); i++) { sigaction (fetch_signals[i], NULL, &old_action); if (old_action.sa_handler != SIG_IGN) sigaction (fetch_signals[i], &new_action, NULL); } init_symbols_boundaries(); /************************************************************************\ * You are about to change the GPIO settings of your computer. * * Mess this up and it will stop working! * * It might be a good idea to 'sync' before running this program * * so at least you still have your code changes written to the SD-card! * \************************************************************************/ // configure the gpio pins and start the multiplexer thread multiplexer_setup_scroll(&scroll_data); #define TEXT_BUFFER_LENGTH SCROLL_BUF_LEN / 5 char *text_buffer; char *text_buffer_end; char text_buffers[OUTPUT_IDX_MAX][MAX_TEXT_OUTPUT_LEN]; char output_text_buffer[MAX_TEXT_OUTPUT_LEN]; char humidity_text_buffer[MAX_TEXT_OUTPUT_LEN]; double outside_temperature = 0, outside_humidity = 0, inside_temperature = 0, inside_humidity = 0; int updated = 0; memset(humidity_text_buffer, 0 ,MAX_TEXT_OUTPUT_LEN); text_buffer = malloc(TEXT_BUFFER_LENGTH); if (text_buffer == NULL) { fprintf(stderr, "malloc failed to allocate %d bytes\n", TEXT_BUFFER_LENGTH); turn_off_display(); return EXIT_FAILURE; } memset(text_buffer, 0, TEXT_BUFFER_LENGTH); memset(text_buffers, 0, OUTPUT_IDX_MAX * MAX_TEXT_OUTPUT_LEN); memset(output_text_buffer, 0, MAX_TEXT_OUTPUT_LEN); for (int i=0; i 15) { updated = 0; memset(text_buffer, 0, TEXT_BUFFER_LENGTH); text_buffer_end = text_buffer; for (int i=0; i 0) && (*text_buffers[i])) text_buffer_end += snprintf( text_buffer_end, text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end, "%s; ", text_buffers[i] ); } struct tm time_struct; time_t now; memset(&time_struct, 0, sizeof(time_struct)); now = time(NULL); localtime_r(&now, &time_struct); for (int i = 0; i < (time_struct . tm_wday + 6) % 7 + 1; i++) { if (text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end <= 0) break; text_buffer_end += snprintf( text_buffer_end, text_buffer + TEXT_BUFFER_LENGTH - text_buffer_end, "%c%c%c%c", 0xEE, i==0 ? 0x01 : 0x03 + 2 * (i & 0x01), 0xEE, i==0 ? 0x02 : 0x04 + 2 * (i & 0x01) ); } scroll_data . input_len = render( text_buffer, text_buffer_end - text_buffer, scroll_data . input, sizeof(scroll_data . input), 1 ); scroll_data . update = 1; } usleep(100000); } for (int i=0; i