public function api_updatebot() { if (!$this->args('bot_id')) { throw new Exception("You must provide the 'bot_id' parameter."); } $bot = new Bot($this->args('bot_id')); if (!$bot->isHydrated()) { throw new Exception("Bot does not exist."); } if (!$bot->isMine()) { throw new Exception("This bot is not yours."); } //if (!$this->args('manufacturer')) // throw new Exception('Bot manufacturer is a required parameter.'); //if (!$this->args('model')) // throw new Exception('Bot model is a required parameter.'); if ($this->args('name')) { $bot->set('name', $this->args('name')); } if ($this->args('name')) { $bot->set('identifier', $this->args('identifier')); } if ($this->args('manufacturer')) { $bot->set('manufacturer', $this->args('manufacturer')); } if ($this->args('model')) { $bot->set('model', $this->args('model')); } if ($this->args('electronics')) { $bot->set('electronics', $this->args('electronics')); } if ($this->args('firmware')) { $bot->set('firmware', $this->args('firmware')); } if ($this->args('extruder')) { $bot->set('extruder', $this->args('extruder')); } if ($this->args('status')) { $bot->set('status', $this->args('status')); } if ($this->args('error_text')) { $bot->set('error_text', $this->args('error_text')); } $bot->save(); Activity::log("updated the bot " . $bot->getLink() . " via the API."); return $bot->getAPIData(); }
public function driver_form() { try { //load our bot $bot = new Bot($this->args('id')); if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } if ($this->args('token_id') == 0) { $this->set('nodriver', "No driver was selected"); } else { //load our token $token = new OAuthToken($this->args('token_id')); if (!$token->isHydrated()) { throw new Exception("Could not find that computer."); } if (!$token->isMine()) { throw new Exception("This is not your computer."); } //what driver form to create? $driver = $this->args('driver'); //pass on our info. $this->set('bot', $bot); $this->set('driver', $driver); $this->set('token', $token); $devices = json::decode($token->get('device_data')); $this->set('devices', $devices); //pull in our driver config $driver_config = $bot->getDriverConfig(); //if we're using the same driver, pull in old values... if ($driver == $bot->get('driver_name')) { $this->set('driver_config', $driver_config); if (is_object($driver_config)) { $this->set('delay', $driver_config->delay); $this->set('serial_port', $driver_config->port); $this->set('baudrate', $driver_config->baud); } } else { if ($driver == "dummy") { $this->set('delay', '0.001'); } } //pull in our old webcam values too. if (is_object($driver_config) && !empty($driver_config->webcam)) { $this->set('webcam_id', $driver_config->webcam->id); $this->set('webcam_name', $driver_config->webcam->name); $this->set('webcam_device', $driver_config->webcam->device); $this->set('webcam_brightness', $driver_config->webcam->brightness); $this->set('webcam_contrast', $driver_config->webcam->contrast); } else { //some default webcam settings. $this->set('webcam_id', ''); $this->set('webcam_name', ''); $this->set('webcam_device', ''); $this->set('webcam_brightness', 50); $this->set('webcam_contrast', 50); } $this->set('driver_config', $driver_config); $this->set('baudrates', array(250000, 115200, 57600, 38400, 28880, 19200, 14400, 9600)); } } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); } }
public function listjobs() { $this->assertLoggedIn(); try { //how do we find them? if ($this->args('id')) { $bot = new Bot($this->args('id')); } //did we really get someone? if (!$bot->isHydrated()) { throw new Exception("Could not find that bot."); } if (!$bot->isMine()) { throw new Exception("You cannot view that bot."); } $this->set('bot', $bot); $this->setTitle("Bot Jobs - " . $bot->getName()); $collection = $bot->getJobs(); $per_page = 20; $page = $collection->putWithinBounds($this->args('page'), $per_page); $this->set('per_page', $per_page); $this->set('total', $collection->count()); $this->set('page', $page); $this->set('jobs', $collection->getPage($page, $per_page)); $this->set('status', $status); } catch (Exception $e) { $this->set('megaerror', $e->getMessage()); $this->setTitle("View Bot - Error"); } }