/* Sean Bradly - 2009 */ #include #include #include /* for nanosleep */ #include /* for nonblocking getch */ #include /* for ioperm and outb */ /* Check with /proc/ioports to make sure this io-mapping is correct */ #define LPT0 0x03bc /* Modify depending on what pins you attached LEDs to */ #define RED ( 1 << 0 ) #define GREEN ( 1 << 1 ) #define BLUE ( 1 << 2 ) /* Simple use toggle macros */ #define ON(LED) (lpt0_shadow |= LED) #define OFF(LED) (lpt0_shadow &= ~LED) /* One-liner to flush local copy of port to the wire */ #define OUTPUT outb(lpt0_shadow,LPT0) /* char to simulate led ' '=off or [.,oO]=on w/ brightness */ #define FAKELED(val,color) (lpt0_shadow & color)?((val>192)?'O':(val>128)?'o':(val>64)?',':'.'):' ' /* keep a copy of the port status to prevent clobbering pins unintentionally */ static unsigned char lpt0_shadow = 0; /* Ncurses foo */ WINDOW *window; int handle_keys(unsigned char *, unsigned char *, unsigned char *, unsigned int *); int main(int argc, char *argv[]) { unsigned int finished = 0; /* Timer values */ struct timespec tm = {0,0}; int freq=1; /* Contains current RGB values (0..255) */ unsigned char r,g,b; unsigned char r_ctr,g_ctr,b_ctr; r=g=b=r_ctr=g_ctr=b_ctr=0; /* Get permission for raw IO */ if(ioperm(LPT0,3,1)) { fprintf(stderr,"Failed to get raw IO permissions (are you root?)\n"); exit(-1); } /* set all output pins to 0 */ OFF(RED); OFF(GREEN); OFF(BLUE); OUTPUT; /* Initialize ncurses for nonblocking key polling w/o echo */ window = initscr(); cbreak(); noecho(); nodelay(window,1); keypad(window,1); /* Loop until done */ while(!finished) { /* configure output bits */ (r_ctr1)?*freq-=1:(void)0; break; case KEY_BACKSPACE: return 1; } } return 0; }