Advertisement
Guest User

Untitled

a guest
Dec 6th, 2012
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.23 KB | None | 0 0
  1. <?php                                                                                                                                      
  2. /* A simple PHP script using the PHPSerial class to
  3.  * send messages over the serial connection to the arduino
  4.  * from the image map.
  5.  *
  6.  * issues:
  7.  *      - after changing the cycle to 3 from the PSP you cannot change to
  8.  *        any other cycles. (I think the issue is how the PSP interprets
  9.  *        the image map.(IE: try playing with the HTML generating the image
  10.  *        map))
  11.  */
  12.  
  13.  
  14.  
  15. // import the phpSerial class
  16. include('php_serial.class.php');
  17.  
  18. // is $_GET['cycle'] set, if so send appropriate
  19. // cycle value to the serial connection
  20. if (isset($_GET['cycle'])) {
  21.   $cycle = $_GET['cycle'];
  22.   unset($_GET['cycle']);  
  23.  
  24.   // Setup the serial connection to print to
  25.   $serial = new phpSerial;
  26.  
  27.   // configure some settings
  28.   $serial->deviceSet("/dev/ttyUSB0");
  29.   $serial->confBaudRate(9600);
  30.   $serial->confParity("none");
  31.   $serial->confCharacterLength(8);
  32.   $serial->confStopBits(1);
  33.   $serial->confFlowControl("none");
  34.  
  35.   // open the serial device
  36.   $serial->deviceOpen();
  37.  
  38.   // send appropriate value to serial connection
  39.   if ($cycle == 0) {
  40.     $serial->sendMessage("0"); // initiate cycle 0
  41.   }
  42.   if ($cycle == 1) {
  43.     $serial->sendMessage("1"); // initiate cycle 1
  44.   }
  45.   if ($cycle == 2) {
  46.     $serial->sendMessage("2"); // initiate cycle 2
  47.   }
  48.   if ($cycle == 3) {
  49.     $serial->sendMessage("3"); // initiate cycle 3
  50.   }
  51.  
  52.   // close the serial connection
  53.   $serial->deviceClose();
  54. }
  55.  
  56.  
  57. // HTML to generate image map
  58. echo '<html>\n
  59. <body>\n
  60. <img src="img/PSP_Interface.jpg" usemap="#psp_interface_imgmap" border="0" width="480" height="272" alt="" />\n
  61. <map name="psp_interface_imgmap">\n
  62. <area shape="rect" coords="2,3,116,266" href="'.$_SERVER['PHP_SELF'].'?cycle=0" alt="" title=""    />\n
  63. <area shape="rect" coords="123,2,237,266" href="'.$_SERVER['PHP_SELF'].'?cycle=1" alt="" title=""    />\n
  64. <area shape="rect" coords="243,2,356,267" href="'.$_SERVER['PHP_SELF'].'?cycle=2" alt="" title=""    />\n
  65. <area shape="rect" coords="362,2,477,267" href="'.$_SERVER['PHP_SELF'].'?cycle=3" alt="" title=""    />\n
  66. </map>\n
  67. </body>\n
  68. </html>\n';
  69.  
  70. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement