コード例 #1
0
ファイル: rest.php プロジェクト: Jaesin/zim-web
 public function get()
 {
     $parameter = NULL;
     $cr = 0;
     $display = NULL;
     $api_prm = NULL;
     $this->load->helper(array('printerstate', 'zimapi'));
     $parameter = $this->input->get('p');
     //return false if missing
     if ($parameter) {
         switch ($parameter) {
             case PRINTERSTATE_PRM_EXTRUDER:
                 $cr = PrinterState_getExtruder($display);
                 //$abb_extruder
                 break;
             case PRINTERSTATE_PRM_TEMPER:
                 // check which temperature we want
                 $has_e = $this->input->get('e');
                 $has_h = $this->input->get('h');
                 $has_v = $this->input->get('v');
                 if ($has_e === FALSE && $has_h === FALSE) {
                     $cr = ERROR_MISS_PRM;
                 } else {
                     if (!($has_e === FALSE) && !($has_h === FALSE)) {
                         $cr = ERROR_WRONG_PRM;
                     } else {
                         if (!($has_e === FALSE) && !($has_v === FALSE)) {
                             // refuse getting data not existed for mono extruder
                             if ($has_v == 'l' && $this->config->item('nb_extruder') == 1) {
                                 $cr = ERROR_WRONG_PRM;
                             } else {
                                 if (in_array($has_v, array('l', 'r'))) {
                                     // 							$tmp_array = PrinterState_getExtruderTemperaturesAsArray();
                                     // 							$cr = ERROR_OK;
                                     // 							$display = ($has_v == 'l')
                                     // 									? $tmp_array[PRINTERSTATE_LEFT_EXTRUD]
                                     // 									: $tmp_array[PRINTERSTATE_RIGHT_EXTRUD];
                                     $cr = PrinterState_getTemperature($display, 'e', $has_v);
                                 } else {
                                     $cr = ERROR_WRONG_PRM;
                                 }
                             }
                         } else {
                             $api_prm = $has_e === FALSE ? 'h' : 'e';
                             $cr = PrinterState_getTemperature($display, $api_prm);
                         }
                     }
                 }
                 break;
             case PRINTERSTATE_PRM_CARTRIDGE:
                 $api_prm = $this->input->get('v');
                 // refuse getting data not existed for mono extruder
                 if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) {
                     $cr = ERROR_WRONG_PRM;
                 } else {
                     $cr = PrinterState_getCartridge($display, $api_prm);
                 }
                 break;
             case PRINTERSTATE_PRM_INFO:
                 //TODO need add SSO account
                 $cr = ERROR_OK;
                 $display = PrinterState_getInfo();
                 break;
             case 'render':
                 $this->_return_under_construction();
                 return;
                 break;
             case PRINTERSTATE_PRM_ACCELERATION:
                 $cr = PrinterState_getAcceleration($display);
                 break;
             case PRINTERSTATE_PRM_SPEED_MOVE:
             case PRINTERSTATE_PRM_SPEED_EXTRUDE:
                 $cr = PrinterState_getSpeed($display);
                 break;
             case PRINTERSTATE_PRM_COLDEXTRUSION:
                 $value = NULL;
                 $cr = PrinterState_getColdExtrusion($value);
                 if ($cr == ERROR_OK) {
                     if ($value == TRUE) {
                         $display = 'on';
                     } else {
                         $display = 'off';
                     }
                 }
                 break;
             case PRINTERSTATE_PRM_FILAMENT:
                 $value = NULL;
                 $api_prm = $this->input->get('v');
                 // refuse getting data not existed for mono extruder
                 if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) {
                     $cr = ERROR_WRONG_PRM;
                 } else {
                     if ($api_prm) {
                         $cr = ERROR_OK;
                         $value = PrinterState_getFilamentStatus($api_prm);
                         if ($value == TRUE) {
                             $display = 'true';
                         } else {
                             $display = 'false';
                         }
                     } else {
                         $cr = ERROR_MISS_PRM;
                     }
                 }
                 break;
             case PRINTERSTATE_PRM_ENDSTOP:
                 $status = NULL;
                 $abb_endstop = $this->input->get('axis');
                 $cr = PrinterState_getEndstop($abb_endstop, $status);
                 if ($cr == ERROR_OK) {
                     $display = $status ? 'on' : 'off';
                 }
                 break;
             case PRINTERSTATE_PRM_STRIPLED:
                 $value = NULL;
                 $cr = PrinterState_getStripLedStatus($value);
                 if ($cr == ERROR_OK) {
                     if ($value == TRUE) {
                         $display = 'on';
                     } else {
                         $display = 'off';
                     }
                 }
                 break;
             case PRINTERSTATE_PRM_HEADLED:
                 $value = NULL;
                 $cr = PrinterState_getTopLedStatus($value);
                 if ($cr == ERROR_OK) {
                     if ($value == TRUE) {
                         $display = 'on';
                     } else {
                         $display = 'off';
                     }
                 }
                 break;
             case PRINTERSTATE_PRM_OFFSET:
                 $value = NULL;
                 $axis = $this->input->get('axis');
                 if ($axis) {
                     $cr = PrinterState_getOffset($axis, $value);
                     if ($cr == ERROR_OK) {
                         $display = $value;
                     }
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case PRINTERSTATE_PRM_POSITION:
                 $cr = PrinterState_getPosition($display);
                 break;
             case ZIMAPI_PRM_CAPTURE:
                 $path_capture = '';
                 $password = $this->input->get('password');
                 if (!ZimAPI_checkCameraPassword($password)) {
                     $cr = ERROR_WRONG_PWD;
                     break;
                 }
                 $this->load->helper('file');
                 if (ZimAPI_cameraCapture($path_capture)) {
                     $this->output->set_content_type(get_mime_by_extension($path_capture))->set_output(@file_get_contents($path_capture));
                     return;
                 } else {
                     $cr = ERROR_INTERNAL;
                 }
                 break;
             case ZIMAPI_PRM_VIDEO_MODE:
                 if (ZimAPI_checkCamera($display)) {
                     $cr = ERROR_OK;
                 } else {
                     $cr = ERROR_INTERNAL;
                 }
                 break;
             case ZIMAPI_PRM_PRESET:
                 if (ZimAPI_getPreset($display)) {
                     $cr = ERROR_OK;
                 } else {
                     $cr = ERROR_INTERNAL;
                 }
                 break;
             case ZIMAPI_PRM_UPGRADE:
                 if (ZimAPI_getUpgradeMode($display)) {
                     $cr = ERROR_OK;
                 } else {
                     $cr = ERROR_INTERNAL;
                 }
                 if ($display != 'off') {
                     $display = 'on';
                 }
                 break;
             case ZIMAPI_PRM_PROXY:
                 if (ZimAPI_getTromboning()) {
                     $display = 'on';
                 } else {
                     $display = 'off';
                 }
                 $cr = ERROR_OK;
                 break;
             case ZIMAPI_PRM_SSH:
                 $status_current = NULL;
                 if (ZimAPI_getSSH($status_current)) {
                     $cr = ERROR_OK;
                     if ($status_current) {
                         $display = 'on';
                     } else {
                         $display = 'off';
                     }
                 } else {
                     $cr = ERROR_INTERNAL;
                 }
                 break;
             case ZIMAPI_PRM_STATS:
                 if (ZimAPI_getStatistic()) {
                     $display = 'on';
                 } else {
                     $display = 'off';
                 }
                 $cr = ERROR_OK;
                 break;
             default:
                 $cr = ERROR_WRONG_PRM;
                 break;
         }
     } else {
         $cr = ERROR_MISS_PRM;
     }
     if ($cr != ERROR_OK) {
         $display = $cr . " " . t(MyERRMSG($cr));
     }
     $this->output->set_status_header($cr, $display);
     // 		http_response_code($cr);
     $this->output->set_content_type(RETURN_CONTENT_TYPE);
     // 		echo $display;
     $this->load->library('parser');
     $this->parser->parse('plaintxt', array('display' => $display));
     return;
 }
