Example #1
0
 public function changecartridge_ajax()
 {
     $template_data = array();
     $body_page = NULL;
     $ret_val = 0;
     $abb_cartridge = $this->input->post('abb_cartridge');
     $need_filament = $this->input->post('need_filament');
     $id_model = $this->input->post('mid');
     $next_phase = $this->input->post('next_phase');
     $code_miss_cartridge = $abb_cartridge == 'r' ? ERROR_MISS_RIGT_CART : ERROR_MISS_LEFT_CART;
     $code_low_filament = $abb_cartridge == 'r' ? ERROR_LOW_RIGT_FILA : ERROR_LOW_LEFT_FILA;
     $code_miss_filament = $abb_cartridge == 'r' ? ERROR_MISS_RIGT_FILA : ERROR_MISS_LEFT_FILA;
     $low_hint = FALSE;
     $change_able = TRUE;
     // treat input data
     if (!$abb_cartridge && !in_array($abb_cartridge, array('l', 'r'))) {
         if (isset($_SERVER['HTTP_REFERER'])) {
             $this->output->set_header('Location: ' . $_SERVER['HTTP_REFERER']);
         } else {
             $this->output->set_header('Location: /');
         }
         return;
     }
     if ($need_filament) {
         $need_filament = (int) $need_filament;
     } else {
         $need_filament = 0;
     }
     $this->load->helper(array('corestatus'));
     // detect status
     switch ($next_phase) {
         case PRINTERSTATE_CHANGECART_UNLOAD_F:
             // we call the page: wait unload filament, need checking status (first status page)
             $status_current = '';
             $array_status = array();
             // block any sending command to arduino when in unloading wait time
             if (CoreStatus_checkInIdle($status_current, $array_status) == FALSE) {
                 if (in_array($status_current, array(CORESTATUS_VALUE_UNLOAD_FILA_L, CORESTATUS_VALUE_UNLOAD_FILA_R))) {
                     if (!$this->_deal_with_unloading_wait_time($abb_cartridge, $array_status)) {
                         $this->_display_changecartridge_in_unload_filament($abb_cartridge);
                         break;
                     }
                 } else {
                     if (in_array($status_current, array(CORESTATUS_VALUE_LOAD_FILA_L, CORESTATUS_VALUE_LOAD_FILA_R))) {
                         $this->_display_changecartridge_in_load_filament();
                         break;
                     }
                 }
             }
             if (PrinterState_getFilamentStatus($abb_cartridge)) {
                 // have filament
                 $status_correct = $abb_cartridge == 'r' ? CORESTATUS_VALUE_UNLOAD_FILA_R : CORESTATUS_VALUE_UNLOAD_FILA_L;
                 $status_changed = $abb_cartridge == 'r' ? CORESTATUS_VALUE_LOAD_FILA_R : CORESTATUS_VALUE_LOAD_FILA_L;
                 if (CoreStatus_checkInIdle($status_current, $array_status)) {
                     // in idle
                     $ret_val = PrinterState_getTemperature($temp_data, 'e', $abb_cartridge);
                     if ($ret_val != ERROR_OK) {
                         $this->load->helper('printerlog');
                         PrinterLog_logError('can not get temperature: ' . $abb_cartridge, __FILE__, __LINE__);
                         $this->output->set_status_header(202);
                         // disable checking
                     } else {
                         $this->_display_changecartridge_wait_unload_filament($abb_cartridge, $id_model, $temp_data > PRINTERSTATE_VALUE_MAXTEMPER_BEFORE_UNLOAD);
                     }
                 } else {
                     if ($status_current == $status_correct) {
                         // in busy (normally only unloading is possible)
                         $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_UNLOAD;
                         if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $array_status) && $array_status[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) {
                             $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_UNLOAD_PVA;
                         }
                         if (!CoreStatus_checkInWaitTime($timeout_check)) {
                             //TODO test me
                             // already passed the timeout of changement
                             // change status into idle
                             $ret_val = CoreStatus_setInIdle();
                             if ($ret_val == FALSE) {
                                 $this->load->helper('printerlog');
                                 PrinterLog_logError('can not set idle after unloading filament', __FILE__, __LINE__);
                                 $this->output->set_status_header(202);
                                 // disable checking
                             }
                             $this->_display_changecartridge_error_unloading();
                             break;
                         }
                         $this->_display_changecartridge_in_unload_filament($abb_cartridge);
                     } else {
                         if ($status_current == $status_changed) {
                             // in busy (but in idle, status is changed in real)
                             $ret_val = CoreStatus_setInIdle();
                             if ($ret_val == FALSE) {
                                 $this->load->helper('printerlog');
                                 PrinterLog_logError('can not set idle after unloading filament', __FILE__, __LINE__);
                                 $this->output->set_status_header(202);
                                 // disable checking
                             }
                         } else {
                             // in other busy status
                             $this->load->helper('printerlog');
                             PrinterLog_logError('error status when changing filament', __FILE__, __LINE__);
                             $this->_display_changecartridge_error_status($status_current);
                             // 						$this->output->set_status_header(202); // disable checking
                         }
                     }
                 }
             } else {
                 // no filament
                 $status_correct = $abb_cartridge == 'r' ? CORESTATUS_VALUE_LOAD_FILA_R : CORESTATUS_VALUE_LOAD_FILA_L;
                 $status_changed = $abb_cartridge == 'r' ? CORESTATUS_VALUE_UNLOAD_FILA_R : CORESTATUS_VALUE_UNLOAD_FILA_L;
                 if (CoreStatus_checkInIdle($status_current, $array_status)) {
                     $ret_val = PrinterState_checkFilament($abb_cartridge, $need_filament);
                     if ($ret_val == $code_miss_filament) {
                         // have cartridge, enough filament
                         $this->_display_changecartridge_wait_load_filament(TRUE, $id_model, $abb_cartridge);
                     } else {
                         if ($ret_val == $code_low_filament) {
                             // have cartridge, low filament
                             $this->_display_changecartridge_remove_cartridge(TRUE);
                         } else {
                             if ($ret_val == $code_miss_cartridge) {
                                 // no cartridge
                                 // raise the platform for first loading ajax page
                                 if (ERROR_OK != PrinterState_raisePlatform()) {
                                     $this->output->set_header('Location: /');
                                     return;
                                 }
                                 $this->_display_changecartridge_insert_cartridge();
                             } else {
                                 // error status
                                 $this->load->helper('printerlog');
                                 PrinterLog_logError('error checkfilament return status when changing filament (in starting)', __FILE__, __LINE__);
                                 $this->_display_changecartridge_remove_cartridge();
                             }
                         }
                     }
                 } else {
                     if ($status_current == $status_correct) {
                         $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_LOAD;
                         if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $array_status) && $array_status[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) {
                             $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_LOAD_PVA;
                         }
                         // in busy (normally only loading is possible)
                         if (!CoreStatus_checkInWaitTime($timeout_check)) {
                             // already passed the timeout of changement
                             // change status into idle
                             $ret_val = CoreStatus_setInIdle();
                             if ($ret_val == FALSE) {
                                 $this->load->helper('printerlog');
                                 PrinterLog_logError('can not set idle after loading filament', __FILE__, __LINE__);
                                 $this->output->set_status_header(202);
                                 // disable checking
                             }
                             $this->_display_changecartridge_error_loading();
                             break;
                         }
                         $this->_display_changecartridge_in_load_filament();
                     } else {
                         if ($status_current == $status_changed) {
                             // in busy (but in idle, status is changed in real)
                             $ret_val = CoreStatus_setInIdle();
                             if ($ret_val == FALSE) {
                                 $this->load->helper('printerlog');
                                 PrinterLog_logError('can not set idle after loading filament', __FILE__, __LINE__);
                                 $this->output->set_status_header(202);
                                 // disable checking
                             }
                         } else {
                             // in other busy status
                             $this->load->helper('printerlog');
                             PrinterLog_logError('error status when changing filament', __FILE__, __LINE__);
                             $this->_display_changecartridge_error_status($status_current);
                             // 						$this->output->set_status_header(202); // disable checking
                         }
                     }
                 }
             }
             break;
         case PRINTERSTATE_CHANGECART_REMOVE_C:
             // we call the page: in unload filament
             // 				$status_current = NULL;
             $array_status = array();
             // 				CoreStatus_checkInIdle($status_current, $array_status);
             CoreStatus_getStatusArray($array_status);
             if (!$this->_deal_with_unloading_wait_time($abb_cartridge, $array_status)) {
                 $this->_display_changecartridge_in_unload_filament($abb_cartridge);
                 break;
             }
             if (PrinterState_getFilamentStatus($abb_cartridge)) {
                 // have filament
                 $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_UNLOAD;
                 if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $array_status) && $array_status[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) {
                     $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_UNLOAD_PVA;
                 }
                 if (!CoreStatus_checkInWaitTime($timeout_check)) {
                     // already passed the timeout of changement
                     // change status into idle
                     $ret_val = CoreStatus_setInIdle();
                     if ($ret_val == FALSE) {
                         $this->load->helper('printerlog');
                         PrinterLog_logError('can not set idle after unloading filament', __FILE__, __LINE__);
                         $this->output->set_status_header(202);
                         // disable checking
                     }
                     $this->_display_changecartridge_error_unloading();
                     break;
                 }
                 $this->_display_changecartridge_in_unload_filament($abb_cartridge);
             } else {
                 // no filament
                 $ret_val = CoreStatus_setInIdle();
                 if ($ret_val == FALSE) {
                     $this->load->helper('printerlog');
                     PrinterLog_logError('can not set idle after unloading filament', __FILE__, __LINE__);
                     $this->output->set_status_header(202);
                     // disable checking
                 }
                 $this->_display_changecartridge_remove_cartridge();
             }
             break;
         case PRINTERSTATE_CHANGECART_REINST_C:
             // we use switch breakdown to continue the treatement
             $low_hint = TRUE;
         case PRINTERSTATE_CHANGECART_INSERT_C:
             // we call the page: remove / reinsert cartridge
             $temp_data = NULL;
             $ret_val = PrinterState_checkFilament($abb_cartridge, $need_filament, $temp_data, FALSE);
             if ($ret_val == $code_miss_cartridge) {
                 // no cartridge
                 $this->_display_changecartridge_insert_cartridge();
             } else {
                 if ($ret_val == $code_low_filament) {
                     // have cartridge, low filament
                     $this->_display_changecartridge_remove_cartridge(TRUE);
                 } else {
                     if ($ret_val == $code_miss_filament) {
                         // have cartridge, no filemant
                         $this->_display_changecartridge_remove_cartridge($low_hint);
                     } else {
                         // error status
                         $this->load->helper('printerlog');
                         PrinterLog_logError('error checkfilament return status when changing filament (in removing)', __FILE__, __LINE__);
                         $this->_display_changecartridge_remove_cartridge();
                     }
                 }
             }
             break;
         case PRINTERSTATE_CHANGECART_LOAD_F:
             // we call the page: insert cartridge
             $temp_data = NULL;
             $ret_val = PrinterState_checkFilament($abb_cartridge, $need_filament, $temp_data, FALSE);
             if ($ret_val == $code_miss_filament) {
                 //TODO added a new temporary page here, need to remove when not needed
                 // 					$this->_display_changecartridge_wait_load_filament(FALSE);
                 // 					if ($temp_data[PRINTERSTATE_TITLE_CARTRIDGE] == PRINTERSTATE_DESP_CARTRIDGE_REFILL) {
                 // 						$this->_display_changecartridge_write_cartridge($abb_cartridge, PRINTERSTATE_CHANGECART_WAIT_F, $need_filament);
                 // 					}
                 // 					else {
                 // 						$this->_display_changecartridge_wait_load_filament(FALSE);
                 // 					}
                 $this->_display_changecartridge_write_cartridge($abb_cartridge, PRINTERSTATE_CHANGECART_WAIT_F, $need_filament);
                 //TODO a new filament quantity verification system
                 // turn off RFID power after changing
                 $ret_val = PrinterState_setRFIDPower(FALSE);
                 if ($ret_val != ERROR_OK) {
                     $this->load->helper('printerlog');
                     PrinterLog_logError('error in turning off RFID power', __FILE__, __LINE__);
                 }
             } else {
                 if ($ret_val == $code_low_filament) {
                     $this->_display_changecartridge_remove_cartridge(TRUE);
                 } else {
                     if ($ret_val == $code_miss_cartridge) {
                         // no cartridge
                         $this->_display_changecartridge_insert_cartridge();
                     } else {
                         // error status
                         $this->load->helper('printerlog');
                         PrinterLog_logError('error checkfilament return status when changing filament (in inserting)', __FILE__, __LINE__);
                         $this->_display_changecartridge_remove_cartridge();
                     }
                 }
             }
             break;
         case PRINTERSTATE_CHANGECART_WAIT_F:
             // we use switch breakdown to continue the treatement
             $change_able = FALSE;
         case PRINTERSTATE_CHANGECART_WAIT_F_C:
             // we call the page: wait load filament / change cartridge
             if (CoreStatus_checkInIdle()) {
                 // in idle
                 $this->_display_changecartridge_wait_load_filament($change_able, $id_model, $abb_cartridge);
             } else {
                 // in busy (normally only loading is possible)
                 $this->_display_changecartridge_in_load_filament();
             }
             break;
         case PRINTERSTATE_CHANGECART_NEED_P:
             // we call the page: in load filament
             // 				$status_current = NULL;
             $array_status = array();
             $offset_check = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_LOAD;
             // 				CoreStatus_checkInIdle($status_current, $array_status);
             CoreStatus_getStatusArray($array_status);
             if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $array_status) && $array_status[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) {
                 $offset_check = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_LOAD_PVA;
             }
             // wait the time for arduino before checking filament when loading filament
             if (CoreStatus_checkInWaitTime($offset_check)) {
                 $this->_display_changecartridge_in_load_filament();
                 break;
             }
             if (PrinterState_getFilamentStatus($abb_cartridge)) {
                 // have filament
                 $ret_val = CoreStatus_setInIdle();
                 if ($ret_val == FALSE) {
                     $this->load->helper('printerlog');
                     PrinterLog_logError('can not set idle after loading filament', __FILE__, __LINE__);
                     $this->output->set_status_header(202);
                     // disable checking
                 }
                 $this->_display_changecartridge_need_prime($abb_cartridge, $id_model);
             } else {
                 // no filament
                 $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_LOAD;
                 if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $array_status) && $array_status[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) {
                     $timeout_check = PRINTERSTATE_VALUE_TIMEOUT_TO_CHECK_LOAD_PVA;
                 }
                 if (!CoreStatus_checkInWaitTime($timeout_check)) {
                     // already passed the timeout of changement
                     CoreStatus_setInIdle();
                     //TODO need test and error control here
                     $this->_display_changecartridge_error_loading();
                     break;
                 }
                 $this->_display_changecartridge_in_load_filament();
             }
             break;
         default:
             break;
     }
     $this->output->set_content_type('text/plain; charset=UTF-8');
     return;
 }
Example #2
0
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
}