From feb10a536aeea4ebd6558659ea172129adb6abe1 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 7 Jun 2012 21:57:26 +0100 Subject: added output external --- overo_gpioin.pd_linux | Bin 5520 -> 0 bytes src/makefile | 4 +- src/overo_gpioout.c | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) delete mode 100755 overo_gpioin.pd_linux create mode 100644 src/overo_gpioout.c diff --git a/overo_gpioin.pd_linux b/overo_gpioin.pd_linux deleted file mode 100755 index 5d4b6c1..0000000 Binary files a/overo_gpioin.pd_linux and /dev/null differ diff --git a/src/makefile b/src/makefile index 7042469..e571945 100644 --- a/src/makefile +++ b/src/makefile @@ -3,9 +3,9 @@ CC=cc STRIP=strip -NAME=overo_gpioin +SRC=$(shell ls *.c) -Phony: $(NAME).pd_linux +Phony: $(SRC:.c=.pd_linux) .SUFFIXES: .pd_linux diff --git a/src/overo_gpioout.c b/src/overo_gpioout.c new file mode 100644 index 0000000..4eeb5a3 --- /dev/null +++ b/src/overo_gpioout.c @@ -0,0 +1,105 @@ +/* overo_gpioout + + pd external for output to gumstix overo gpio + + Copyright (C) 2012 Tim Redfern + tim@eclectronics.org + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License + as published by the Free Software Foundation; either version 2.1 + of the License, or (at your option) any later version. + + allows use of GPIO pins 144,145 and 170 on overo expansion header for output + creation parameter 1 - 3 - (gpio 144 / 170/ 145) + + WARNING use at your own risk! +*/ + +#include "m_pd.h" +#include +#include +#include + +#define min(X,Y) ((X) < (Y) ? (X) : (Y)) +#define max(X,Y) ((X) > (Y) ? (X) : (Y)) + + +t_class *overo_gpioout_class; + +typedef struct overo_gpioout +{ + t_object x_obj; + int gpioNum; + char outfile[32]; + FILE *fs; + int set; //0 or 1 +} t_overo_gpioout; + +void overo_gpioout_float(t_overo_gpioout *x, t_floatarg f) +{ + int newset=(int) f; + if (newset!=x->set) { + x->fs = fopen( x->outfile, "w" ); + + int t; + + if (newset) t=fwrite( "1", sizeof(char), 1, x->fs ); + else t=fwrite( "0", sizeof(char), 1, x->fs ); + + fclose(x->fs); + x->set=newset; + } +} + +void overo_gpioout_free(t_overo_gpioout *x) +{ + // +} + +void *overo_gpioout_new(t_floatarg f) +{ + t_overo_gpioout *x = (t_overo_gpioout *)pd_new(overo_gpioout_class); + int nums[]={144,170,145}; + x->gpioNum=nums[min(2,max(0,((int) f)-1))]; //maps switch number to GPIO number + post("overo_gpoout: using GPIO(%d): switch %d\n",x->gpioNum,min(2,max(1,(int) f))); + sprintf(x->outfile,"/sys/class/gpio/gpio%d/value",x->gpioNum); + post("outfile: %s\n",x->outfile); + + char gpionum[4]; + sprintf(gpionum,"%d",x->gpioNum); + + //if (( + x->fs = fopen( "/sys/class/gpio/export", "w" ); + //) < 0 ) + //{ + // error( "Unable to open exportfile" ); + // exit( 1 ); + //} + int t=fwrite( gpionum, sizeof(char), 3, x->fs ); + fclose(x->fs); + + char dirfile[30]; + sprintf(dirfile,"/sys/class/gpio/gpio%d/value",x->gpioNum); + x->fs = fopen(dirfile, "w" ); + t=fwrite( "out", sizeof(char), 3, x->fs ); + fclose(x->fs); + + //if (( + x->fs = fopen( x->outfile, "w" ); + //) < 0 ) + //{ + // error( "Unable to open outfile" ); + // exit( 1 ); + //} + t=fwrite( "0", sizeof(char), 1, x->fs ); + x->set=0; + fclose(x->fs); + return (void *)x; +} + +void overo_gpioout_setup(void) +{ + overo_gpioout_class = class_new(gensym("overo_gpioout"), (t_newmethod)overo_gpioout_new, (t_method)overo_gpioout_free, sizeof(t_overo_gpioout), 0, A_DEFFLOAT, 0); + class_addfloat(overo_gpioout_class,overo_gpioout_float); +} -- cgit v1.2.3