/** * 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); } }
/** * Write a pin status * <pre class="PUT"> PUT [url]/gpio/write/:pin/:status/</pre> * * @param String - pin number (wPi pin) * @param String - status * * @example * No POST Body * * @return JSON - **Object** success message * * @since 2016-02-05 * @author Wesley Dekkers <*****@*****.**> * @todo check if statuss are set correctly * @todo check if pin exists **/ public function write($pin, $status) { try { if (!is_numeric($pin) || !is_numeric($status)) { throw new \Exception("Pin and Value should both be numeric", 1); } $write_gpio = new \Models\GPIO(); $write_gpio->pin = $pin; $write_gpio->status = $status; $write_gpio->write(); echo \Rhonda\Success::create(); } catch (\Exception $e) { echo \Rhonda\Error::handle($e); } }