[PD-cvs] externals/zexy/src configure.ac,1.6,1.7 lpt.c,1.4,1.5
IOhannes m zmölnig
zmoelnig at users.sourceforge.net
Wed Sep 28 14:18:16 CEST 2005
Update of /cvsroot/pure-data/externals/zexy/src
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21273
Modified Files:
configure.ac lpt.c
Log Message:
added support for accessing the parallel-port via device-files (/dev/parport0)
Index: configure.ac
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/configure.ac,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** configure.ac 16 Jun 2005 13:25:23 -0000 1.6
--- configure.ac 28 Sep 2005 12:18:13 -0000 1.7
***************
*** 350,353 ****
--- 350,355 ----
fi
+ AC_CHECK_HEADER(linux/ppdev.h, [ have_ppdev="yes" ], [ have_ppdev="no" ])
+
dnl check for LPT
AC_MSG_CHECKING("parallel-port")
***************
*** 359,362 ****
--- 361,365 ----
echo "yes (forced)"
else
+
cat > conftest.c << EOF
# include <sys/io.h>
***************
*** 372,376 ****
then
DFLAGS="$DFLAGS -DZ_WANT_LPT"
! echo "yes"
else
echo "no"
--- 375,385 ----
then
DFLAGS="$DFLAGS -DZ_WANT_LPT"
! if test "x$have_ppdev" = "xyes"
! then
! DFLAGS="$DFLAGS -DHAVE_PPDEV"
! echo "yes (with device-support)"
! else
! echo "yes"
! fi
else
echo "no"
Index: lpt.c
===================================================================
RCS file: /cvsroot/pure-data/externals/zexy/src/lpt.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -d -r1.4 -r1.5
*** lpt.c 9 Jun 2005 12:17:03 -0000 1.4
--- lpt.c 28 Sep 2005 12:18:14 -0000 1.5
***************
*** 25,29 ****
Thomas Musil: adding "control-output" and "input"
*/
-
#define BASE0 0x3bc
#define BASE1 0x378
--- 25,28 ----
***************
*** 40,43 ****
--- 39,51 ----
#ifdef Z_WANT_LPT
# include <stdlib.h>
+ # include <errno.h>
+
+ # ifdef HAVE_PPDEV
+ # include <sys/ioctl.h>
+ # include <linux/ppdev.h>
+ # include <linux/parport.h>
+ # include <fcntl.h>
+ # endif /* HAVE_PPDEV */
+
# ifdef __WIN32__
***************
*** 90,93 ****
--- 98,102 ----
unsigned long port;
+ int device; /* file descriptor of device, in case we are using one ...*/
int mode; // MODE_IOPERM, MODE_IOPL
***************
*** 96,102 ****
static void lpt_float(t_lpt *x, t_floatarg f)
{
#ifdef Z_WANT_LPT
if (x->port) {
- unsigned char b = f;
sys_outb(b, x->port+0);
}
--- 105,116 ----
static void lpt_float(t_lpt *x, t_floatarg f)
{
+ unsigned char b = f;
#ifdef Z_WANT_LPT
+ # ifdef HAVE_PPDEV
+ if (x->device>0){
+ ioctl (x->device, PPWDATA, &b);
+ } else
+ # endif
if (x->port) {
sys_outb(b, x->port+0);
}
***************
*** 106,112 ****
static void lpt_control(t_lpt *x, t_floatarg f)
{
#ifdef Z_WANT_LPT
if (x->port) {
- unsigned char b = f;
sys_outb(b, x->port+2);
}
--- 120,131 ----
static void lpt_control(t_lpt *x, t_floatarg f)
{
+ unsigned char b = f;
+ # ifdef HAVE_PPDEV
+ if (x->device>0){
+ ioctl (x->device, PPWCONTROL, &b);
+ } else
+ # endif
#ifdef Z_WANT_LPT
if (x->port) {
sys_outb(b, x->port+2);
}
***************
*** 116,119 ****
--- 135,145 ----
static void lpt_bang(t_lpt *x)
{
+ # ifdef HAVE_PPDEV
+ if (x->device>0){
+ unsigned char b=0;
+ ioctl (x->device, PPRCONTROL, &b);
+ outlet_float(x->x_obj.ob_outlet, (float)b);
+ } else
+ # endif
#ifdef Z_WANT_LPT
if (x->port) {
***************
*** 127,140 ****
{
t_lpt *x = (t_lpt *)pd_new(lpt_class);
if(s==gensym("lp"))
error("lpt: the use of 'lp' has been deprecated; use 'lpt' instead");
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("control"));
outlet_new(&x->x_obj, gensym("float"));
x->mode = MODE_NONE;
x->port = 0;
#ifdef Z_WANT_LPT
-
if ((argc==0)||(argv->a_type==A_FLOAT)) {
/* FLOAT specifies a parallel port */
--- 153,168 ----
{
t_lpt *x = (t_lpt *)pd_new(lpt_class);
+ char*devname=atom_getsymbol(argv)->s_name;
if(s==gensym("lp"))
error("lpt: the use of 'lp' has been deprecated; use 'lpt' instead");
+
inlet_new(&x->x_obj, &x->x_obj.ob_pd, gensym("float"), gensym("control"));
outlet_new(&x->x_obj, gensym("float"));
x->mode = MODE_NONE;
x->port = 0;
+ x->device = -1;
#ifdef Z_WANT_LPT
if ((argc==0)||(argv->a_type==A_FLOAT)) {
/* FLOAT specifies a parallel port */
***************
*** 159,191 ****
LATER think about this
*/
! x->port=strtol(atom_getsymbol(argv)->s_name, 0, 16);
}
! if (!x->port || x->port>65535){
post("lpt : bad port %x", x->port);
x->port = 0;
return (x);
}
!
! if (x->port && x->port < 0x400){
! if (ioperm(x->port, 8, 1)) {
! x->mode=MODE_NONE;
! } else x->mode = MODE_IOPERM;
! }
! if(x->mode==MODE_NONE){
! if (iopl(3)){
! x->mode=MODE_NONE;
! } else x->mode=MODE_IOPL;
! count_iopl++;
! // post("iopl.............................%d", count_iopl);
! }
!
! if(x->mode==MODE_NONE){
! error("lpt : couldn't get write permissions");
! x->port = 0;
! return (x);
}
!
! post("connected to port %x in mode '%s'", x->port, (x->mode==MODE_IOPL)?"iopl":"ioperm");
if (x->mode==MODE_IOPL)post("warning: this might seriously damage your pc...");
#else
--- 187,248 ----
LATER think about this
*/
! int bla;
! x->device=-1;
! x->port=strtol(devname, 0, 16);
! if(0==x->port){
! x->port=-1;
! #ifdef HAVE_PPDEV
! x->device = open(devname, O_RDWR);
! if(x->device<0){
! error("lpt: bad device %s", devname);
! return(x);
! } else {
! if (ioctl (x->device, PPCLAIM)) {
! perror ("PPCLAIM");
! close (x->device);
! return(x);
! }
! }
! #endif /* HAVE_PPDEV */
! }
}
! if ((x->device<0) && (!x->port || x->port>65535)){
post("lpt : bad port %x", x->port);
x->port = 0;
return (x);
}
! if (x->device<0){
! /* this is ugly: when using a named device,
! * we are currently assuming that we have read/write-access
! * of course, this is not necessary true
! */
! /* furthermore, we might also use the object
! * withOUT write permissions
! * (just reading the parport)
! */
! if (x->port && x->port < 0x400){
! if (ioperm(x->port, 8, 1)) {
! x->mode=MODE_NONE;
! } else x->mode = MODE_IOPERM;
! }
! if(x->mode==MODE_NONE){
! if (iopl(3)){
! x->mode=MODE_NONE;
! } else x->mode=MODE_IOPL;
! count_iopl++;
! // post("iopl.............................%d", count_iopl);
! }
!
! if(x->mode==MODE_NONE){
! error("lpt : couldn't get write permissions");
! x->port = 0;
! return (x);
! }
}
! if(x->device>0)
! post("connected to device %s", devname);
! else
! post("connected to port %x in mode '%s'", x->port, (x->mode==MODE_IOPL)?"iopl":"ioperm");
if (x->mode==MODE_IOPL)post("warning: this might seriously damage your pc...");
#else
***************
*** 199,202 ****
--- 256,266 ----
{
#ifdef Z_WANT_LPT
+ # ifdef HAVE_PPDEV
+ if (x->device>0){
+ ioctl (x->device, PPRELEASE);
+ close(x->device);
+ x->device=0;
+ } else
+ # endif
if (x->port) {
if (x->mode==MODE_IOPERM && ioperm(x->port, 8, 0)) error("lpt: couldn't clean up device");
More information about the Pd-cvs
mailing list