示例#1
0
 public static function pulse($pin, $miliseconds, $state)
 {
     Gpio::write($pin, $state);
     usleep($miliseconds);
     $state = $state == 1 ? 0 : 1;
     Gpio::write($pin, $state);
 }
示例#2
0
function wirerelay_plugin_change_state($engine, $state)
{
    $wireRelay = new WireRelay();
    $wireRelay = $wireRelay->getById($engine);
    Gpio::mode($wireRelay->pin, 'out');
    if ($wireRelay->pulse == 0) {
        Gpio::write($wireRelay->pin, $state);
    } else {
        Gpio::pulse($wireRelay->pin, $wireRelay->pulse, 1);
    }
    //Reference device state change for other plugins
    $device = new Device();
    $device = $device->load(array('plugin' => 'wireRelay', 'uid' => $wireRelay->id));
    $device->setValue('value', $state);
    $device->save();
}
function wirerelay_plugin_change_state($engine, $state)
{
    $wireRelay = new WireRelay();
    $wireRelay = $wireRelay->getById($engine);
    Gpio::mode($wireRelay->pin, 'out');
    if ($wireRelay->pulse == 0) {
        Gpio::write($wireRelay->pin, $state);
    } else {
        Gpio::pulse($wireRelay->pin, $wireRelay->pulse, 1);
    }
}
示例#4
0
             } else {
                 echo '<br/>Plugin invalide, fichier principal manquant <span class="label label-error">Erreur</span>';
             }
         } else {
             echo '<br/>Echec de l\'extraction <span class="label label-error">Erreur</span>';
         }
         unlink($tempZipName);
     } else {
         echo '<br/>Echec du téléchargement <span class="label label-error">Erreur</span>';
     }
     break;
 case 'CHANGE_GPIO_STATE':
     if ($myUser == false) {
         exit('Vous devez vous connecter pour cette action.');
     } else {
         Gpio::write($_["pin"], $_["state"], true);
     }
     break;
     // Gestion des interfaces de seconde génération
 // Gestion des interfaces de seconde génération
 case 'SUBSCRIBE_TO_CLIENT':
     Action::write(function ($_, &$response) {
         global $myUser, $conf;
         if (!isset($_['ip'])) {
             throw new Exception("IP invalide");
         }
         if (!isset($_['port']) || !is_numeric($_['port'])) {
             throw new Exception("Port invalide");
         }
         $url = Functions::getBaseUrl('action.php') . '/action.php';
         $client = new CLient($_['ip'], $_['port']);
function speechcommands_action()
{
    global $_, $conf, $myUser;
    switch ($_['action']) {
        case 'plugin_speechcommands_save':
            if (!$myUser->can('speech_command', 'c')) {
                exit('Permissions insufisantes');
            }
            require_once 'SpeechCommand.class.php';
            $command = new SpeechCommand();
            $command = !empty($_['id']) ? $command->getById($_['id']) : new SpeechCommand();
            $command->command = $_['command'];
            $command->action = $_['type'];
            $command->parameter = $_['parameter'];
            $command->confidence = $_['confidence'];
            $command->state = $_['state'] == 'on' ? 1 : 0;
            $command->save();
            header('location: setting.php?section=speechcommands');
            break;
        case 'plugin_speechcommands_delete':
            if (!$myUser->can('speech_command', 'd')) {
                exit('Permissions insufisantes');
            }
            require_once 'SpeechCommand.class.php';
            $command = new SpeechCommand();
            $command->delete(array('id' => $_['id']));
            header('location: setting.php?section=speechcommands');
            break;
        case 'speechcommands_execute':
            global $_;
            require_once 'SpeechCommand.class.php';
            $command = new SpeechCommand();
            $command = $command->getById($_['command']);
            set_error_handler(function ($errno, $errstr, $errfile, $errline, array $errcontext) {
                // error was suppressed with the @-operator
                if (0 === error_reporting()) {
                    return false;
                }
                throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
            });
            try {
                switch ($command->action) {
                    case 'talk':
                        $response = array('responses' => array(array('type' => 'talk', 'sentence' => $command->parameter)));
                        $json = json_encode($response);
                        echo $json == '[]' ? '{}' : $json;
                        break;
                    case 'gpio':
                        list($pin, $value) = explode(',', $command->parameter);
                        Gpio::write($pin, $value, true);
                        break;
                    case 'server_command':
                        System::commandSilent(html_entity_decode($command->parameter));
                        echo '{}';
                        break;
                    case 'client_command':
                        $response = array('responses' => array(array('type' => 'command', 'program' => $command->parameter)));
                        $json = json_encode($response);
                        echo $json == '[]' ? '{}' : $json;
                        break;
                    case 'sound':
                        $response = array('responses' => array(array('type' => 'sound', 'file' => $command->parameter)));
                        $json = json_encode($response);
                        echo $json == '[]' ? '{}' : $json;
                        break;
                    case 'url':
                        $content = file_get_contents($command->parameter);
                        $response = array('responses' => array(array('type' => 'talk', 'sentence' => $content)));
                        $json = json_encode($response);
                        echo $json == '[]' ? '{}' : $json;
                        break;
                    default:
                        throw new Exception('Aucun action n\'est spécifiée');
                        break;
                }
            } catch (Exception $e) {
                $response = array('responses' => array(array('type' => 'talk', 'sentence' => Personality::response('WORRY_EMOTION') . ', le problème viens de : ' . $e->getMessage())));
                $json = json_encode($response);
                echo $json == '[]' ? '{}' : $json;
            }
            break;
    }
}