Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /* A simple PHP script using the PHPSerial class to
- * send messages over the serial connection to the arduino
- * from the image map.
- *
- * issues:
- * - after changing the cycle to 3 from the PSP you cannot change to
- * any other cycles. (I think the issue is how the PSP interprets
- * the image map.(IE: try playing with the HTML generating the image
- * map))
- */
- // import the phpSerial class
- include('php_serial.class.php');
- // is $_GET['cycle'] set, if so send appropriate
- // cycle value to the serial connection
- if (isset($_GET['cycle'])) {
- $cycle = $_GET['cycle'];
- unset($_GET['cycle']);
- // Setup the serial connection to print to
- $serial = new phpSerial;
- // configure some settings
- $serial->deviceSet("/dev/ttyUSB0");
- $serial->confBaudRate(9600);
- $serial->confParity("none");
- $serial->confCharacterLength(8);
- $serial->confStopBits(1);
- $serial->confFlowControl("none");
- // open the serial device
- $serial->deviceOpen();
- // send appropriate value to serial connection
- if ($cycle == 0) {
- $serial->sendMessage("0"); // initiate cycle 0
- }
- if ($cycle == 1) {
- $serial->sendMessage("1"); // initiate cycle 1
- }
- if ($cycle == 2) {
- $serial->sendMessage("2"); // initiate cycle 2
- }
- if ($cycle == 3) {
- $serial->sendMessage("3"); // initiate cycle 3
- }
- // close the serial connection
- $serial->deviceClose();
- }
- // HTML to generate image map
- echo '<html>\n
- <body>\n
- <img src="img/PSP_Interface.jpg" usemap="#psp_interface_imgmap" border="0" width="480" height="272" alt="" />\n
- <map name="psp_interface_imgmap">\n
- <area shape="rect" coords="2,3,116,266" href="'.$_SERVER['PHP_SELF'].'?cycle=0" alt="" title="" />\n
- <area shape="rect" coords="123,2,237,266" href="'.$_SERVER['PHP_SELF'].'?cycle=1" alt="" title="" />\n
- <area shape="rect" coords="243,2,356,267" href="'.$_SERVER['PHP_SELF'].'?cycle=2" alt="" title="" />\n
- <area shape="rect" coords="362,2,477,267" href="'.$_SERVER['PHP_SELF'].'?cycle=3" alt="" title="" />\n
- </map>\n
- </body>\n
- </html>\n';
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement