Ejemplo n.º 1
0
 public function slice()
 {
     $cr = 0;
     $status_current = NULL;
     $array_cartridge = array();
     $custom_change = FALSE;
     $this->load->helper('slicer');
     // we bypass this call when checking status block in slicing to make possible for local slicing callback
     // so we have to check printer is really in remote slicing case when calling this function (return error if not so)
     CoreStatus_checkInIdle($status_current);
     if ($status_current == CORESTATUS_VALUE_SLICE && !file_exists(SLICER_FILE_REMOTE_STATUS)) {
         $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER);
         return;
         // never reach here
     }
     // check platform and filament present (do not check filament quantity)
     $cr = Slicer_checkPlatformColor($array_cartridge, $custom_change);
     if ($cr == ERROR_OK) {
         $cr = Slicer_changeTemperByCartridge($array_cartridge, $this->config->item('heat_bed'));
     }
     // start slice command after checking filament
     if ($cr == ERROR_OK) {
         $remote_slice = FALSE === $this->input->get('local') ? TRUE : FALSE;
         $cr = Slicer_slice($remote_slice && !$custom_change);
     }
     $this->_return_cr($cr);
     return;
 }
Ejemplo n.º 2
0
 public function changecartridge_action($mode = '')
 {
     $abb_cartridge = $this->input->get('v');
     if (!$abb_cartridge && !in_array($abb_cartridge, array('l', 'r'))) {
         $this->output->set_status_header(403);
         // invalid request
         return;
     }
     if ($mode == 'unload_r') {
         $mode = 'unload';
     } else {
         if ($mode == 'load_r') {
             $mode = 'load';
         } else {
             if ($mode != 'cancel_unload') {
                 //block request when not in idle
                 $this->load->helper('corestatus');
                 if (CoreStatus_checkInIdle() == FALSE) {
                     $this->output->set_status_header(403);
                     // bad request
                     return;
                 }
             }
         }
     }
     switch ($mode) {
         case 'unload':
             $ret_val = PrinterState_unloadFilament($abb_cartridge);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header($ret_val, MyERRMSG($ret_val));
             }
             break;
         case 'cancel_unload':
             $ret_val = 0;
             @unlink(PRINTERSTATE_FILE_UNLOAD_HEAT);
             $ret_val = CoreStatus_setInIdle();
             if ($ret_val == FALSE) {
                 $this->load->helper('printerlog');
                 PrinterLog_logError('can not set idle after cancelling unloading', __FILE__, __LINE__);
                 $this->output->set_status_header(ERROR_INTERNAL);
             }
             break;
         case 'load':
             $ret_val = PrinterState_loadFilament($abb_cartridge);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header($ret_val);
             }
             break;
         case 'detail':
             $id_model = $this->input->get('id');
             $this->_display_changecartridge_cartridge_detail($abb_cartridge, $id_model);
             break;
         case 'write':
             $ret_val = 0;
             $array_data = array();
             $array_old = array();
             $color = $this->input->get('c');
             $temper = (int) $this->input->get('t');
             $material = (int) $this->input->get('m');
             $length = (int) $this->input->get('l') * 1000;
             $abb_cartridge = $this->input->get('v');
             // get cartridge type from old RFID
             $ret_val = PrinterState_getCartridgeAsArray($array_old, $abb_cartridge, FALSE);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header(403);
                 $this->load->helper('printerlog');
                 PrinterLog_logMessage('read rfid error: ' . $ret_val, __FILE__, __LINE__);
                 break;
             }
             // change color from name to hex code
             $this->load->helper('printlist');
             $ret_val = ModelList__changeColorName($color);
             if ($ret_val == ERROR_WRONG_PRM) {
                 $this->output->set_status_header(404);
                 $this->load->helper('printerlog');
                 PrinterLog_logMessage('unknown color name: ' . $color, __FILE__, __LINE__);
                 break;
             }
             $color = str_replace('#', '', $color);
             // write RFID card
             $array_data = array(PRINTERSTATE_TITLE_COLOR => $color, PRINTERSTATE_TITLE_EXT_TEMPER => $temper, PRINTERSTATE_TITLE_INITIAL => $length, PRINTERSTATE_TITLE_MATERIAL => $material, PRINTERSTATE_TITLE_CARTRIDGE => $array_old[PRINTERSTATE_TITLE_CARTRIDGE]);
             $ret_val = PrinterState_setCartridgeAsArray($abb_cartridge, $array_data);
             if ($ret_val != ERROR_OK) {
                 $this->output->set_status_header(403);
                 $this->load->helper('printerlog');
                 PrinterLog_logMessage('write rfid error: ' . $ret_val, __FILE__, __LINE__);
                 break;
             }
             break;
         default:
             $this->output->set_status_header(403);
             // unknown request
             break;
     }
     return;
 }
