Ejemplo n.º 1
0
$action = isset($_POST['action']) ? $_POST['action'] : '';
$response = new stdClass();
$response->performed = '';
$response->error = '';
try {
    $robot = new Robot();
    switch ($action) {
        case 'connect':
            $response->performed = 'KuKuRobot001';
            break;
        case 'stop':
        case 'fwd':
        case 'rev':
        case 'left':
        case 'right':
            $robot->setDuration(isset($_POST['duration']) ? intval($_POST['duration']) : 0);
            $robot->{$action}();
            $response->performed = $action;
            break;
        case 'cam':
            $direction = isset($_POST['direction']) ? $_POST['direction'] : '';
            $position = isset($_POST['position']) ? $_POST['position'] : '';
            $response->performed = $robot->camera($direction, $position);
            break;
        case 'ping_dist':
            $response->performed = $robot->pingDist();
            break;
        case 'status':
            $response->data = $robot->status();
            $response->performed = 'status';
            break;
Ejemplo n.º 2
0
<?php

include '../Classes/Robot.php';
$action = isset($_POST['action']) ? $_POST['action'] : '';
$duration = isset($_POST['duration']) ? intval($_POST['duration']) : 1;
$performed = '';
$error = '';
try {
    switch ($action) {
        case 'fwd':
        case 'rev':
        case 'left':
        case 'right':
            $robot = new Robot();
            $robot->setDuration($duration);
            $robot->{$action}();
            $performed = $action;
            break;
    }
} catch (Exception $exception) {
    $error = $exception->getMessage();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<title>RobotCar</title>
</head>