From e2dec0fd7e688cf3d932c60b2a9e9210e08e9b72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?IOhannes=20m=20zm=C3=B6lnig?= Date: Wed, 28 Jul 2004 10:43:30 +0000 Subject: bugfix (unsigned char instead of char) svn path=/trunk/externals/hardware/; revision=1894 --- memPIO/memPIO.cpp | 200 +++++++++++++++++++++++++++--------------------------- 1 file changed, 100 insertions(+), 100 deletions(-) diff --git a/memPIO/memPIO.cpp b/memPIO/memPIO.cpp index aa9aaf2..2e255bf 100644 --- a/memPIO/memPIO.cpp +++ b/memPIO/memPIO.cpp @@ -14,9 +14,9 @@ * * TODO: currently two [memPIO]s interfere * - * - * copyleft:forum::für::umläute:2004 -*/ + * + * copyleft:forum::für::umläute:2004 + */ #include @@ -26,96 +26,96 @@ // IMPORTANT: Adjust this path to your needs //#import "c:\windows\system\memx.ocx" #import "c:\winnt\system32\memx.ocx" - -/* do a little help thing */ - -typedef struct memPIO -{ + +/* do a little help thing */ + +typedef struct memPIO +{ t_object x_obj; MEMXLib::_DmeMPIOPtr pio; int input[3]; - t_outlet *outlet[3]; -} t_memPIO; - -t_class *memPIO_class; - -static void memPIO_help(void) -{ - post("\n\n...mem-PIO for pd" - "\n\n(l) forum::für::umläute 2004\n" + t_outlet *outlet[3]; +} t_memPIO; + +t_class *memPIO_class; + +static void memPIO_help(void) +{ + post("\n\n...mem-PIO for pd" + "\n\n(l) forum::für::umläute 2004\n" "this software is under the GnuGPL that is provided with these files\n"); post("usage:"); post("\t'mode <1|0>': set all ports to writable(1) or readable(0=default)"); post("\t'mode <1|0> <1|0> <1|0>': set the read/write-mode of the individual ports"); post("\t'bang': returns the values of all readable ports"); post("\t'set ': set all writable ports to the 8bit-value"); - post("\t'set ': set writable ports to the corresponding value"); + post("\t'set ': set writable ports to the corresponding value"); } static void memPIO_bang(t_memPIO*x){ - int port=3; + int port=3; - x->pio->UpdateCache (); + x->pio->UpdateCache (); - while(port--){ - if (!x->input[port]){ - long l=x->pio->CachedPort [port+1]; - outlet_float(x->outlet[port], l); - } - } + while(port--){ + if (!x->input[port]){ + long l=x->pio->CachedPort [port+1]; + outlet_float(x->outlet[port], l); + } + } } static void memPIO_mode(t_memPIO*x, t_symbol *s, int argc, t_atom*argv){ - MEMXLib::IO dir; - bool out; - - switch(argc){ - default: - error("memPIO: \"mode\" message needs 1 or 3 arguments, have %d", argc); - return; - case 1: - out=(atom_getfloat(argv)>0.f); - dir=(out)?MEMXLib::DirOut:MEMXLib::DirIn; - x->pio->DirPort1 =dir; x->input[0]=out; - x->pio->DirPort2 =dir; x->input[1]=out; - x->pio->DirPort3H=dir; x->input[2]=out; - x->pio->DirPort3L=dir; - break; - case 3: - out=(atom_getfloat(argv+0)>0.f); - x->pio->DirPort1 =(out)?MEMXLib::DirOut:MEMXLib::DirIn; x->input[0]=out; - out=(atom_getfloat(argv+1)>0.f); - x->pio->DirPort2 =(out)?MEMXLib::DirOut:MEMXLib::DirIn; x->input[1]=out; - out=(atom_getfloat(argv+2)>0.f); - x->pio->DirPort3H=(out)?MEMXLib::DirOut:MEMXLib::DirIn; x->input[2]=out; - x->pio->DirPort3L=(out)?MEMXLib::DirOut:MEMXLib::DirIn; - } + MEMXLib::IO dir; + bool out; + + switch(argc){ + default: + error("memPIO: \"mode\" message needs 1 or 3 arguments, have %d", argc); + return; + case 1: + out=(atom_getfloat(argv)>0.f); + dir=(out)?MEMXLib::DirOut:MEMXLib::DirIn; + x->pio->DirPort1 =dir; x->input[0]=out; + x->pio->DirPort2 =dir; x->input[1]=out; + x->pio->DirPort3H=dir; x->input[2]=out; + x->pio->DirPort3L=dir; + break; + case 3: + out=(atom_getfloat(argv+0)>0.f); + x->pio->DirPort1 =(out)?MEMXLib::DirOut:MEMXLib::DirIn; x->input[0]=out; + out=(atom_getfloat(argv+1)>0.f); + x->pio->DirPort2 =(out)?MEMXLib::DirOut:MEMXLib::DirIn; x->input[1]=out; + out=(atom_getfloat(argv+2)>0.f); + x->pio->DirPort3H=(out)?MEMXLib::DirOut:MEMXLib::DirIn; x->input[2]=out; + x->pio->DirPort3L=(out)?MEMXLib::DirOut:MEMXLib::DirIn; + } } static void memPIO_set(t_memPIO*x, t_symbol*s, int argc, t_atom*argv){ - int port=3; + int port=3; - char val[4]={0,0,0,0}; + unsigned char val[4]={0,0,0,0}; - switch(argc){ - case 1: - val[0]=val[1]=val[2]=val[3]=atom_getfloat(argv); - break; - case 3: - val[0]=atom_getfloat(argv+0); - val[1]=atom_getfloat(argv+1); - val[2]=atom_getfloat(argv+2); - break; - default: - break; - } - - while(port--) - if(x->input[port]){ - x->pio->port[port+1]=val[port]; - } + switch(argc){ + case 1: + val[0]=val[1]=val[2]=val[3]=atom_getfloat(argv); + break; + case 3: + val[0]=atom_getfloat(argv+0); + val[1]=atom_getfloat(argv+1); + val[2]=atom_getfloat(argv+2); + break; + default: + break; + } + + while(port--) + if(x->input[port]){ + x->pio->port[port+1]=val[port]; + } } @@ -123,12 +123,12 @@ static void memPIO_set(t_memPIO*x, t_symbol*s, int argc, t_atom*argv){ static void memPIO_free(t_memPIO*x) { x->pio.Release (); -} - -void *memPIO_new(void) +} + +void *memPIO_new(void) { int i; - bool found=false; + bool found=false; t_memPIO *x = (t_memPIO *)pd_new(memPIO_class); // because we use a ActiveX we need to initialize OLE for this app OleInitialize (NULL); @@ -144,44 +144,44 @@ void *memPIO_new(void) found=false; // search until the highest-possible Card-ID for(i = 0; i < x->pio->LastAttached; i++) - { - // select a device - x->pio->CardId = i+1; - // if selected device is attached, return - if (x->pio->Attached){ - found=true; - break; - } - } + { + // select a device + x->pio->CardId = i+1; + // if selected device is attached, return + if (x->pio->Attached){ + found=true; + break; + } + } i++; if(!found){ - memPIO_free(x); - return 0; + memPIO_free(x); + return 0; } /* these are all outputs */ for (int n=0; n<3; n++) { x->outlet[n] = outlet_new(&x->x_obj, 0); - x->input[n]=0; + x->input[n]=0; } - return (void *)x; -} - -void memPIO_setup(void) -{ - post("\t the memPIO external"); - post("\t (l) forum::für::umläute"); - post("\t compiled: "__DATE__""); - + return (void *)x; +} + +void memPIO_setup(void) +{ + post("\t the memPIO external"); + post("\t (l) forum::für::umläute"); + post("\t compiled: "__DATE__""); + memPIO_class = class_new(gensym("memPIO"), - (t_newmethod)memPIO_new, - (t_method)memPIO_free, - sizeof(t_memPIO), - 0, A_NULL); + (t_newmethod)memPIO_new, + (t_method)memPIO_free, + sizeof(t_memPIO), + 0, A_NULL); class_addmethod(memPIO_class, (t_method)memPIO_help, gensym("help"), A_NULL); class_addmethod(memPIO_class, (t_method)memPIO_mode, gensym("mode"), A_GIMME, A_NULL); class_addmethod(memPIO_class, (t_method)memPIO_set, gensym("set"), A_GIMME, A_NULL); - class_addbang(memPIO_class, (t_method)memPIO_bang); -} + class_addbang(memPIO_class, (t_method)memPIO_bang); +} -- cgit v1.2.1