From 0c8c9ad976879f7c90f9915a60845ccb0cdb337d Mon Sep 17 00:00:00 2001 From: manuel Date: Wed, 25 Dec 2013 13:25:16 +0100 Subject: initial commit --- examples/scripts/basic/script.py | 34 +++++++++++ examples/scripts/blink/script.py | 41 +++++++++++++ examples/scripts/macros/index.html | 120 +++++++++++++++++++++++++++++++++++++ examples/scripts/macros/script.py | 60 +++++++++++++++++++ examples/scripts/simple/index.html | 68 +++++++++++++++++++++ 5 files changed, 323 insertions(+) create mode 100644 examples/scripts/basic/script.py create mode 100644 examples/scripts/blink/script.py create mode 100644 examples/scripts/macros/index.html create mode 100644 examples/scripts/macros/script.py create mode 100644 examples/scripts/simple/index.html (limited to 'examples/scripts') diff --git a/examples/scripts/basic/script.py b/examples/scripts/basic/script.py new file mode 100644 index 0000000..5750a69 --- /dev/null +++ b/examples/scripts/basic/script.py @@ -0,0 +1,34 @@ +# Imports +import webiopi + +# Enable debug output +webiopi.setDebug() + +# Retrieve GPIO lib +GPIO = webiopi.GPIO +SWITCH = 21 +SERVO = 23 +LED0 = 24 +LED1 = 25 + +# Called by WebIOPi at script loading +def setup(): + webiopi.debug("Basic script - Setup") + # Setup GPIOs + GPIO.setFunction(SWITCH, GPIO.IN) + GPIO.setFunction(SERVO, GPIO.PWM) + GPIO.setFunction(LED0, GPIO.PWM) + GPIO.setFunction(LED1, GPIO.OUT) + + GPIO.pwmWrite(LED0, 0.5) # set to 50% ratio + GPIO.pwmWriteAngle(SERVO, 0) # set to 0 (neutral) + GPIO.digitalWrite(LED1, GPIO.HIGH) + +# Called by WebIOPi at server shutdown +def destroy(): + webiopi.debug("Basic script - Destroy") + # Reset GPIO functions + GPIO.setFunction(SWITCH, GPIO.IN) + GPIO.setFunction(SERVO, GPIO.IN) + GPIO.setFunction(LED0, GPIO.IN) + GPIO.setFunction(LED1, GPIO.IN) diff --git a/examples/scripts/blink/script.py b/examples/scripts/blink/script.py new file mode 100644 index 0000000..90c6c8c --- /dev/null +++ b/examples/scripts/blink/script.py @@ -0,0 +1,41 @@ +# Imports +import webiopi + +# Enable debug output +webiopi.setDebug() + +# Retrieve GPIO lib +GPIO = webiopi.GPIO +SWITCH = 21 +SERVO = 23 +LED0 = 24 +LED1 = 25 + +# Called by WebIOPi at script loading +def setup(): + webiopi.debug("Blink script - Setup") + # Setup GPIOs + GPIO.setFunction(SWITCH, GPIO.IN) + GPIO.setFunction(SERVO, GPIO.PWM) + GPIO.setFunction(LED0, GPIO.PWM) + GPIO.setFunction(LED1, GPIO.OUT) + + GPIO.pwmWrite(LED0, 0.5) # set to 50% ratio + GPIO.pwmWriteAngle(SERVO, 0) # set to 0 (neutral) + GPIO.digitalWrite(LED1, GPIO.HIGH) + +# Looped by WebIOPi +def loop(): + # Toggle LED each 5 seconds + value = not GPIO.digitalRead(LED1) + GPIO.digitalWrite(LED1, value) + webiopi.sleep(5) + +# Called by WebIOPi at server shutdown +def destroy(): + webiopi.debug("Blink script - Destroy") + # Reset GPIO functions + GPIO.setFunction(SWITCH, GPIO.IN) + GPIO.setFunction(SERVO, GPIO.IN) + GPIO.setFunction(LED0, GPIO.IN) + GPIO.setFunction(LED1, GPIO.IN) diff --git a/examples/scripts/macros/index.html b/examples/scripts/macros/index.html new file mode 100644 index 0000000..2dc118e --- /dev/null +++ b/examples/scripts/macros/index.html @@ -0,0 +1,120 @@ + + + + + + WebIOPi | Demo + + + + + +
+ + diff --git a/examples/scripts/macros/script.py b/examples/scripts/macros/script.py new file mode 100644 index 0000000..a469b1a --- /dev/null +++ b/examples/scripts/macros/script.py @@ -0,0 +1,60 @@ +# Imports +import webiopi +import time + +# Enable debug output +webiopi.setDebug() + +# Retrieve GPIO lib +GPIO = webiopi.GPIO + +SWITCH = 21 +SERVO = 23 +LED0 = 24 +LED1 = 25 + +# Called by WebIOPi at script loading +def setup(): + webiopi.debug("Script with macros - Setup") + # Setup GPIOs + GPIO.setFunction(SWITCH, GPIO.IN) + GPIO.setFunction(SERVO, GPIO.PWM) + GPIO.setFunction(LED0, GPIO.PWM) + GPIO.setFunction(LED1, GPIO.OUT) + + GPIO.pwmWrite(LED0, 0.5) # set to 50% ratio + GPIO.pwmWriteAngle(SERVO, 0) # set to 0 (neutral) + GPIO.digitalWrite(LED1, GPIO.HIGH) + + gpio0 = webiopi.deviceInstance("gpio0") + gpio0.digitalWrite(0, 0) + +# Looped by WebIOPi +def loop(): + # Toggle LED each 5 seconds + value = not GPIO.digitalRead(LED1) + GPIO.digitalWrite(LED1, value) + webiopi.sleep(5) + +# Called by WebIOPi at server shutdown +def destroy(): + webiopi.debug("Script with macros - Destroy") + # Reset GPIO functions + GPIO.setFunction(SWITCH, GPIO.IN) + GPIO.setFunction(SERVO, GPIO.IN) + GPIO.setFunction(LED0, GPIO.IN) + GPIO.setFunction(LED1, GPIO.IN) + gpio0 = webiopi.deviceInstance("gpio0") + gpio0.digitalWrite(0, 1) + +# A macro which says hello +@webiopi.macro +def HelloWorld(first, last): + webiopi.debug("HelloWorld(%s, %s)" % (first, last)) + return "Hello %s %s !" % (first, last) + +# A macro without args which return nothing +@webiopi.macro +def PrintTime(): + webiopi.debug("PrintTime: " + time.asctime()) + diff --git a/examples/scripts/simple/index.html b/examples/scripts/simple/index.html new file mode 100644 index 0000000..516ecbe --- /dev/null +++ b/examples/scripts/simple/index.html @@ -0,0 +1,68 @@ + + + + + + WebIOPi | Demo + + + + + +
+ + -- cgit v1.2.3