Ejemplo n.º 3
0
 public function youtube_form()
 {
     $array_status = array();
     $model_displayname = NULL;
     $this->load->library('parser');
     $this->lang->load('youtube_form', $this->config->item('language'));
     $this->lang->load('printdetail', $this->config->item('language'));
     // timelapse default model name
     $this->load->helper('corestatus');
     if (CoreStatus_checkInIdle($status_current, $array_status) && array_key_exists(CORESTATUS_TITLE_PRINTMODEL, $array_status)) {
         $model_id = NULL;
         if (strpos($array_status[CORESTATUS_TITLE_PRINTMODEL], CORESTATUS_VALUE_MID_PREFIXGCODE) === 0) {
             // gcode library model
             $gcode_info = array();
             $gid = (int) substr($array_status[CORESTATUS_TITLE_PRINTMODEL], strlen(CORESTATUS_VALUE_MID_PREFIXGCODE));
             $model_displayname = t('timelapse_info_modelname_unknown');
             $this->load->helper('printerstoring');
             $gcode_info = PrinterStoring_getInfo("gcode", $gid);
             if (!is_null($gcode_info) && array_key_exists("name", $gcode_info)) {
                 $model_displayname = $gcode_info["name"];
             }
         } else {
             switch ($array_status[CORESTATUS_TITLE_PRINTMODEL]) {
                 case CORESTATUS_VALUE_MID_SLICE:
                     $preset_id = NULL;
                     $model_filename = array();
                     $this->load->helper('slicer');
                     if (ERROR_OK == Slicer_getModelFile(0, $model_filename, TRUE)) {
                         foreach ($model_filename as $model_basename) {
                             if (strlen($model_displayname)) {
                                 $model_displayname .= ' + ' . $model_basename;
                             } else {
                                 $model_displayname = $model_basename;
                             }
                         }
                     } else {
                         $model_displayname = t('timelapse_info_modelname_slice');
                     }
                     break;
                 default:
                     // treat as pre-sliced model
                     $model_data = array();
                     $model_displayname = "";
                     if (is_null($model_id)) {
                         $this->load->helper('printlist');
                         $model_id = $array_status[CORESTATUS_TITLE_PRINTMODEL];
                     }
                     if (ERROR_OK == ModelList__getDetailAsArray($model_id, $model_data, TRUE)) {
                         $model_displayname = $model_data[PRINTLIST_TITLE_NAME];
                     }
                     break;
             }
         }
     }
     if ($this->input->server('REQUEST_METHOD') == 'POST') {
         $this->load->library("session");
         $title = isset($_POST['yt_title']) ? $_POST['yt_title'] : t('yt_title') . $model_displayname;
         $description = isset($_POST['yt_description']) ? $_POST['yt_description'] : t('yt_desc');
         // 			$tags = explode(',', $_POST['yt_tags'] ? $_POST['yt_tags'] : t('yt_tags'));
         $tags = explode(',', t('yt_tags'));
         $tags = array_map('trim', $tags);
         $video_infos = array('yt_title' => $title, 'yt_tags' => $tags, 'yt_desc' => $description, 'yt_privacy' => $_POST["yt_privacy"]);
         $this->session->set_userdata($video_infos);
         $this->output->set_header("Location: /share/connect_google");
         return;
     }
     $data = array('yt_title' => t('yt_title') . $model_displayname, 'yt_desc' => t('yt_desc'), 'yt_privacy_public' => t('yt_privacy_public'), 'yt_privacy_private' => t('yt_privacy_private'), 'yt_privacy_unlisted' => t('yt_privacy_unlisted'), 'upload_to_yt' => t('upload_to_yt'), 'title_label' => t('title_label'), 'desc_label' => t('desc_label'), 'tags_label' => t('tags_label'), 'privacy_label' => t('privacy_label'), 'back' => t('back'));
     $this->_parseBaseTemplate(t('youtube_title'), $this->parser->parse('share/youtube_form', $data, TRUE));
     return;
 }
