Beispiel #1
0
<?php

if (\Request::method() === 'POST') {
    $pin = \Request::input('pin');
    $state = \Request::input('state');
    if (empty($pin) && $pin !== 0 || empty($state) && $state !== 0) {
        throw new \DreamFactory\Core\Exceptions\BadRequestException('Please provide pin and state data');
    }
    $gpio = new \a15lam\RpiGpio\GPIO();
    $result = $gpio->write($pin, $state);
    $result = empty($result) ? ['success' => true] : $result;
    return \DreamFactory\Core\Utility\ResourcesWrapper::cleanResources($result);
} else {
    throw new \DreamFactory\Core\Exceptions\BadRequestException('Only POST is accepted');
}
Beispiel #2
0
<?php

if (\Request::method() === 'POST') {
    $pulse = \Request::input('pulse');
    if (empty($pulse)) {
        throw new \DreamFactory\Core\Exceptions\BadRequestException('Please provide pulse data');
    }
    if ($pulse < 27) {
        $pulse = 27;
    }
    if ($pulse > 107) {
        $pulse = 107;
    }
    $gpio = new \a15lam\RpiGpio\GPIO();
    $gpio->setupPWM();
    $result = $gpio->pwm($pulse);
    $result = empty($result) ? ['success' => true] : $result;
    return \DreamFactory\Core\Utility\ResourcesWrapper::cleanResources($result);
} else {
    throw new \DreamFactory\Core\Exceptions\BadRequestException('Only POST is accepted');
}
Beispiel #3
0
<?php

if (\Request::method() === 'POST') {
    $pin = \Request::input('pin');
    $state = \Request::input('state');
    if (empty($pin) && $pin !== 0 || empty($state) && $state !== 0) {
        throw new \DreamFactory\Core\Exceptions\BadRequestException('Please provide pin and state data');
    }
    $gpio = new \a15lam\RpiGpio\GPIO();
    $result = $gpio->mode($pin, $state);
    $result = empty($result) ? ['success' => true] : $result;
    return \DreamFactory\Core\Utility\ResourcesWrapper::cleanResources($result);
} else {
    throw new \DreamFactory\Core\Exceptions\BadRequestException('Only POST is accepted');
}
Beispiel #4
0
<?php

include 'src/GPIO.php';
$gpio = new \a15lam\RpiGpio\GPIO();
$gpio->mode(0, 'out');
$gpio->mode(2, 'out');
while (true) {
    $gpio->write(0, 1);
    sleep(1);
    $gpio->write(0, 0);
    $gpio->write(2, 1);
    sleep(1);
    $gpio->write(2, 0);
}