function __construct() { parent::__construct(); $this->load->helper(array('form', 'url', 'json', 'errorcode', 'corestatus')); $status_current = ''; if (CoreStatus_checkInInitialization() || CoreStatus_checkInConnection() || CoreStatus_checkInUSB()) { // let no block REST web service go for setting network if (CoreStatus_checkCallNoBlockRESTInConnection()) { return; } // we haven't finished initialization or connection yet $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER); } else { if (!CoreStatus_checkInIdle($status_current)) { // check if the status is changed $ret_val = 0; $this->load->helper('printerstate'); switch ($status_current) { case CORESTATUS_VALUE_SLICE: if (CoreStatus_checkCallNoBlockRESTInSlice()) { // do not block some special REST for action in slicing return; } $ret_val = PrinterState_checkBusyStatus($status_current); if ($ret_val == FALSE) { // still in slicing break; } else { if ($status_current == CORESTATUS_VALUE_IDLE) { // encounted some errors break; } else { // CORESTATUS_VALUE_PRINT $this->load->helper('printerlog'); PrinterLog_logMessage('call rest when we are in slicing, but finished really', __FILE__, __LINE__); } } // we treat canceling as printing // we treat canceling as printing case CORESTATUS_VALUE_PRINT: // do not block some special REST for action in printing if (CoreStatus_checkCallNoBlockRESTInPrint()) { return; } case CORESTATUS_VALUE_CANCEL: //TODO test here for canceling $ret_val = PrinterState_checkInPrint(); if ($ret_val == FALSE) { $ret_val = CoreStatus_setInIdle(); if ($ret_val == TRUE) { $this->load->helper('printerlog'); PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__); return; // continue to generate if we are now in idle } $this->load->helper('printerlog'); PrinterLog_logError('can not set status in idle', __FILE__, __LINE__); } break; default: $ret_val = PrinterState_checkBusyStatus($status_current); if ($ret_val == TRUE) { $this->load->helper('printerlog'); PrinterLog_logDebug('set idle when calling REST', __FILE__, __LINE__); return; // status has changed to idle } break; } // do not block some special REST if (CoreStatus_checkCallNoBlockREST()) { return; } // return that printer is busy $this->_exitWithError500(ERROR_BUSY_PRINTER . ' ' . t(MyERRMSG(ERROR_BUSY_PRINTER)), ERROR_BUSY_PRINTER); } } }
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; }
function Slicer_sliceHalt($force_remote = FALSE) { $cr = 0; $ret_val = 0; $action_remote = FALSE; $url_remote = NULL; $CI =& get_instance(); $CI->load->helper('printerlog'); if (file_exists(SLICER_FILE_REMOTE_STATUS) || ($force_remote = TRUE)) { // remote slicing $output = array(); $json_status = array(); $command = $CI->config->item('siteutil') . SLICER_CMD_PRM_REMOTE_STOP; $CI->load->helper('json'); $json_status = json_read(SLICER_FILE_REMOTE_STATUS, TRUE); if (!isset($json_status['error']) && isset($json_status['json'][SLICER_TITLE_REMOTE_URL])) { $url_remote = $json_status['json'][SLICER_TITLE_REMOTE_URL]; } else { $url_remote = PRINTERLOG_STATS_VALUE_REMOTE; } if (!DectectOS_checkWindows()) { $command = 'sudo ' . $command; } $action_remote = TRUE; exec($command, $output, $ret_val); if ($ret_val != ERROR_NORMAL_RC_OK) { $CI->load->helper('remote slicing cancel utils command error', __FILE__, __LINE__); $ret_val = SLICER_RESPONSE_ERROR; } else { $ret_val = SLICER_RESPONSE_OK; } } else { // local slicing $ret_val = Slicer__requestSlicer(SLICER_URL_SLICE_HALT); $url_remote = PRINTERLOG_STATS_VALUE_LOCAL; } if ($ret_val == SLICER_RESPONSE_OK) { $CI->load->helper('corestatus'); CoreStatus_setInIdle(); // stats info PrinterLog_statsSlice(PRINTERLOG_STATS_ACTION_CANCEL, array(PRINTERLOG_STATS_SLICE_SERVER => $url_remote)); $cr = ERROR_OK; if ($action_remote == FALSE) { Slicer_restart(); //FIXME remove me as soon as possible } } else { $cr = ERROR_NO_SLICING; } return $cr; }
function CoreStatus_initialFile() { $CI =& get_instance(); $state_file = NULL; $sdcard = FALSE; $check_onboot = FALSE; $nb_extruder = 0; $heat_bed = 0; // for the first time, check if we can use all files in sdcard instead of config partition // then save the choice in a status file in the temp to remember it if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_SD_ON)) { $sdcard = TRUE; } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_SD_OFF)) { $sdcard = FALSE; } else { if (is_writable($CI->config->item('sdcard'))) { $cr = 0; $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('sdcard') . '.phptest.tmp'; $output = array(); $CI->load->helper('errorcode'); exec($command, $output, $cr); if ($cr == ERROR_NORMAL_RC_OK) { $sdcard = TRUE; $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('temp') . CORESTATUS_FILE_SD_ON; } else { $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('temp') . CORESTATUS_FILE_SD_OFF; } } else { $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('temp') . CORESTATUS_FILE_SD_OFF; } exec($command); $check_onboot = TRUE; } } $array_change = array('conf' => CORESTATUS_SUFFIX_CONF, 'presetlist' => CORESTATUS_SUFFIX_PRESET); foreach ($array_change as $key => $value) { $folder_path = NULL; if ($sdcard == TRUE) { $folder_path = $CI->config->item('sdcard') . $value; } else { $folder_path = $CI->config->item('nandconf') . $value; } // check folder exists or not, if not, create it if (!file_exists($folder_path)) { mkdir($folder_path); } // change config setting to right path $CI->config->set_item($key, $folder_path); } $CI->config->set_item('use_sdcard', $sdcard); // initialization of preset $CI->load->helper('zimapi'); if (!ZimAPI_initialFile()) { return FALSE; } // initialization of library if ($sdcard) { $CI->load->helper('printerstoring'); if (!PrinterStoring_initialFile()) { return FALSE; } } $state_file = $CI->config->item('conf') . CORESTATUS_FILENAME_WORK; if (!file_exists($state_file) || 0 == filesize($state_file)) { // prepare data array $CI->load->helper('printerstate'); $data_json = array(CORESTATUS_TITLE_VERSION => '1.0', CORESTATUS_TITLE_STATUS => CORESTATUS_VALUE_IDLE, CORESTATUS_TITLE_LASTERROR => NULL, CORESTATUS_TITLE_MESSAGE => NULL, CORESTATUS_TITLE_SUBSTATUS => NULL, CORESTATUS_TITLE_PRINTMODEL => CORESTATUS_VALUE_MID_CALIBRATION, CORESTATUS_TITLE_ELAPSED_TIME => 0, CORESTATUS_TITLE_P_TEMPER_L => 0, CORESTATUS_TITLE_P_TEMPER_R => 0, CORESTATUS_TITLE_P_TEMPER_B => 0, CORESTATUS_TITLE_P_EXCH_BUS => 0, CORESTATUS_TITLE_FILA_MAT => PRINTERSTATE_DESP_MATERIAL_PLA, CORESTATUS_TITLE_GUID => random_string('numeric', CORESTATUS_VALUE_RAND_STRING_LENGTH), CORESTATUS_TITLE_ESTIMATE_T => 0); // write json file $fp = fopen($state_file, 'w'); if ($fp) { fwrite($fp, json_encode($data_json)); fclose($fp); chmod($state_file, 0777); } else { return FALSE; } } else { if ($check_onboot == TRUE) { // change loading and unloading status into idle on the first boot checking $status_check = NULL; CoreStatus_checkInIdle($status_check); if (in_array($status_check, array(CORESTATUS_VALUE_LOAD_FILA_L, CORESTATUS_VALUE_UNLOAD_FILA_L, CORESTATUS_VALUE_LOAD_FILA_R, CORESTATUS_VALUE_UNLOAD_FILA_R))) { CoreStatus_setInIdle(); } } } // debug level if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_DEBUG)) { $CI->config->set_item('log_level', 3); } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_MESSAGE)) { $CI->config->set_item('log_level', 2); } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_ERROR)) { $CI->config->set_item('log_level', 1); } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_NONE)) { $CI->config->set_item('log_level', 0); } } } } // extruder number $state_file = $CI->config->item('temp') . CORESTATUS_FILE_NB_EXTRUDER; if (file_exists($state_file)) { $nb_extruder = (int) @file_get_contents($state_file); } if ($nb_extruder == 0) { // check again if status file indicate 0 extruder $CI->load->helper('printerstate'); $nb_extruder = PrinterState_getNbExtruder(); // write status file $fp = fopen($state_file, 'w'); if ($fp) { fwrite($fp, $nb_extruder); fclose($fp); } else { return FALSE; } } if ($nb_extruder != 0) { // set printer in default mode (2) if error (0 extruder detected) $CI->config->set_item('nb_extruder', $nb_extruder); } // heat bed $state_file = $CI->config->item('temp') . CORESTATUS_FILE_HEAT_BED; if (file_exists($state_file)) { $heat_bed = (int) @file_get_contents($state_file); if ($heat_bed) { $CI->config->set_item('heat_bed', TRUE); } } else { $CI->load->helper('printerstate'); $ret_val = PrinterState_getTemperature($heat_bed, 'b'); if ($ret_val == ERROR_OK) { $tmp_bool = $heat_bed != PRINTERSTATE_TEMPER_NO_HEAT_BED; $fp = fopen($state_file, 'w'); if ($fp) { fwrite($fp, $tmp_bool ? 1 : 0); fclose($fp); $CI->config->set_item('heat_bed', $tmp_bool); } else { return FALSE; } } } return TRUE; }
public function cancel_ajax() { $template_data = array(); $ret_val = 0; // $data_status = array(); // $this->load->helper(array('printer', 'timedisplay')); $this->load->helper('printer'); $this->load->library('parser'); $this->lang->load('printdetail', $this->config->item('language')); // $this->lang->load('timedisplay', $this->config->item('language')); // $ret_val = Printer_checkCancelStatus($data_status); $ret_val = Printer_checkCancelStatus(); if ($ret_val == FALSE) { $this->load->helper('corestatus'); $ret_val = CoreStatus_setInIdle(); if ($ret_val == FALSE) { // log internal error $this->load->helper('printerlog'); PrinterLog_logError('can not set idle after canceling', __FILE__, __LINE__); } if ($this->config->item('simulator')) { // just set temperature for simulation $this->load->helper('printerstate'); PrinterState_setExtruder('r'); PrinterState_setTemperature(20); PrinterState_setExtruder('l'); PrinterState_setTemperature(20); PrinterState_setExtruder('r'); } $this->output->set_status_header(202); return; } // // treat time remaining for display // if (isset($data_status['print_remain'])) { // $time_remain = TimeDisplay__convertsecond( // $data_status['print_remain'], t('Time remaining: '), t('under calculating')); // } // else { // $time_remain = t('Time remaining: ') . t('unknown'); // } // parse the ajax part $template_data = array('wait_info' => t('wait_hint_cancel')); $this->parser->parse('printdetail/cancel_ajax', $template_data); $this->output->set_content_type('text/plain; charset=UTF-8'); return; }
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; }
function PrinterState_checkBusyStatus(&$status_current, &$array_data = array()) { $ret_val = 0; $time_wait = NULL; $time_max = NULL; // $temp_status = NULL; $temp_array = array(); $CI =& get_instance(); $CI->load->helper('corestatus'); switch ($status_current) { case CORESTATUS_VALUE_WAIT_CONNECT: $ret_val = CoreStatus_checkInConnection(); if ($ret_val == FALSE) { CoreStatus_setInIdle(); $status_current = CORESTATUS_VALUE_IDLE; return TRUE; } break; case CORESTATUS_VALUE_CANCEL: // jump out if it's a simulator or when cancelling is finished if ($CI->config->item('simulator') || !file_exists(PRINTERSTATE_FILE_STOPFILE)) { $stats_info = PrinterState_prepareStatsPrintLabel(); PrinterLog_statsPrint(PRINTERLOG_STATS_ACTION_CANCEL, $stats_info); CoreStatus_setInIdle(); $status_current = CORESTATUS_VALUE_IDLE; return TRUE; } break; case CORESTATUS_VALUE_SLICE: // get percentage and check finished or not $progress = 0; $message = NULL; $array_slicer = array(); $CI->load->helper('slicer'); $ret_val = Slicer_checkSlice($progress, $message, $array_slicer); if ($ret_val != ERROR_OK) { $error_message = NULL; $url_remote = NULL; $stats_info = array(); // handle error for slicing $CI->load->helper('printerlog'); $url_remote = PRINTERLOG_STATS_VALUE_LOCAL; $array_data[PRINTERSTATE_TITLE_LASTERROR] = $ret_val; $status_current = CORESTATUS_VALUE_IDLE; switch ($ret_val) { //TODO treat the error with api and ui case ERROR_NO_SLICING: $error_message = 'not in slicing'; break; case ERROR_WRONG_PRM: $error_message = 'slicer error'; // perhaps because of parameter break; case ERROR_UNKNOWN_MODEL: $error_message = 'slicer export error'; // perhaps because of model break; case ERROR_REMOTE_SLICE: $error_message = 'remote slicer error'; $url_remote = $message; break; default: $error_message = 'slicer internal error'; // internal system error PrinterLog_logDebug('return: ' . $ret_val . ', progress: ' . $progress); break; } PrinterLog_logMessage($error_message, __FILE__, __LINE__); CoreStatus_setInIdle($ret_val, $error_message); $array_data[PRINTERSTATE_TITLE_DETAILMSG] = $error_message; // stats info $stats_info = PrinterState_prepareStatsSliceLabel(); $stats_info[PRINTERLOG_STATS_SLICE_ERROR] = $error_message; $stats_info[PRINTERLOG_STATS_SLICE_SERVER] = $url_remote; PrinterLog_statsSlice(PRINTERLOG_STATS_ACTION_ERROR, $stats_info); return TRUE; } elseif ($progress == 100) { $url_remote = NULL; $stats_info = array(); // set temp json file for every service $ret_val = PrinterState__setSlicedJson($array_slicer); $status_current = CORESTATUS_VALUE_IDLE; if ($ret_val != ERROR_OK) { $array_data[PRINTERSTATE_TITLE_LASTERROR] = $ret_val; CoreStatus_setInIdle($ret_val); } else { CoreStatus_setInIdle(); } // stats info $CI->load->helper('printerlog'); $stats_info = PrinterState_prepareStatsSliceLabel(TRUE); //detect remote slicing if (file_exists(SLICER_FILE_REMOTE_REQUEST_URL)) { $url_remote = trim(@file_get_contents(SLICER_FILE_REMOTE_REQUEST_URL)); if (strlen($url_remote) == 0) { $url_remote = PRINTERLOG_STATS_VALUE_REMOTE; } } else { $url_remote = PRINTERLOG_STATS_VALUE_LOCAL; } $stats_info[PRINTERLOG_STATS_SLICE_SERVER] = $url_remote; PrinterLog_statsSlice(PRINTERLOG_STATS_ACTION_END, $stats_info); return TRUE; } else { // still in slicing, so get percentage (estimated time is useless for now, slicer exports percentage badly) $array_data[PRINTERSTATE_TITLE_PERCENT] = $progress; $array_data[PRINTERSTATE_TITLE_DETAILMSG] = $message; } break; case CORESTATUS_VALUE_LOAD_FILA_L: case CORESTATUS_VALUE_LOAD_FILA_R: // CoreStatus_checkInIdle($temp_status, $temp_array); CoreStatus_getStatusArray($temp_array); if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $temp_array) && $temp_array[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) { $time_wait = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_LOAD_PVA; $time_max = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_LOAD_PVA; } else { $time_wait = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_LOAD; $time_max = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_LOAD; } case CORESTATUS_VALUE_UNLOAD_FILA_L: case CORESTATUS_VALUE_UNLOAD_FILA_R: $abb_filament = 'r'; $status_fin_filament = FALSE; if (in_array($status_current, array(CORESTATUS_VALUE_LOAD_FILA_L, CORESTATUS_VALUE_UNLOAD_FILA_L))) { $abb_filament = 'l'; $status_fin_filament = TRUE; } if (is_null($time_wait) || is_null($time_max)) { if (file_exists(PRINTERSTATE_FILE_UNLOAD_HEAT)) { $time_start = @file_get_contents(PRINTERSTATE_FILE_UNLOAD_HEAT); if (is_null($time_start)) { PrinterLog_logError('check unload heat status file error', __FILE__, __LINE__); break; } else { if (time() - $time_start <= PRINTERSTATE_VALUE_TIMEOUT_UNLOAD_HEAT) { // block the status if in timeout, and refresh the start time for the following state CoreStatus_setInUnloading($abb_filament); break; } else { // always in heating when we passed timeout, we unlock the mobile site PrinterLog_logError('always in heating process when we unload filament', __FILE__, __LINE__); @unlink(PRINTERSTATE_FILE_UNLOAD_HEAT); $ret_val = CoreStatus_setInIdle(); if ($ret_val == TRUE) { $status_current = CORESTATUS_VALUE_IDLE; return TRUE; } $CI->load->helper('printerlog'); PrinterLog_logError('can not set status into idle', __FILE__, __LINE__); break; } } } // CoreStatus_checkInIdle($temp_status, $temp_array); CoreStatus_getStatusArray($temp_array); if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $temp_array) && $temp_array[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) { $time_wait = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_UNLOAD_PVA; $time_max = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_UNLOAD_PVA; } else { $time_wait = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_UNLOAD; $time_max = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_UNLOAD; } } // wait the time for arduino before checking filament when loading / unloading filament if (CoreStatus_checkInWaitTime($time_wait)) { break; } // generate parameters by different status $ret_val = PrinterState_getFilamentStatus($abb_filament); if ($ret_val == $status_fin_filament || !CoreStatus_checkInWaitTime($time_max)) { if ($ret_val != $status_fin_filament) { $CI->load->helper('printerlog'); PrinterLog_logError('we pass timeout when we are in changing catridge, status: ' . $status_current, __FILE__, __LINE__); } $ret_val = CoreStatus_setInIdle(); if ($ret_val == TRUE) { $status_current = CORESTATUS_VALUE_IDLE; return TRUE; // continue to generate if we are now in idle } $CI->load->helper('printerlog'); PrinterLog_logError('can not set status into idle', __FILE__, __LINE__); } break; case CORESTATUS_VALUE_PRINT: $output = array(); $command = $CI->config->item('arcontrol_c') . PRINTERSTATE_CHECK_STATE; if (file_exists($CI->config->item('printstatus'))) { $output = @file($CI->config->item('printstatus')); if (count($output) == 0) { // case: read the percentage status file when arcontrol_cli is writing in it // so we let the percentage as 1 to continue printing $output = array('1'); $CI->load->helper('printerlog'); PrinterLog_logDebug('read percentage file when arcontrol_cli wrinting in it', __FILE__, __LINE__); } } else { $output = array('0'); } PrinterLog_logArduino($command, $output); // if (count($output)) { // // we have right return if ((int) $output[0] == 0) { $stats_info = array(); // not in printing(?), now we consider it is just idle (no slicing) $CI->load->helper('printerlog'); PrinterLog_logDebug('check in idle - checkstatusasarray', __FILE__, __LINE__); $status_current = CORESTATUS_VALUE_IDLE; if (!CoreStatus_setInIdle()) { PrinterLog_logError('cannot set in idle - checkstatusasarray', __FILE__, __LINE__); } //stats info $stats_info = PrinterState_prepareStatsPrintLabel(); PrinterLog_statsPrint(PRINTERLOG_STATS_ACTION_END, $stats_info); return TRUE; } else { $array_data[PRINTERSTATE_TITLE_PERCENT] = $output[0]; } // } // else { // $CI->load->helper('printerlog'); // PrinterLog_logError('print check status command error', __FILE__, __LINE__); // } break; default: // log internal API error $CI->load->helper('printerlog'); PrinterLog_logError('unknown status in work json', __FILE__, __LINE__); break; } return FALSE; // status has not changed }