示例#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
function ZimAPI_cameraOff()
{
    $CI =& get_instance();
    $output = NULL;
    $ret_val = 0;
    $command = $CI->config->item('camera') . ZIMAPI_PRM_CAMERA_STOP;
    $data_json = array();
    $fp = 0;
    $mode_current = '';
    if (!ZimAPI_checkCamera($mode_current)) {
        return FALSE;
    } else {
        if ($mode_current == ZIMAPI_VALUE_MODE_OFF) {
            return TRUE;
        } else {
            if (ZimAPI_checkCameraInBlock()) {
                return TRUE;
            }
        }
    }
    exec($command, $output, $ret_val);
    if ($ret_val != ERROR_NORMAL_RC_OK) {
        $CI =& get_instance();
        $CI->load->helper('printerlog');
        PrinterLog_logError('camera stop command error', __FILE__, __LINE__);
        return FALSE;
    }
    $data_json = array(ZIMAPI_TITLE_MODE => ZIMAPI_VALUE_MODE_OFF, ZIMAPI_TITLE_COMMAND => NULL);
    // write json file
    $fp = fopen($CI->config->item('temp') . ZIMAPI_FILENAME_CAMERA, 'w');
    if ($fp) {
        fwrite($fp, json_encode($data_json));
        fclose($fp);
    } else {
        $CI =& get_instance();
        $CI->load->helper('printerlog');
        PrinterLog_logError('write camera status error', __FILE__, __LINE__);
        return FALSE;
    }
    return TRUE;
}
示例#3
0
 public function cancel()
 {
     $ret_val = NULL;
     $this->load->helper('printer');
     $ret_val = Printer_stopPrint();
     if ($ret_val == TRUE) {
         $template_data = array();
         $array_status = array();
         $this->load->library('parser');
         $this->lang->load('printdetail', $this->config->item('language'));
         $this->load->helper('zimapi');
         if (Printer_checkCancelStatus() || !file_exists(ZIMAPI_FILEPATH_VIDEO_TS)) {
             if (ZimAPI_checkCamera($mode_current) && $mode_current == ZIMAPI_VALUE_MODE_HLS_IMG) {
                 $this->load->helper('printerlog');
                 PrinterLog_logMessage('detected in hls image timelapse mode, do not set camera', __FILE__, __LINE__);
             } else {
                 if (!ZimAPI_cameraOn(ZIMAPI_PRM_CAMERA_PRINTSTART)) {
                     $this->load->helper('printerlog');
                     PrinterLog_logError('can not set camera', __FILE__, __LINE__);
                 }
             }
         }
         // parse the main body
         $template_data = array('title' => t('Control your printing'), 'loading_player' => t('loading_player'), 'wait_info' => t('wait_hint_cancel'), 'finish_info' => t('finish_hint_cancel'), 'return_button' => t('Home'), 'return_url' => '/', 'video_url' => $this->config->item('video_url'), 'restart_url' => NULL, 'again_button' => t('Print again'));
         if (CoreStatus_getStatusArray($array_status) && is_array($array_status) && isset($array_status[CORESTATUS_TITLE_PRINTMODEL])) {
             if (strpos($array_status[CORESTATUS_TITLE_PRINTMODEL], CORESTATUS_VALUE_MID_PREFIXGCODE) === 0) {
                 // gcode library model
                 $gid = (int) substr($array_status[CORESTATUS_TITLE_PRINTMODEL], strlen(CORESTATUS_VALUE_MID_PREFIXGCODE));
                 $template_data['restart_url'] = '/printdetail/printgcode?id=' . $gid;
             } else {
                 $abb_cartridge = NULL;
                 $restart_url = NULL;
                 switch ($array_status[CORESTATUS_TITLE_PRINTMODEL]) {
                     case CORESTATUS_VALUE_MID_SLICE:
                         $restart_url = '/printdetail/printslice';
                         break;
                     case CORESTATUS_VALUE_MID_PRIME_L:
                         $abb_cartridge = 'l';
                     case CORESTATUS_VALUE_MID_PRIME_R:
                         $abb_cartridge = is_null($abb_cartridge) ? 'r' : $abb_cartridge;
                         $restart_url = '/printdetail/printprime?v=' . $abb_cartridge;
                         $template_data['title'] = t('title_prime');
                         $template_data['again_button'] = t('prime_agin');
                         break;
                     case CORESTATUS_VALUE_MID_CALIBRATION:
                         $restart_url = '/printmodel/detail?id=calibration';
                         break;
                     default:
                         // treat as pre-sliced model
                         $restart_url = '/printdetail/printmodel?id=' . $array_status[CORESTATUS_TITLE_PRINTMODEL];
                         break;
                 }
                 $template_data['restart_url'] = $restart_url;
             }
         }
         // parse all page
         $this->_parseBaseTemplate(t('printdetail_cancel_pagetitle'), $this->parser->parse('printdetail/cancel', $template_data, TRUE));
         return;
     } else {
         $this->load->helper('printerlog');
         PrinterLog_logError('can not stop printing', __FILE__, __LINE__);
         $this->output->set_status_header(403);
         return;
     }
     return;
 }