Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit c83eb568dfc31971131693f2b86bb4019c8a3832 davidb24v committed Jul 29, 2012
Showing with 161 additions and 0 deletions.
  1. +34 −0 README
  2. +51 −0 build
  3. +41 −0 utils.tcl
  4. +35 −0 wiringpi.i
@@ -0,0 +1,34 @@
+Tcl wrappers for Gordon't WiringPi Library
+
+Uses Gadgetoid's wiringpi.i, modified to remove explicit paths and use the version of WiringPi installed on the system.
+
+You will need swig and tcl-devel installed.
+
+To build, just run:
+
+./build
+
+And the Tcl extension will be built and installed to the first available directory in Tcl's auto_path
+
+Just add "package require wiringpi" at the start of your tcl script to use it
+
+Global variables are created to match some of Gordon's #defines:
+
+pinMode:
+INPUT, OUTPUT and PWM_OUTPUT
+
+digitalWrite:
+LOW and HIGH
+
+The following Tcl commands are also defined for convenience:
+
+mode <pins> <mode> : calls pinMode to set the mode for each pin in a list of pins
+on <pins> : Sets each pin in a list of pins to HIGH
+off <pins> : Sets each pin in list of pins to LOW
+
+flash <pins> [delay 100] [repeat 1] : Set the pins HIGH and LOW with an optional delay (default 100ms) and optional repeat
+
+Enjoy!
+
+Dave
+
@@ -0,0 +1,51 @@
+#!/bin/bash
+
+# Restart using tclsh\
+exec tclsh "$0" "$@"
+
+set PKG_VERSION 1.0
+
+proc main { } {
+ global PKG_VERSION
+
+ cmd swig -tcl -pkgversion $PKG_VERSION wiringpi.i
+
+ cmd gcc -shared wiringpi_wrap.c -I/usr/include/tcl \
+ -L/usr/local/lib -lwiringPi -o wiringpi.so
+
+ puts "Making pkgIndex"
+ pkg_mkIndex . wiringpi.so *.tcl
+
+ puts "Installing..."
+ foreach dir $::auto_path {
+ if { [file isdirectory $dir] } {
+ puts " Using $dir"
+ set target [file join $dir wiringpi$PKG_VERSION]
+ puts " Creating $target"
+ file mkdir $target
+ puts " wiringpi.so -> [file join $target wiringpi.so]"
+ file copy -force wiringpi.so $target
+ puts " pkgIndex.tcl -> [file join $target pkgIndex.tcl]"
+ file copy -force pkgIndex.tcl $target
+ puts " utils.tcl -> [file join $target utils.tcl]"
+ file copy -force utils.tcl $target
+ puts "done"
+ break
+ }
+ }
+}
+
+proc cmd { args } {
+ puts -nonewline "Running: $args ... "
+ flush stdout
+ if { [catch "eval exec $args" result] } {
+ puts "FAILED!"
+ puts "Message was:"
+ puts "$result"
+ exit 1
+ } else {
+ puts " ok"
+ }
+}
+
+main
@@ -0,0 +1,41 @@
+package provide wiringpi 1.0
+
+set INPUT 0
+set OUTPUT 1
+set PWM_OUTPUT 2
+
+set LOW 0
+set HIGH 1
+
+proc on { pins } {
+ foreach pin $pins {
+ digitalWrite $pin 1
+ }
+}
+
+proc off { pins } {
+ foreach pin $pins {
+ digitalWrite $pin 0
+ }
+}
+
+proc mode { pins mode } {
+ foreach pin $pins {
+ pinMode $pin $mode
+ }
+}
+
+proc flash { pins {delay 100} {repeat 1} } {
+ for {set count 0} {$count < $repeat} {incr count} {
+ foreach pin $pins {
+ on $pin
+ }
+ delay $delay
+ foreach pin $pins {
+ off $pin
+ }
+ delay $delay
+ }
+}
+
+
@@ -0,0 +1,35 @@
+%module wiringpi
+
+%apply unsigned char { uint8_t };
+
+extern int wiringPiSetup (void) ;
+extern int wiringPiSetupSys (void) ;
+extern int wiringPiSetupGpio (void) ;
+
+extern void wiringPiGpioMode (int mode) ;
+extern void pullUpDnControl (int pin, int pud) ;
+extern void pinMode (int pin, int mode) ;
+extern void digitalWrite (int pin, int value) ;
+extern void pwmWrite (int pin, int value) ;
+extern int digitalRead (int pin) ;
+extern void shiftOut (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val);
+extern void shiftOutWithDelay (uint8_t dPin, uint8_t cPin, uint8_t order, uint8_t val, int delay);
+extern uint8_t shiftIn (uint8_t dPin, uint8_t cPin, uint8_t order);
+
+extern void delay (unsigned int howLong) ;
+extern void delayMicroseconds (unsigned int howLong) ;
+extern unsigned int millis (void) ;
+
+extern int serialOpen (char *device, int baud) ;
+extern void serialClose (int fd) ;
+extern void serialPutchar (int fd, uint8_t c) ;
+extern void serialPuts (int fd, char *s) ;
+extern int serialDataAvail (int fd) ;
+extern int serialGetchar (int fd) ;
+extern void serialPrintf (int fd, char *message, ...) ;
+
+%{
+#include "wiringPi.h"
+#include "wiringShift.h"
+#include "serial.h"
+%}

0 comments on commit c83eb56

Please sign in to comment.