Пример #1
0
 public function offset_setting()
 {
     $template_data = array();
     $error = '';
     $this->load->library('parser');
     $this->lang->load('printerstate/nozzles', $this->config->item('language'));
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $this->load->helper('printerstate');
         $top_offset = $this->input->post('top_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         $bot_offset = $this->input->post('bot_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         $right_offset = $this->input->post('right_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         $left_offset = $this->input->post('left_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         if ($top_offset * $bot_offset != 0 || $right_offset * $left_offset != 0) {
             $error .= t('invalid_input') . '<br/>';
         } else {
             $array_data = array();
             if ($top_offset != 0) {
                 $array_data['Y'] = -$top_offset;
             } else {
                 if ($bot_offset != 0) {
                     $array_data['Y'] = $bot_offset;
                 }
             }
             if ($right_offset != 0) {
                 $array_data['X'] = -$right_offset;
             } else {
                 if ($left_offset != 0) {
                     $array_data['X'] = $left_offset;
                 }
             }
             if (count($array_data)) {
                 $cr = 0;
                 foreach (array('X', 'Y') as $axis) {
                     if (array_key_exists($axis, $array_data)) {
                         $value = 0;
                         $cr = PrinterState_getOffset($axis, $value);
                         if ($cr != ERROR_OK) {
                             $error .= t('marlin_error') . '<br/>';
                             $this->load->helper('printerlog');
                             PrinterLog_logError('get ancient offset error, axis: ' . $axis . ', cr: ' . $cr, __FILE__, __LINE__);
                             break;
                         }
                         $array_data[$axis] += $value;
                         // add new offset on the ancient offset
                     }
                 }
                 if (count($error)) {
                     // we have no error for getting ancient offset, goto setting offset
                     $cr = PrinterState_setOffset($array_data);
                     if ($cr == ERROR_WRONG_PRM) {
                         $error .= t('value_zone_error') . '<br/>';
                         $this->load->helper('printerlog');
                         PrinterLog_logError('pass value zone for offset', __FILE__, __LINE__);
                     } else {
                         if ($cr != ERROR_OK) {
                             $error .= t('marlin_error') . '<br/>';
                             $this->load->helper('printerlog');
                             PrinterLog_logError('set offset error, axis: ' . $axis . ', cr: ' . $cr, __FILE__, __LINE__);
                         } else {
                             $this->output->set_header('Location: /printerstate/nozzles_adjustment');
                             return;
                         }
                     }
                 }
             }
         }
     }
     $template_data = array('nozzles_title' => t('nozzles_title'), 'nozzles_intro' => t('nozzles_intro'), 'collapsible_1' => t('collapsible_1'), 'collapsible_2' => t('collapsible_2'), 'back' => t('back'), 'home' => t('home'), 'error' => $error);
     $this->_parseBaseTemplate(t('nozzle_offset_pagetitle'), $this->parser->parse('printerstate/offset_setting', $template_data, TRUE));
     return;
 }
Пример #2
0
 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;
 }