コード例 #2
0
ファイル: printerstate.php プロジェクト: Jaesin/zim-web
 public function index()
 {
     $template_data = array();
     $ret_val = 0;
     $status_upgrade = FALSE;
     $status_tromboning = FALSE;
     $status_statistic = FALSE;
     $status_ssh = FALSE;
     $option_selected = 'selected="selected"';
     // get function status
     $this->load->helper(array('zimapi', 'printerlog'));
     $ret_val = ZimAPI_getUpgradeMode($status_upgrade);
     if ($ret_val != TRUE) {
         $status_upgrade = 'off';
     }
     $ret_val = ZimAPI_getSSH($status_ssh);
     if ($ret_val != TRUE) {
         $status_ssh = FALSE;
     }
     $status_tromboning = ZimAPI_getTromboning();
     $status_statistic = ZimAPI_getStatistic();
     // 		$this->changecartridge();
     $this->load->library('parser');
     $this->lang->load('printerstate/index', $this->config->item('language'));
     // parse the main body
     $template_data = array('reset_network' => t('reset_network'), 'printer_info' => t('printer_info'), 'back' => t('back'), 'set_hostname' => t('set_hostname'), 'set_preset' => t('set_preset'), 'upgrade_on' => $status_upgrade != 'off' ? $option_selected : NULL, 'tromboning_on' => $status_tromboning == TRUE ? $option_selected : NULL, 'statistic_on' => $status_statistic == TRUE ? $option_selected : NULL, 'remote_control_on' => $status_ssh == TRUE ? $option_selected : NULL, 'upgrade' => t('upgrade'), 'tromboning' => t('tromboning'), 'remote_control' => t('remote_control'), 'function_on' => t('function_on'), 'function_off' => t('function_off'), 'nozzles_adjustments' => t('nozzles_adjustments'), 'support' => t('support'), 'bicolor' => $this->config->item('nb_extruder') >= 2 ? 'true' : 'false');
     // parse all page
     $this->_parseBaseTemplate(t('printerstate_index_pagetitle'), $this->parser->parse('printerstate/index', $template_data, TRUE));
     return;
 }
