Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- import cherrypy
- class Control:
- @cherrypy.expose
- def index(self):
- return '''<!DOCTYPE html>
- <html>
- <head>
- <title>RaspiCare</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <link rel="stylesheet" href="static/jquery.mobile-1.4.0.min.css">
- <link rel="stylesheet" href="static/style.css">
- <script src="static/jquery-1.10.2.min.js"></script>
- <script src="static/jquery.mobile-1.4.0.min.js"></script>
- <script>
- $(document).ready(function(){
- $('#dbmgmt').click(function(){
- window.location.href='static/dbmgmt.php';
- });
- $('#left_button').click(function(){
- $.post('/turnCamera', {direction:"left"}).done(function (reply) {
- $('#camerapos').empty().append(reply);
- alert("left button clicked");});
- });
- $('#right_button').click(function(){
- $.post('/turnCamera', {direction:"right"}).done(function (reply) {
- $('#camerapos').empty().append(reply);
- alert("right button clicked");});
- });
- $('#dispense').click(function(){
- $.post('/turnCamera', {direction:"dispense"}).done(function (reply) {
- $('#camerapos').empty().append(reply);
- alert("dispense button clicked");});
- });
- $("#light_1").change(function () {$.post('/switch',{key_pressed:"power_"+$(this).val()})});
- $('#photocell').click(function(){
- $.post('/photocell').done(function (reply) {
- $('#photocellvalue').empty().append(reply);});
- });
- $('#FSR').click(function(){
- $.post('/FSR').done(function (reply) {
- $('#photocellvalue').empty().append(reply);});
- });
- });
- </script>
- </head>
- <body style="overflow: scroll;overflow-x:hidden;">
- <div data-role="page" data-theme="a" id="page1">
- <div data-role="header">
- <img src="static/raspicare_logo.png">
- </div><!-- /header -->
- <div role="main" class="ui-content">
- <p>Welcome to the Homepage of RaspiCare. RaspiCare is a smart system that facilitates the daily routine of hospitals.</p>
- <div id="control_button">
- <img src="static/button_left.png" id="left_button" height="50" width="50">
- <img src="static/button_right.png" id="right_button" height="50" width="50">
- <p id="camerapos"> test </p>
- </div>
- <div class="ui-grid-b">
- <div class="ui-block-a" ><div class="ui-bar ui-bar-a" style="height:30px">Light Control</div>
- <form>
- <label for="light_1">Light 1</label>
- <select name="light_1" id="light_1" data-role="slider" data-track-theme="b" data-theme="b">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- <label for="light_2">Light 2</label>
- <select name="light_2" id="light_2" data-role="slider" data-track-theme="b" data-theme="b">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- <label for="light_3">Light 3</label>
- <select name="light_3" id="light_3" data-role="slider" data-track-theme="b" data-theme="b">
- <option value="off">Off</option>
- <option value="on">On</option>
- </select>
- </form>
- </div>
- <div class="ui-block-b"><div class="ui-bar ui-bar-a" style="height:30px">Sensor</div>
- <a id="photocell"; href="#">Sensor Controlled Lighting</a>
- <p id="photocellvalue"></p>
- <a id="FSR"; href="#">FSR Controlled Lighting</a>
- </div>
- <div class="ui-block-c"><div class="ui-bar ui-bar-a" style="height:30px">Pill Dispenser</div>
- <div class="ui-input-btn ui-btn ui-btn-b">
- Database Management
- <input data-enhanced="true" value="Enhanced - Theme swatch B" type="button" id="dbmgmt">
- </div>
- <div class="ui-input-btn ui-btn ui-btn-b">
- Dispense Pill
- <input data-enhanced="true" value="Enhanced - Theme swatch B" type="button" id="dispense">
- </div>
- </div>
- </div><!-- /grid-b -->
- </div><!-- /content -->
- <div data-role="footer">
- <p align="center"><small>NTU EEE 2013-2014</small></p>
- </div><!-- /footer -->
- </div><!-- /page -->
- </body>
- </html>
- '''
- @cherrypy.expose
- def turnCamera (self, **data):
- import pigpio
- import time
- # import serial
- # def servo_control(command):
- # serialport= serial.Serial ("/dev/ttyACM0", 9600, timeout=0.5)
- # serialport.write(command)
- # return serialport.readlines(1)
- servos=[4,7] #GPIO number
- pigpio.start()
- key = data['direction']
- ## if key=="left":
- ## servostatus = "left"
- ## print servostatus
- ## m=1500
- ##
- ## elif key=="right":
- ## m=1000
- #to dispense pill
- if key=="dispense":
- m=900
- pigpio.set_servo_pulsewidth(servos[0], m)
- servostat= "Position of servo: %s"%m
- print servostat
- time.sleep(1)
- m=1500
- pigpio.set_servo_pulsewidth(servos[0], m)
- servostat= "Position of servo: %s"%m
- print servostat
- time.sleep(1)
- pigpio.stop()
- return servostat
- @cherrypy.expose
- def switch(self, **data):
- import RPi.GPIO as GPIO #Import GPIO library
- import time #Import 'time' library so that we can use 'sleep()'
- # Use physical board pin numbers
- GPIO.setmode(GPIO.BOARD)
- # Set up header pin 11 (GPIO17) as an output
- print "Setup Pin 11"
- GPIO.setup(11, GPIO.OUT)
- key = data['key_pressed']
- if key=="power_on":
- print "switch on light"
- GPIO.output(11, True) #switch on
- time.sleep(1)
- elif key=="power_off":
- print "switch off light"
- GPIO.output(11, False) #switch off
- time.sleep(1)
- @cherrypy.expose
- def photocell(self):
- import RPi.GPIO as GPIO, time, os
- DEBUG = 1
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(11, GPIO.OUT)
- def RCtime (RCpin):
- reading = 0
- GPIO.setup(RCpin, GPIO.OUT)
- GPIO.output(RCpin, GPIO.LOW)
- time.sleep(1)
- GPIO.setup(RCpin, GPIO.IN)
- # This takes about 1 millisecond per loop cycle
- while (GPIO.input(RCpin) == GPIO.LOW):
- reading += 1
- return reading
- while True:
- sensorvalue= RCtime(12)
- if sensorvalue > 1000:
- print "switch on light"
- GPIO.output(11, True) #switch on
- lightstate ="On"
- time.sleep(1)
- else:
- print "switch off light"
- GPIO.output(11, False) #switch off
- lightstate ="Off"
- time.sleep(1)
- print sensorvalue # Read RC timing using BCM pin #18, physical pin 12
- return lightstate
- @cherrypy.expose
- def FSR(self):
- import RPi.GPIO as GPIO, time, os
- DEBUG = 1
- GPIO.setmode(GPIO.BOARD)
- GPIO.setup(11, GPIO.OUT)
- def Force (RCpin):
- reading = 0
- GPIO.setup(RCpin, GPIO.OUT)
- GPIO.output(RCpin, GPIO.LOW)
- time.sleep(1)
- GPIO.setup(RCpin, GPIO.IN)
- # This takes about 1 millisecond per loop cycle
- while (GPIO.input(RCpin) == GPIO.LOW):
- reading += 1
- return reading
- while True:
- sensorvalue= Force(13)
- if sensorvalue < 100:
- print "switch on light"
- GPIO.output(11, True) #switch on
- lightstate ="On"
- time.sleep(1)
- else:
- print "switch off light"
- GPIO.output(11, False) #switch off
- lightstate ="Off"
- time.sleep(1)
- print sensorvalue # Read RC timing using BCM pin #18, physical pin 12
- return lightstate
- #shutdown server
- @cherrypy.expose
- def shutdown(self):
- cherrypy.engine.exit()
- import os.path
- tutconf = os.path.join(os.path.dirname(__file__), 'tutorial.conf')
- if __name__ == '__main__':
- # CherryPy always starts with app.root when trying to map request URIs
- # to objects, so we need to mount a request handler root. A request
- # to '/' will be mapped to Comfort().index().
- cherrypy.quickstart(Control(), config=tutconf)
- else:
- # This branch is for the test suite; you can ignore it.
- cherrypy.tree.mount(Control(), config=tutconf)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement