/** * Switch pin ON / OFF * <pre class="PUT"> PUT [url]/switch/set/:pin/:value/</pre> * * @param String - pin number (wPi pin) * @param String - value (ON/OFF) * * @example * No POST Body * * @return JSON - **Object** success message * * @since 2016-02-05 * @author Wesley Dekkers <*****@*****.**> * @todo check if values are set correctly * @todo check if pin exists **/ public function set($pin, $value) { try { if (!is_numeric($pin)) { throw new \Exception("Pin should be numeric"); } # Load the model $set_gpio = new \Models\GPIO(); $set_gpio->pin = $pin; # Decide what to do if ($value == 'ON') { $set_gpio->mode = 'OUT'; $set_gpio->status = 0; } elseif ($value == 'OFF') { $set_gpio->mode = 'IN'; $set_gpio->status = 1; } else { throw new \Exception("No valid pin value entered"); } // Execute the commands $set_gpio->mode(); $set_gpio->write(); // Reload the pin echo json_encode($set_gpio->get()); } catch (\Exception $e) { echo \Rhonda\Error::handle($e); } }
/** * Set a pin mode * <pre class="PUT"> PUT [url]/gpio/mode/:pin/:mode/</pre> * * @param String - pin number (wPi pin) * @param String - mode IN/OUT (or others) * * @example * No POST Body * * @return JSON - **Object** success message * * @since 2016-02-05 * @author Wesley Dekkers <*****@*****.**> * @todo check if modes are set correctly * @todo check if pin exists **/ public function mode($pin, $mode) { try { if (!is_numeric($pin)) { throw new \Exception("Pin should be numeric", 1); } $mode_gpio = new \Models\GPIO(); $mode_gpio->pin = $pin; $mode_gpio->mode = $mode; $mode_gpio->mode(); echo \Rhonda\Success::create(); } catch (\Exception $e) { echo \Rhonda\Error::handle($e); } }