コード例 #3
0
ファイル: test_version.php プロジェクト: Jaesin/zim-web
 public function index()
 {
     $template_data = array();
     $temp_info = array();
     $array_info = array();
     $sso_name = NULL;
     $upgrade_mode = NULL;
     $profile_link = NULL;
     $this->load->helper(array('printerstate', 'zimapi'));
     $this->load->library('parser');
     $this->lang->load('printerstate/printerinfo', $this->config->item('language'));
     $this->lang->load('test_version', $this->config->item('language'));
     ZimAPI_getPrinterSSOName($sso_name);
     ZimAPI_getUpgradeMode($upgrade_mode, $profile_link);
     $profile_link = $this->_bindUpgradeURL($profile_link);
     $temp_info = PrinterState_getInfoAsArray();
     $array_info = array(array('title' => t('profile_title'), 'value' => $upgrade_mode . ' [ ' . $profile_link . ' ]'), array('title' => t('version_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_VERSION]), array('title' => t('next_version_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_VERSION_N]), array('title' => t('type_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_TYPE]), array('title' => t('serial_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_SERIAL]), array('title' => t('extruder_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_NB_EXTRUD]), array('title' => t('marlin_title'), 'value' => $temp_info[PRINTERSTATE_TITLE_VER_MARLIN]), array('title' => t('ip_address'), 'value' => $temp_info[ZIMAPI_TITLE_IP]));
     // parse the main body
     $template_data = array('array_info' => $array_info, 'port_test_title' => t('port_test_title'), 'port_test_ok' => t('port_test_ok'), 'port_test_ko' => t('port_test_ko'), 'port_test_r80' => t('port_test_printer', array(80)), 'port_test_r443' => t('port_test_printer', array(443)), 'port_test_r4443' => t('port_test_printer', array(4443)), 'port_test_l80' => t('port_test_client', array(80)), 'port_test_l443' => t('port_test_client', array(443)));
     $this->_parseBaseTemplate(t('printerstate_printerinfo_pagetitle'), $this->parser->parse('test_version', $template_data, TRUE));
     return;
 }