Commit ad88fca9 authored by kollo's avatar kollo

added wiring Pi functions --> GPIO

Description for new commands GPIO added to manual Update gpio-Functions
parent ec479360
......@@ -343,6 +343,74 @@ EXAMPLE:
SHOWPAGE
SEE ALSO: PRINT, TEXT, SETFONT
##############################################################################
Command: GPIO
Syntax: GPIO n,v
DESCRIPTION:
Sets the nth GPIO to output direction and value v.
The pin numbers follow the wirig Pi pin numbering
----*
n=0 -->GPIO 17
1 18
2 27
3 22
4 23
5 24
6 25
7 4
8 2
9 3
10 8
11 7
12 10
13 9
14 11
15 14
16 15
21 5
22 6
23 13
24 19
25 26
26 12
27 16
28 20
29 21
30 0
31 1
*----
SEE ALSO: GPIO?, GPIO()
##############################################################################
Variable: GPIO?
Syntax: a=GPIO?
DESCRIPTION:
This system variable GPIO? is 0 if no general purpose input/output (GPIO)
interface is a available on this hardware
platform, otherwise the number of usable GPIO channels is returned.
This variable is useful to detect, if the program is running on a
Raspberry Pi.
SEE ALSO: GPS?, SENSOR?, GPIO_SET, GPIO()
##############################################################################
Function: GPIO()
Syntax: a=GPIO(n)
DESCRIPTION:
Readout the n-th value of the general purpose input/output (GPIO)
channel. Usually the return values are 0 or 1.
The channel is set to input.
SEE ALSO: GPS, SENSOR, SENSOR?, ANDROID?, GPIO
##############################################################################
Command: GPS
......
......@@ -319,6 +319,7 @@ Syntax: a=SENSOR(n)
DESCRIPTION:
Readout the n-th value of the sensor-phalanx. Usually
----*
n=0 --> Temperature
1 --> Ambient light
3 --> Proximity
......@@ -326,8 +327,9 @@ DESCRIPTION:
7,8,9 --> Gyroscope x,y,z
10,11,12 --> Magnetic field x,y,z
13,14,15 --> Accelerometer x,y,z
*----
SEE ALSO: GPS, SENSOR, SENSOR?, ANDROID?
SEE ALSO: GPS, SENSOR, SENSOR?, ANDROID?, GPIO()
##############################################################################
......
......@@ -1144,8 +1144,8 @@ by the X11-Basic interpreter \verb|xbasic|. This is seen before in shell
scripts, in which the first line tells Unix to execute it with one of the shell
programs. The xbasic executable, which will take this file, parse it, and
execute it, is located in the directory /usr/bin. This may be different on some
systems. If you are not sure where the xbasic executable is, type \verb|which
xbasic| on the command line, and it will return you the path.
systems. If you are not sure where the xbasic executable is, type
\verb|which xbasic| on the command line, and it will return you the path.
\item {\bf All scripts should be marked as executable by the system.}
......
......@@ -151,6 +151,9 @@
/* rfftw_create_plan in RFFTW */
#undef HAVE_RFFTW
/* wiringPiSetup in wiringPi */
#undef HAVE_WIRINGPI
/* _SystemCycle in dynamical TINE lib */
#undef HAVE_TINE
......
......@@ -5757,6 +5757,53 @@ fi
# `-wiringPi':
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for wiringPiSetup in -lwiringPi" >&5
$as_echo_n "checking for wiringPiSetup in -lwiringPi... " >&6; }
if ${ac_cv_lib_wiringPi_wiringPiSetup+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-lwiringPi $libs $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char wiringPiSetup ();
int
main ()
{
return wiringPiSetup ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_wiringPi_wiringPiSetup=yes
else
ac_cv_lib_wiringPi_wiringPiSetup=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_wiringPi_wiringPiSetup" >&5
$as_echo "$ac_cv_lib_wiringPi_wiringPiSetup" >&6; }
if test "x$ac_cv_lib_wiringPi_wiringPiSetup" = xyes; then :
libs="-lwiringPi $libs"
$as_echo "#define HAVE_WIRINGPI 1" >>confdefs.h
fi
......
......@@ -279,6 +279,12 @@ AC_DEFINE(HAVE_RFFTW,1,[rfftw_create_plan in rfftw])
],,[$libs])
# `-wiringPi':
AC_CHECK_LIB([wiringPi], [wiringPiSetup], [
libs="-lwiringPi $libs"
AC_DEFINE(HAVE_WIRINGPI,1,[wiringPiSetup in wiringPi])
],,[$libs])
......
......@@ -23,6 +23,9 @@
#ifdef HAVE_CACOS
#include <complex.h>
#endif
#ifdef HAVE_WIRINGPI
#include <wiringPi.h>
#endif
#include "x11basic.h"
#include "variablen.h"
#include "xbasic.h"
......@@ -178,6 +181,7 @@
#define f_ror NULL
#define f_root NULL
#define f_rsrc_gaddr NULL
#define f_gpio NULL
#define f_sensor NULL
#define f_sgn NULL
#define f_shl NULL
......@@ -1088,6 +1092,27 @@ static double f_sensor(int n) {
}
#ifdef HAVE_WIRINGPI
int wiringpiissetup=0;
#endif
static double f_gpio(int n) {
#ifdef HAVE_WIRINGPI
if(n<0 || n>31) printf("ERROR: Wrong pin number [0-16, 21-31].\n");
else {
if(!wiringpiissetup) {
if (wiringPiSetup()==-1) {
printf("Error with wiring Pi setup!\n");
} else wiringpiissetup=1;
}
pinMode(n,INPUT);
return(digitalRead(n));
}
#endif
return(0);
}
static int f_lof(PARAMETER *plist,int e) {
// dump_parameterlist(plist,e);
if(filenr[plist[0].integer].typ) return(lof(filenr[plist[0].integer].dptr));
......@@ -1475,6 +1500,7 @@ const FUNCTION pfuncs[]= { /* alphabetisch !!! */
{ F_PLISTE|F_IRET, "GET_COLOR" , (pfunc)f_get_color,3,3,{PL_INT,PL_INT,PL_INT}},
#endif
{ F_CONST|F_PLISTE|F_IRET, "GLOB" , (pfunc) f_glob ,2,3,{PL_STRING,PL_STRING,PL_INT}},
{ F_IQUICK|F_IRET, "GPIO" ,(pfunc) f_gpio ,1,1,{PL_INT}},
{ F_CONST|F_IQUICK|F_IRET, "GRAY" , (pfunc) f_gray ,1,1,{PL_INT}},
{ F_CONST|F_DQUICK|F_DRET, "HYPOT" , hypot ,2,2,{PL_FLOAT,PL_FLOAT}},
......
......@@ -31,6 +31,11 @@
#include <fnmatch.h>
#include "defs.h"
#ifdef HAVE_WIRINGPI
#include <wiringPi.h>
#endif
#include "x11basic.h"
#include "variablen.h"
#include "xbasic.h"
......@@ -106,6 +111,7 @@
#define c_dec NULL
#define c_help NULL
#define c_home NULL
#define c_gpio NULL
#define c_gps NULL
#define c_goto NULL
#define c_gosub NULL
......@@ -2158,6 +2164,61 @@ static void c_gps(PARAMETER *plist,int e) {
printf("GPS <%s> %x\n",n,f);
#endif
}
#ifdef HAVE_WIRINGPI
extern int wiringpiissetup;
#endif
/* Sets the GPIO of the Raspberry Pi, using the wirig Pi pin numbering
n=0 -->GPIO 17
1 18
2 27
3 22
4 23
5 24
6 25
7 4
8 2
9 3
10 8
11 7
12 10
13 9
14 11
15 14
16 15
21 5
22 6
23 13
24 19
25 26
26 12
27 16
28 20
29 21
30 0
31 1
*/
static void c_gpio(PARAMETER *plist,int e) {
int n=plist->integer;
int f=plist[1].integer;
#ifdef HAVE_WIRINGPI
if(n<0 || n>31) printf("ERROR: Wrong pin number [0-16, 21-31].\n");
else {
if(!wiringpiissetup) {
if (wiringPiSetup()==-1) {
printf("Error with wiring Pi setup!\n");
} else wiringpiissetup=1;
}
pinMode(n,OUTPUT);
digitalWrite(n,f);
}
#endif
}
static void c_sensor(PARAMETER *plist,int e) {
#ifdef ANDROID
char *n=plist[0].pointer;
......@@ -2756,6 +2817,7 @@ const COMMAND comms[]= {
#endif
{ P_GOSUB, "GOSUB" , c_gosub,1,1,(unsigned short []){PL_PROC}},
{ P_GOTO, "GOTO" , c_goto,1,1,(unsigned short []){PL_LABEL}},
{ P_PLISTE, "GPIO" , c_gpio ,2,2,(unsigned short []){PL_INT,PL_INT}},
#ifndef NOGRAPHICS
{ P_PLISTE, "GPRINT" , c_gprint, 0,-1,(unsigned short []){PL_EVAL}},
#endif
......
......@@ -51,6 +51,7 @@
#define v_pi NULL
#define v_rows NULL
#define v_sensorf NULL
#define v_gpiof NULL
#define v_sp NULL
#define v_stimer NULL
#define v_timer NULL
......@@ -69,6 +70,9 @@ static int v_pc() {return(pc);}
#ifdef ANDROID
static int v_sensorf() {return(ANZSENSORS);}
#endif
#ifdef HAVE_WIRINGPI
static int v_gpiof() {return(32);}
#endif
static int v_stimer() { /* Sekunden-Timer */
time_t timec=time(NULL);
if(timec==-1) io_error(errno,"TIMER");
......@@ -147,6 +151,11 @@ const SYSVAR sysvars[]= { /* alphabetisch !!! */
{ FLOATTYP, "CTIMER", v_ctimer},
{ INTTYP, "ERR", (pfunc) v_err},
{ CONSTTYP|INTTYP, "FALSE", (pfunc) v_false},
#ifdef HAVE_WIRINGPI
{ CONSTTYP|INTTYP, "GPIO?", (pfunc) v_gpiof},
#else
{ CONSTTYP|INTTYP, "GPIO?", (pfunc) v_false},
#endif
#ifdef ANDROID
{ CONSTTYP|INTTYP, "GPS?", (pfunc) v_true},
#else
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment