#include #include #include #include #include #define PORT_DATA 0x378 #define PORT_CTRL 0x37a #define STROBE_ON 1 #define STROBE_OFF 0 #define RESET 0 #define SEG_ON 3 #define SEG_OFF 2 #define DELAY_TIME 1 #define DIGIT_TIME 1000 #define FILE_PATH "/home/door/message" const short int charcodes[] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x4004, 0x0000, 0xc8da, 0x0000, 0x0000, 0x0004, 0x0072, 0x001e, 0xfe80, 0xc880, 0x0000, 0x8080, 0x0000, 0x2400, 0x007e, 0x4800, 0x80b6, 0xb012, 0x80cc, 0x80da, 0x80fa, 0x2402, 0x80fe, 0x80ce, 0x0000, 0x0000, 0x3000, 0x8090, 0x0600, 0x0886, 0x08be, 0x80ee, 0x489e, 0x0072, 0x481e, 0x8072, 0x8062, 0x00fa, 0x80ec, 0x4812, 0x003c, 0xb060, 0x0070, 0x226c, 0x126c, 0x007e, 0x80e6, 0x107e, 0x90e6, 0x80da, 0x4802, 0x007c, 0x120c, 0x146c, 0x3600, 0x2a00, 0x2412, 0x0072, 0x1200, 0x001e, 0x0000, 0x0010, 0x0040, 0x8830, 0x80f8, 0x80b0, 0x80bc, 0x80f6, 0x8062, 0x80de, 0x80e8, 0x0800, 0x001c, 0xb060, 0x4800, 0x88a8, 0x80a8, 0x80b8, 0x80e6, 0x80ce, 0x80a0, 0x80da, 0x8070, 0x0038, 0x1008, 0x0838, 0x3600, 0x00dc, 0x2412, 0x0000, 0x4800, 0x0000, 0x0002, 0x0000, 0x468c, 0x468c, 0x468c, 0x468c, 0x5500 }; char message[50]; void terminate(int signal); void read_file(int signal); void display_char(unsigned char); void writebyte(unsigned char); void display_reset(void); int main(int argc, char** argv){ int i; int bw; int current = 0; FILE* pidfile; pidfile = fopen("/home/door/door.pid", "w"); if (pidfile == NULL) abort(); fprintf(pidfile, "%i", getpid()); fclose(pidfile); bw = (argc > 1 ? atoi(argv[1]) : 1000); signal(SIGINT, terminate); signal(SIGUSR1, read_file); read_file(0); ioperm(PORT_DATA, 3, 1); while(1){ int i; char input; display_reset(); for (i = 0; i < 8 && message[i]; i++){ int j; display_char(message[i]); for(j = 0; j < bw; j++); } } //never gets here but never know I guess... ioperm(PORT_DATA, 3, 0); return 0; } void read_file(int signal){ FILE* input_file; int len; if (!(input_file = fopen(FILE_PATH, "r"))) abort(); len = fread(message, 1, 50, input_file); if (len < 50) message[len] = 0; fclose(input_file); } void terminate(int signal){ ioperm(PORT_DATA, 3, 0); exit(EXIT_SUCCESS); return; } void display_char(unsigned char input){ int i; short int charcode; unsigned char outbyte; if (input > 127) return; //my spoon is too big! charcode = charcodes[input]; for (i = 0; i < 16; i++){ outbyte = (unsigned char) ((charcode & 0x8000) >> 15); writebyte(outbyte + 2); charcode = charcode << 1; } return; } void writebyte(unsigned char output){ outb(STROBE_ON, PORT_CTRL); outb(output, PORT_DATA); #ifdef DELAY usleep(DELAY_TIME); #endif outb(STROBE_OFF, PORT_CTRL); return; } void display_reset(){ writebyte(RESET); return; }