/* parPort03.c */ /* Compilació : gcc -o parPort03 parPort03.c `pkg-config --cflags --libs libglade-2.0 gtk+-2.0` -rdynamic Execució : sudo ./parPort03 */ /* 20071031 www.binefa.net */ #include #include #include #include #include /* #include */ #include /* Adreça física del port paraŀlel */ #define PORTADDRESS 0x378 #define DATA PORTADDRESS+0 #define STATUS PORTADDRESS+1 #define CONTROL PORTADDRESS+2 static GtkWidget *finestraPrincipal; static gboolean gbSel; static guchar gucByte; void vIniciaVariables(){ gbSel = FALSE; gucByte = 0x00; } void vTramet(gboolean gbDirecte){ if(gbDirecte){ outb(gucByte,DATA); g_print("Escric directament : 0x%X\n",gucByte); }else g_print("No escric directament : 0x%X\n",gucByte); } void on_button1_clicked(GtkWidget *widget){ vTramet(TRUE); } void on_checkbutton1_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gbSel = TRUE; else gbSel = FALSE; } void on_togglebutton_b7_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x80; else gucByte &= 0x7F; vTramet(gbSel); } void on_togglebutton_b6_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x40; else gucByte &= 0xBF; vTramet(gbSel); } void on_togglebutton_b5_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x20; else gucByte &= 0xDF; vTramet(gbSel); } void on_togglebutton_b4_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x10; else gucByte &= 0xEF; vTramet(gbSel); } void on_togglebutton_b3_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x08; else gucByte &= 0xF7; vTramet(gbSel); } void on_togglebutton_b2_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x04; else gucByte &= 0xFB; vTramet(gbSel); } void on_togglebutton_b1_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x02; else gucByte &= 0xFD; vTramet(gbSel); } void on_togglebutton_b0_toggled(GtkWidget *widget){ if(gtk_toggle_button_get_active((GtkToggleButton *)widget)) gucByte |= 0x01; else gucByte &= 0xFE; vTramet(gbSel); } void vIniciaPermisos(){ if(ioperm(DATA,3,1)) { perror("Donant permisos (esteu segurs de que sou root?)"); exit(1); } /* Dono permisos d'ús al port paraŀlel */ system("chmod 666 /dev/parport0"); } void vFinalitzaPermisos(){ if(ioperm(DATA,3,0)) { perror("Treient permisos"); exit(1); } } int main(int argc, char *argv[]){ GladeXML *arbreDeGinys; gtk_init(&argc,&argv); vIniciaVariables(); vIniciaPermisos(); arbreDeGinys = glade_xml_new("parPort01.glade",NULL,NULL); finestraPrincipal = glade_xml_get_widget(arbreDeGinys,"window1"); glade_xml_signal_autoconnect(arbreDeGinys); gtk_widget_show_all(finestraPrincipal); gtk_main(); vFinalitzaPermisos(); return 0; }