#define _GNU_SOURCE #include #include #include #include #include #include #include #include #include "fonts.h" #include "input_gadgets.h" #include "multiplexer.h" void drop_privileges(); int main(int argc, char **argv) { pthread_t thread_id; t_display_data display_data; int ret_val; unsigned char *text_buffer; // Set up gpi pointer for direct register access ret_val = multiplexer_setup_root(); if (ret_val) exit(ret_val); // Drop root privileges drop_privileges(); /************************************************************************\ * 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 thread_id = multiplexer_setup_non_root(&display_data); int i,j,k; text_buffer = malloc(8); if (text_buffer == NULL) { fprintf(stderr, "malloc failed to allocate 8 bytes\n"); exit(EXIT_FAILURE); } for (i=0; i<20; i++) { // usleep(2500000); // if (i & 0x01) { ret_val = gadgets_retrieve_temperature(text_buffer,sizeof(text_buffer)); if (ret_val) { free(text_buffer); exit(ret_val); } for (j=0; j<39; j++) display_data.buf[(display_data.should_buf+1)%3][j] = 0x00; for (j=0; (j<7) && (text_buffer[j]); j++) { text_buffer[j] = text_buffer[j] & 0xff; printf("%02x %c\n",text_buffer[j],text_buffer[j]); if (text_buffer[j] >= 0x7f) { if (text_buffer[j] <= 0xaf) continue; text_buffer[j] -= 0xaf - 0x7f + 1; } text_buffer[j] -= 0x20; if ((text_buffer[j] < 0) || (text_buffer[j] >= (sizeof(symbols)/5))) { printf("EXCESS: %d %d %d\n", text_buffer[j], (text_buffer[j] < 0), (text_buffer[j] >= (sizeof(symbols)/5))); continue; } for (k=0; k<5; k++) display_data.buf[(display_data.should_buf+1)%3][6*j+k] = symbols[5*(text_buffer[j])+k]; // } } display_data.should_buf = (display_data.should_buf+1)%3; } free(text_buffer); display_data.keep_running = 0; pthread_join(thread_id, NULL); return 0; } // main // // Drop (root) privileges // void drop_privileges() { /* Drop superuser privileges in correct order */ if (setgid(99) == -1) { perror("can't drop group privileges"); exit(-1); } if (setuid(99) == -1) { perror("can't drop user privileges"); exit(-1); } } // drop_root