Ejemplo n.º 4
0
 public function __construct()
 {
     global $CFG;
     parent::__construct();
     // 		$this->load->helper(array('corestatus', 'url'));
     $this->load->helper(array('corestatus', 'printerlog'));
     // set proper error handler
     set_error_handler(array($this, 'errorToSSO'));
     // add header to disable cache (IE need these headers)
     $this->output->set_header('Pragma: no-cache');
     $this->output->set_header('Cache-Control: no-cache');
     // initialisation status files
     if (!CoreStatus_initialFile()) {
         $this->load->helper('printerlog');
         PrinterLog_logError('status files initialisation error when MY_Controller started', __FILE__, __LINE__);
         // let request failed
         $this->_exitWithError500('file initialisation error');
     }
     // check tromboning autorisation
     if (CoreStatus_checkTromboning(FALSE)) {
         $this->load->helper(array('printerlog', 'errorcode'));
         PrinterLog_logMessage('detected and refused tromboning connection', __FILE__, __LINE__);
         // let request failed
         $this->_exitWithError500(ERROR_REMOTE_REFUSE . ' ' . MyERRMSG(ERROR_REMOTE_REFUSE), ERROR_REMOTE_REFUSE);
     }
     // Workflow management
     if (CoreStatus_checkCallREST()) {
         // we place the control for REST web service in his own class
         // because there are the special error codes for REST web service
         // and we do not need them in normal condition
         return;
     } else {
         $status_current = '';
         $url_redirect = '';
         $array_status = array();
         // stats info (do not stats rest, app can initialize cookies in each request)
         $this->load->library('session');
         if (FALSE === $this->input->cookie('stats_browserLog')) {
             $this->input->set_cookie('stats_browserLog', 'ok', 2592000);
             // 30 days for browser stats
             PrinterLog_statsWebAgent();
         }
         // check initialization issue
         if (CoreStatus_checkInInitialization()) {
             if (CoreStatus_checkCallInitialization($url_redirect)) {
                 return;
                 // we are calling the right page
             }
         } else {
             if (CoreStatus_checkCallInitialization()) {
                 $url_redirect = '/';
             } else {
                 if (CoreStatus_checkInUSB()) {
                     if (CoreStatus_checkCallUSB($url_redirect)) {
                         return;
                         // we are calling the right page
                     }
                 } else {
                     if (CoreStatus_checkCallUSB()) {
                         $url_redirect = '/';
                     } else {
                         if (CoreStatus_checkCallDebug()) {
                             // we always let these interfaces go for debug
                             return;
                         } else {
                             if (CoreStatus_checkInConnection()) {
                                 if (CoreStatus_checkCallNoBlockPageInConnection()) {
                                     return;
                                     // we are calling set hostname, activation or account page
                                 }
                                 if (CoreStatus_checkCallConnection($url_redirect)) {
                                     return;
                                     // we are calling the right page
                                 }
                             } else {
                                 if (CoreStatus_checkCallConnection()) {
                                     $url_redirect = '/';
                                 } else {
                                     if (!CoreStatus_checkInIdle($status_current, $array_status)) {
                                         switch ($status_current) {
                                             case CORESTATUS_VALUE_RECOVERY:
                                                 //TODO finish and test me
                                                 if (CoreStatus_checkCallRecovery($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_PRINT:
                                                 if (CoreStatus_checkCallPrinting($array_status, $url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_CANCEL:
                                                 if (CoreStatus_checkCallCanceling($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_LOAD_FILA_L:
                                             case CORESTATUS_VALUE_LOAD_FILA_R:
                                                 if (CoreStatus_checkCallloading($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 // 						return; // we do not block users when charging filament
                                                 break;
                                             case CORESTATUS_VALUE_UNLOAD_FILA_L:
                                             case CORESTATUS_VALUE_UNLOAD_FILA_R:
                                                 //FIXME finish here to block users
                                                 if (CoreStatus_checkCallUnloading($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_SLICE:
                                                 if (CoreStatus_checkCallSlicing($url_redirect)) {
                                                     return;
                                                 }
                                                 break;
                                             default:
                                                 $url_redirect = '/';
                                                 // internal error, never reach here normally
                                                 break;
                                         }
                                     } else {
                                         if (CoreStatus_checkCallPrintingAjax() || CoreStatus_checkCallCancelingAjax()) {
                                             // let ajax request failed when we finishing printing / canceling
                                             $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
                                             header($protocol . ' 403');
                                             header('Content-type: text/plain; charset=UTF-8');
                                             echo 'Not in printing / canceling';
                                             exit;
                                         } else {
                                             if (CoreStatus_checkCallPrinting() || CoreStatus_checkCallCanceling()) {
                                                 $url_redirect = '/';
                                             } else {
                                                 if (CoreStatus_checkInPrinted()) {
                                                     if (CoreStatus_checkCallEndPrinting($url_redirect) || CoreStatus_checkCallEndPrintingPlus()) {
                                                         return;
                                                     }
                                                 } else {
                                                     if (CoreStatus_checkCallEndPrinting()) {
                                                         $url_redirect = '/';
                                                         // redirect to homepage when we have no timelapse
                                                     }
                                                 }
                                             }
                                         }
                                         if ($url_redirect) {
                                             header('Location: ' . $url_redirect);
                                             exit;
                                         }
                                         return;
                                         // continue to generate the current page
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // log error if we have no redirect url when reaching here
         if (is_null($url_redirect)) {
             $this->load->helper('printerlog');
             PrinterLog_logError('no redirect place when MY_Controller finished', __FILE__, __LINE__);
         }
         header('Location: ' . $url_redirect);
         exit;
     }
 }
Ejemplo n.º 5
0
function CoreStatus_setInIdle($last_error = FALSE, $error_message = FALSE)
{
    $status_previous = '';
    $array_previous = array();
    $array_status = array(CORESTATUS_TITLE_STARTTIME => NULL);
    $ret_val = CoreStatus_checkInIdle($status_previous, $array_previous);
    if ($ret_val == TRUE) {
        return TRUE;
        // we are already in idle
    } else {
        if ($status_previous == CORESTATUS_VALUE_PRINT || $status_previous == CORESTATUS_VALUE_CANCEL) {
            // 		// stop camera http live streaming
            // 		$ret_val = 0;
            // 		$CI = &get_instance();
            // 		$CI->load->helper('zimapi');
            // 		$ret_val = ZimAPI_cameraOff();
            // 		if ($ret_val != TRUE) {
            // 			return FALSE;
            // 		}
            // calculate elapsed time
            $time_pass = 0;
            $CI =& get_instance();
            $CI->load->helper('printerstate');
            //TODO think if it's necessary to pass this filepath out of this heavy helper (printerstate)
            $time_pass = file_exists(PRINTERSTATE_FILE_PRINTLOG) && array_key_exists(CORESTATUS_TITLE_STARTTIME, $array_previous) ? filemtime(PRINTERSTATE_FILE_PRINTLOG) - $array_previous[CORESTATUS_TITLE_STARTTIME] : time() - $array_previous[CORESTATUS_TITLE_STARTTIME];
            $array_status[CORESTATUS_TITLE_ELAPSED_TIME] = $time_pass;
            CoreStatus_setInPause(FALSE);
            // not necessary in any case, just a safty
            // comment initialization of model id to save model info
            // 		$array_status[CORESTATUS_TITLE_PRINTMODEL] = NULL;
        }
    }
    // 	else if ($status_previous == CORESTATUS_VALUE_UNLOAD_FILA_L
    // 			|| $status_previous == CORESTATUS_VALUE_UNLOAD_FILA_R) {
    // 		$CI = &get_instance();
    // 		$CI->load->helper('printerstate');
    // 		$ret_val = PrinterState_afterUnloadFilament();
    // 		if ($ret_val != ERROR_OK) {
    // 			return FALSE;
    // 		}
    // 	}
    if ($last_error !== FALSE) {
        // add last_error for slicing
        //TODO perhaps also check $status_previous == CORESTATUS_VALUE_SLICE ?
        $array_status[CORESTATUS_TITLE_LASTERROR] = $last_error;
        $array_status[CORESTATUS_TITLE_MESSAGE] = $error_message ? $error_message : NULL;
    }
    return CoreStatus__setInStatus(CORESTATUS_VALUE_IDLE, $array_status);
}
Ejemplo n.º 6
0
 public function recovery_ajax()
 {
     //TODO finish me for recovery
     $template_data = array();
     $ret_val = 0;
     $status_current = NULL;
     $data_status = array();
     $this->load->helper('corestatus');
     $this->load->library('parser');
     $this->lang->load('printdetail', $this->config->item('language'));
     $template_data = array('wait_info' => t('wait_hint_recovery'));
     $ret_val = CoreStatus_checkInIdle($status_current, $data_status);
     if ($ret_val == TRUE) {
         // log recovery finish
         $this->load->helper('printerlog');
         PrinterLog_logMessage('recovery status finish', __FILE__, __LINE__);
         $this->output->set_status_header(202);
         return;
     } else {
         if ($status_current == CORESTATUS_VALUE_RECOVERY) {
             if ($data_status[CORESTATUS_TITLE_SUBSTATUS] == CORESTATUS_VALUE_PRINT) {
                 $template_data['wait_info'] = t('wait_hint_recovery_printing');
             } else {
                 $template_data['wait_info'] = t('wait_hint_recovery_unknown');
                 $this->load->helper('printerlog');
                 PrinterLog_logError('unknown substatus value in recovery ' . $data_status[CORESTATUS_TITLE_SUBSTATUS], __FILE__, __LINE__);
             }
         } else {
             $this->output->set_status_header(403);
             $this->load->helper('printerlog');
             PrinterLog_logError('call recovery status check when not in recovery', __FILE__, __LINE__);
             return;
         }
     }
     // parse the ajax part
     $this->parser->parse('printdetail/cancel_ajax', $template_data);
     // we can use the same view for recovery
     $this->output->set_content_type('text/plain; charset=UTF-8');
     return;
 }
Ejemplo n.º 7
0
 function slice_status_ajax()
 {
     $ret_val = 0;
     $cr = 0;
     $array_data = array();
     $status_current = NULL;
     $display = NULL;
     $this->load->helper(array('printerstate', 'slicer'));
     $this->load->library('parser');
     $ret_val = CoreStatus_checkInIdle($status_current);
     if ($ret_val == TRUE) {
         $cr = 403;
         $this->output->set_status_header($cr);
         return;
     }
     $ret_val = PrinterState_checkBusyStatus($status_current, $array_data);
     if ($ret_val == TRUE && $status_current == CORESTATUS_VALUE_IDLE) {
         if (isset($array_data[PRINTERSTATE_TITLE_LASTERROR])) {
             $cr = $array_data[PRINTERSTATE_TITLE_LASTERROR];
         } else {
             $cr = ERROR_OK;
         }
     } else {
         if ($ret_val == FALSE && $status_current == CORESTATUS_VALUE_SLICE) {
             if (!isset($array_data[PRINTERSTATE_TITLE_PERCENT])) {
                 $this->load->helper('printerlog');
                 PrinterLog_logError('can not find percentage in slicing', __FILE__, __LINE__);
                 $cr = ERROR_INTERNAL;
             } else {
                 $this->lang->load('sliceupload/slice_status_ajax', $this->config->item('language'));
                 $array_display = array('percent' => $array_data[PRINTERSTATE_TITLE_PERCENT], 'message' => isset($array_data[PRINTERSTATE_TITLE_DETAILMSG]) ? t($array_data[PRINTERSTATE_TITLE_DETAILMSG]) : NULL);
                 $cr = ERROR_OK;
                 $this->output->set_status_header($cr);
                 $this->output->set_content_type('jsonu');
                 $this->parser->parse('plaintxt', array('display' => json_encode($array_display)));
                 return;
             }
         } else {
             $this->load->helper('printerlog');
             PrinterLog_logError('unknown status in slicing', __FILE__, __LINE__);
             $cr = ERROR_INTERNAL;
             CoreStatus_setInIdle();
         }
     }
     if (!in_array($cr, array(ERROR_OK, ERROR_INTERNAL, ERROR_LOW_RIGT_FILA, ERROR_LOW_LEFT_FILA, ERROR_MISS_RIGT_FILA, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_CART, ERROR_MISS_LEFT_CART))) {
         $this->load->helper('printerlog');
         PrinterLog_logError('unknown return after slicing: ' . $cr, __FILE__, __LINE__);
         $cr = ERROR_INTERNAL;
     }
     if ($cr == ERROR_INTERNAL) {
         $this->output->set_status_header($cr);
     } else {
         $this->output->set_status_header(202);
     }
     $display = $cr . " " . t(MyERRMSG($cr));
     $this->output->set_content_type('txt_u');
     $this->parser->parse('plaintxt', array('display' => $display));
     //optional
     return;
 }
Ejemplo n.º 8
0
function Printer_checkPauseStatus()
{
    $status_current = NULL;
    $temper_status = array();
    $CI =& get_instance();
    $CI->load->helper('corestatus');
    // check status if we are not in canceling
    CoreStatus_checkInIdle($status_current);
    if ($status_current == CORESTATUS_VALUE_PRINT && CoreStatus_checkInPause()) {
        return TRUE;
    }
    return FALSE;
}
Ejemplo n.º 9
0
function PrinterState_checkStatusAsArray($extra_info = TRUE)
{
    $command = '';
    $output = array();
    $ret_val = 0;
    $data_json = array();
    $temp_data[PRINTERSTATE_TITLE_LASTERROR] = array();
    $time_start = NULL;
    $status_current = '';
    // if we need duration, the function that get duration by id is necessary
    // and we must stock print list id somewhere in json file
    $CI =& get_instance();
    $CI->load->helper('corestatus');
    if (CoreStatus_checkInUSB()) {
        $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_USB;
        return $data_json;
    } else {
        if (CoreStatus_checkInConnection()) {
            $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_WAIT_CONNECT;
            return $data_json;
        }
    }
    $ret_val = CoreStatus_checkInIdle($status_current, $status_json);
    if ($ret_val == TRUE) {
        $data_json[PRINTERSTATE_TITLE_STATUS] = CORESTATUS_VALUE_IDLE;
        //TODO think about if we need to display last error as 200 (error_ok) or not
        if (array_key_exists(CORESTATUS_TITLE_LASTERROR, $status_json) && !is_null($status_json[CORESTATUS_TITLE_LASTERROR]) && $status_json[CORESTATUS_TITLE_LASTERROR] != ERROR_OK) {
            // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_LASTERROR] = $status_json[CORESTATUS_TITLE_LASTERROR];
            // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_DETAILMSG] = $status_json[CORESTATUS_TITLE_MESSAGE];
            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_SLICE_ERR] = $status_json[CORESTATUS_TITLE_LASTERROR] . ' ' . $status_json[CORESTATUS_TITLE_MESSAGE];
        }
    } else {
        if ($ret_val == FALSE) {
            $temp_data = array();
            $status_old = $status_current;
            PrinterState_checkBusyStatus($status_current, $temp_data);
            if (in_array($status_current, array(CORESTATUS_VALUE_SLICE, CORESTATUS_VALUE_PRINT))) {
                $data_json[PRINTERSTATE_TITLE_PERCENT] = $temp_data[PRINTERSTATE_TITLE_PERCENT];
            }
            $data_json[PRINTERSTATE_TITLE_STATUS] = $status_current;
            // return error code in the first time when we have error from slicing=>idle
            if ($status_old == CORESTATUS_VALUE_SLICE && $status_current == CORESTATUS_VALUE_IDLE && array_key_exists(PRINTERSTATE_TITLE_LASTERROR, $temp_data)) {
                // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_LASTERROR] = $temp_data[PRINTERSTATE_TITLE_LASTERROR];
                // 			$data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_DETAILMSG] = $temp_data[PRINTERSTATE_TITLE_DETAILMSG];
                $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_SLICE_ERR] = $temp_data[PRINTERSTATE_TITLE_LASTERROR] . ' ' . $temp_data[PRINTERSTATE_TITLE_DETAILMSG];
            } else {
                if ($status_current == CORESTATUS_VALUE_PRINT) {
                    $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_PRINT;
                    $array_status = array();
                    // add temperature
                    if ($extra_info == TRUE && $data_json[PRINTERSTATE_TITLE_PERCENT] != 100) {
                        $data_temperature = PrinterState_getExtruderTemperaturesAsArray();
                        if (!is_array($data_temperature)) {
                            // log internal error
                            $CI->load->helper('printerlog');
                            PrinterLog_logError('API error when getting temperatures in printing', __FILE__, __LINE__);
                        } else {
                            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_L] = array_key_exists(PRINTERSTATE_LEFT_EXTRUD, $data_temperature) ? $data_temperature[PRINTERSTATE_LEFT_EXTRUD] : 0;
                            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_R] = array_key_exists(PRINTERSTATE_RIGHT_EXTRUD, $data_temperature) ? $data_temperature[PRINTERSTATE_RIGHT_EXTRUD] : 0;
                            $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_TEMP_B] = array_key_exists(PRINTERSTATE_HEAT_BED, $data_temperature) ? $data_temperature[PRINTERSTATE_HEAT_BED] : 0;
                        }
                    }
                    // try to calculate time remained when percentage is passed offset
                    $ret_val = CoreStatus_getStatusArray($array_status);
                    if ($ret_val == TRUE && isset($array_status[CORESTATUS_TITLE_STARTTIME]) && isset($array_status[CORESTATUS_TITLE_ESTIMATE_T])) {
                        $time_pass = time() - $array_status[CORESTATUS_TITLE_STARTTIME];
                        $data_json[PRINTERSTATE_TITLE_PASSTIME] = $time_pass;
                        if (isset($data_json[PRINTERSTATE_TITLE_PERCENT]) && ($time_pass >= PRINTERSTATE_VALUE_OFST_TO_CAL_TIME || $data_json[PRINTERSTATE_TITLE_PERCENT] >= PRINTERSTATE_VALUE_OFST_TO_CAL_PCT)) {
                            // rest time = total time - passed time
                            // total time = estimate time (by filament) * (1 - percentage ^ 0.5) + estimate time (by time) * percentage ^ 0.5
                            // estimate time (by time) = passed time / percentage
                            // 					$percentage_finish = $data_json[PRINTERSTATE_TITLE_PERCENT] / 100;
                            $calculate_factor = sqrt($data_json[PRINTERSTATE_TITLE_PERCENT] / 100);
                            $time_estimation = $array_status[CORESTATUS_TITLE_ESTIMATE_T];
                            $data_json[PRINTERSTATE_TITLE_DURATION] = (int) ($time_estimation * (1 - $calculate_factor) + $time_pass * (1 / $calculate_factor - 1));
                        }
                    }
                    // check operation
                    if (file_exists(PRINTERSTATE_FILE_PRINT_HEAT)) {
                        $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_HEAT;
                    } else {
                        if ($data_json[PRINTERSTATE_TITLE_PERCENT] == 100) {
                            $print_operation = PRINTERSTATE_VALUE_PRINT_OPERATION_END;
                        }
                    }
                    $data_json[PRINTERSTATE_TITLE_EXTEND_PRM][PRINTERSTATE_TITLE_EXT_OPER] = $print_operation;
                }
            }
        }
    }
    if ($extra_info == TRUE && $status_current == CORESTATUS_VALUE_IDLE) {
        // check if we need to change idle into sliced or not
        PrinterState_checkSlicedCondition($data_json);
        //TODO add timelapse checking
        PrinterState_checkTimelapseCondition($data_json);
    }
    return $data_json;
}