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; }
public function gcodedetail() { $data_json = array(); $gid = $this->input->get('id'); $array_data = array(); $check_left = NULL; $check_right = NULL; $change_left = NULL; $change_right = NULL; $enable_print = TRUE; $key_suggest_temper = 'suggest_temperature'; $bicolor = $this->config->item('nb_extruder') >= 2; $heat_bed = $this->config->item('heat_bed'); $this->load->helper(array('printerstoring', 'printerstate')); $data_json = PrinterStoring_getInfo('gcode', $gid); if (is_null($data_json)) { $this->output->set_header('Location: /printerstoring/listgcode'); return; } $this->load->library('parser'); $this->lang->load('printerstoring/gcodedetail', $this->config->item('language')); $check_left = $check_right = t('filament_ok'); $change_left = $change_right = t('change_filament'); foreach (array('r', 'l') as $abb_filament) { $data_cartridge = array(); $tmp_ret = 0; $volume_need = 0; $key_length = NULL; $key_material = NULL; if ($abb_filament == 'l') { $key_length = PRINTERSTORING_TITLE_LENG_L; $key_material = PRINTERSTORING_TITLE_MATER_L; } else { // $abb_filament == 'r' $key_length = PRINTERSTORING_TITLE_LENG_R; $key_material = PRINTERSTORING_TITLE_MATER_R; } if ($data_json[$key_length] > 0) { $volume_need = $data_json[$key_length]; // $array_need[$abb_filament] = 'true'; } else { if ($abb_filament == 'l') { $check_left = t('filament_not_need'); } else { // $abb_filament == 'r' $check_right = t('filament_not_need'); } } // check mono extruder case (normally, it's not necessary) if ($bicolor == FALSE && $abb_filament == 'l') { $tmp_ret = ERROR_MISS_LEFT_CART; } else { $tmp_ret = PrinterState_checkFilament($abb_filament, $volume_need, $data_cartridge); } if (in_array($tmp_ret, array(ERROR_OK, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_FILA, ERROR_LOW_LEFT_FILA, ERROR_LOW_RIGT_FILA))) { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => $data_cartridge[PRINTERSTATE_TITLE_COLOR], PRINTERSTATE_TITLE_EXT_TEMPER => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER], PRINTERSTATE_TITLE_MATERIAL => $data_cartridge[PRINTERSTATE_TITLE_MATERIAL]); // set default temperature if pla if ($data_cartridge[PRINTERSTATE_TITLE_MATERIAL] == PRINTERSTATE_DESP_MATERIAL_PLA) { $array_data[$abb_filament][PRINTERSTATE_TITLE_EXT_TEMPER] = PRINTERSTATE_VALUE_FILAMENT_PLA_PRINT_TEMPER; } } else { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => PRINTERSTATE_VALUE_DEFAULT_COLOR, PRINTERSTATE_TITLE_EXT_TEMPER => 0, PRINTERSTATE_TITLE_MATERIAL => NULL); } $array_data[$abb_filament][PRINTERSTATE_TITLE_NEED_L] = $volume_need; $array_data[$abb_filament][$key_suggest_temper] = 0; if ($volume_need > 0 && $data_json[$key_material] != $array_data[$abb_filament][PRINTERSTATE_TITLE_MATERIAL]) { $required_material = t('require_' . $data_json[$key_material]); if ($abb_filament == 'l') { $check_left = $required_material; } else { // $abb_filament == 'r' $check_right = $required_material; } $enable_print = FALSE; // disable print when material is different } else { // treat error switch ($tmp_ret) { case ERROR_OK: // do nothing if no error break; case ERROR_LOW_RIGT_FILA: $check_right = t('filament_not_enough'); break; case ERROR_MISS_RIGT_FILA: $check_right = t('filament_unloaded'); $change_right = t('load_filament'); break; case ERROR_MISS_RIGT_CART: $check_right = t('filament_empty'); $change_right = t('load_filament'); break; case ERROR_LOW_LEFT_FILA: $check_left = t('filament_not_enough'); break; case ERROR_MISS_LEFT_FILA: $check_left = t('filament_unloaded'); $change_left = t('load_filament'); break; case ERROR_MISS_LEFT_CART: $check_left = t('filament_empty'); $change_left = t('load_filament'); break; default: $this->load->helper('printerlog'); PrinterLog_logError('unexpected return when getting detail of gcode library model: ' . $cr, __FILE__, __LINE__); // assign error message if necessary if ($abb_filament == 'l') { $check_left = t('filament_error'); } else { // $abb_filament == 'r' $check_right = t('filament_error'); } break; } } // block print if ($enable_print == TRUE && $tmp_ret != ERROR_OK && $volume_need > 0) { $enable_print = FALSE; } } $template_data = array('home' => t('home'), 'back' => t('back'), 'id' => $gid, 'title' => $data_json['name'], 'photo_title' => t('photo_title'), 'title_current' => t('filament_title'), 'msg_ok' => t('filament_ok'), 'state_c_l' => $array_data['l'][PRINTERSTATE_TITLE_COLOR], 'state_c_r' => $array_data['r'][PRINTERSTATE_TITLE_COLOR], 'state_f_l' => $check_left, 'state_f_r' => $check_right, 'need_filament_l' => $array_data['l'][PRINTERSTATE_TITLE_NEED_L], 'need_filament_r' => $array_data['r'][PRINTERSTATE_TITLE_NEED_L], 'temper_filament_l' => $array_data['l'][PRINTERSTATE_TITLE_EXT_TEMPER], 'temper_filament_r' => $array_data['r'][PRINTERSTATE_TITLE_EXT_TEMPER], 'temper_suggest_l' => $array_data['l'][$key_suggest_temper], 'temper_suggest_r' => $array_data['r'][$key_suggest_temper], 'print_button' => t('print_button'), 'change_filament_l' => $change_left, 'change_filament_r' => $change_right, 'enable_print' => $enable_print ? 'true' : 'false', 'temp_adjustments_l' => t('temp_adjustments_l'), 'temp_adjustments_r' => t('temp_adjustments_r'), 'temp_adjustments' => t('temp_adjustments'), 'advanced' => t('advanced'), 'gcode_link' => t('gcode_link'), '2drender_link' => t('2drender_link'), 'temper_max' => PRINTERSTATE_TEMPER_CHANGE_MAX, 'temper_min' => PRINTERSTATE_TEMPER_CHANGE_MIN, 'temper_delta' => PRINTERSTATE_TEMPER_CHANGE_VAL, 'bicolor' => $bicolor ? 'true' : 'false', 'extrud_multiply' => t('extrud_multiply'), 'left_extrud_mult' => t('left_extrud_mult'), 'right_extrud_mult' => t('right_extrud_mult'), 'extrud_r' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_l' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_min' => PRINTERSTATE_EXT_MULTIPLY_MIN, 'extrud_max' => PRINTERSTATE_EXT_MULTIPLY_MAX, 'title_heatbed' => t('title_heatbed'), 'button_bed_off' => t('button_bed_off'), 'heat_bed' => $heat_bed ? 'true' : 'false', 'bed_temper_pla' => PRINTERSTATE_TEMPER_BED_PLA, 'bed_temper_abs' => PRINTERSTATE_TEMPER_BED_ABS, 'bed_temper_max' => PRINTERSTATE_TEMPER_MAX_H); // parse all page $this->_parseBaseTemplate(t('printerstoring_gcodedetail_pagetitle'), $this->parser->parse('printerstoring/gcodedetail', $template_data, TRUE)); return; }
function slice_result_ajax() { $template_data = array(); $cr = ERROR_OK; $array_data = array(); $check_filament = array(); $change_filament = array(); $data_json = array(); $error = NULL; $bicolor_model = FALSE; $exchange_select_snd = FALSE; $bicolor_printer = $this->config->item('nb_extruder') >= 2; $heat_bed = $this->config->item('heat_bed'); $enable_print = 'false'; $enable_exchange = 'disabled="disabled"'; // select disable $option_selected = 'selected="selected"'; $this->load->helper(array('printerstate', 'slicer')); $this->load->library('parser'); $this->lang->load('sliceupload/slice_status_ajax', $this->config->item('language')); $cr = PrinterState_getSlicedJson($data_json); if ($cr != ERROR_OK) { $display = $cr . " " . t(MyERRMSG($cr)); $this->output->set_status_header($cr); $this->output->set_content_type('txt_u'); $this->parser->parse('plaintxt', array('display' => $display)); //optional return; } else { $material = NULL; $check_filament = array('l' => t('filament_ok'), 'r' => t('filament_ok')); $change_filament = array('l' => t('change_filament'), 'r' => t('change_filament')); foreach (array('r', 'l') as $abb_filament) { $data_cartridge = array(); $data_slice = array(); $tmp_ret = 0; $volume_need = 0; if (isset($data_json[$abb_filament])) { $data_slice = $data_json[$abb_filament]; if (isset($data_slice[PRINTERSTATE_TITLE_NEED_L])) { $volume_need = $data_slice[PRINTERSTATE_TITLE_NEED_L]; } } else { $check_filament[$abb_filament] = t('filament_not_need'); } // check mono extruder case (normally, it's not necessary) if ($bicolor_printer == FALSE && $abb_filament == 'l') { $tmp_ret = ERROR_MISS_LEFT_CART; } else { $tmp_ret = PrinterState_checkFilament($abb_filament, $volume_need, $data_cartridge); } if (in_array($tmp_ret, array(ERROR_OK, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_FILA, ERROR_LOW_LEFT_FILA, ERROR_LOW_RIGT_FILA))) { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => $data_cartridge[PRINTERSTATE_TITLE_COLOR], PRINTERSTATE_TITLE_EXT_TEMPER => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER], PRINTERSTATE_TITLE_EXT_TEMP_1 => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]); // set default temperature if pla if ($data_cartridge[PRINTERSTATE_TITLE_MATERIAL] == PRINTERSTATE_DESP_MATERIAL_PLA) { $array_data[$abb_filament][PRINTERSTATE_TITLE_EXT_TEMPER] = PRINTERSTATE_VALUE_FILAMENT_PLA_PRINT_TEMPER; } } else { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => PRINTERSTATE_VALUE_DEFAULT_COLOR, PRINTERSTATE_TITLE_EXT_TEMPER => SLICER_VALUE_DEFAULT_TEMPER, PRINTERSTATE_TITLE_EXT_TEMP_1 => SLICER_VALUE_DEFAULT_FIRST_TEMPER); } $array_data[$abb_filament][PRINTERSTATE_TITLE_NEED_L] = $volume_need; // treat error switch ($tmp_ret) { case ERROR_OK: // do nothing if no error break; case ERROR_LOW_RIGT_FILA: $check_filament['r'] = t('filament_not_enough'); break; case ERROR_MISS_RIGT_FILA: $check_filament['r'] = t('filament_unloaded'); $change_filament['r'] = t('load_filament'); break; case ERROR_MISS_RIGT_CART: $check_filament['r'] = t('filament_empty'); $change_filament['r'] = t('load_filament'); break; case ERROR_LOW_LEFT_FILA: $check_filament['l'] = t('filament_not_enough'); break; case ERROR_MISS_LEFT_FILA: $check_filament['l'] = t('filament_unloaded'); $change_filament['l'] = t('load_filament'); break; case ERROR_MISS_LEFT_CART: $check_filament['l'] = t('filament_empty'); $change_filament['l'] = t('load_filament'); break; default: $this->load->helper('printerlog'); PrinterLog_logError('unexpected return when generating slicing result: ' . $tmp_ret, __FILE__, __LINE__); // assign error message if necessary $check_filament[$abb_filament] = t('filament_error'); break; } // assign $cr only when status is ok (acts like a flag of error) if ($cr == ERROR_OK && $volume_need > 0) { $cr = $tmp_ret; } // check material difference for all used cartridges if (!in_array($tmp_ret, array(ERROR_INTERNAL, ERROR_MISS_LEFT_CART, ERROR_MISS_RIGT_CART)) && $volume_need > 0) { if ($material == NULL) { $material = $data_cartridge[PRINTERSTATE_TITLE_MATERIAL]; } else { if ($material != $data_cartridge[PRINTERSTATE_TITLE_MATERIAL]) { $error .= t('cartridge_material_diff_msg') . '<br>'; } } // if ($volume_need > 0) { // act as count($data_slice), but with more verification // if ($data_slice[PRINTERSTATE_TITLE_EXT_TEMPER] != $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER]) { // $error .= t('temper_diff_msg', // array( // $data_slice[PRINTERSTATE_TITLE_EXT_TEMPER], // $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER], // ) // ) . '<br>'; // } // if ($data_slice[PRINTERSTATE_TITLE_EXT_TEMP_1] != $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]) { // $error .= t('first_temper_diff_msg', // array( // $data_slice[PRINTERSTATE_TITLE_EXT_TEMP_1], // $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1], // ) // ) . '<br>'; // } // } } } if (!is_null($error)) { $error .= t('suggest_reslice'); } // check enable print if ($cr == ERROR_OK) { $enable_print = 'true'; } // check bicolor model if ($array_data['r'][PRINTERSTATE_TITLE_NEED_L] > 0 && $array_data['l'][PRINTERSTATE_TITLE_NEED_L] > 0) { $bicolor_model = TRUE; } else { if ($array_data['r'][PRINTERSTATE_TITLE_NEED_L] > 0) { $exchange_select_snd = TRUE; } } // check exchange possiblity if (ERROR_OK == PrinterState_checkFilaments(array('l' => $array_data['r'][PRINTERSTATE_TITLE_NEED_L], 'r' => $array_data['l'][PRINTERSTATE_TITLE_NEED_L]))) { $enable_exchange = NULL; // enable exchange if verification is passed } else { if ($bicolor_model == FALSE) { if ($array_data['l'][PRINTERSTATE_TITLE_NEED_L] == 0 && $check_filament['l'] == t('filament_not_need')) { $check_filament['l'] = t('filament_not_enough_for_switch'); } else { if ($array_data['r'][PRINTERSTATE_TITLE_NEED_L] == 0 && $check_filament['r'] == t('filament_not_need')) { $check_filament['r'] = t('filament_not_enough_for_switch'); } } } } } if ($heat_bed) { $bed_temper = 0; $cr = Slicer_getParameter('bed_temperature', $bed_temper); $heat_bed = (int) $bed_temper > 0; // disable heat bed if it is not set by user } $template_data = array('cartridge_c_l' => $array_data['l'][PRINTERSTATE_TITLE_COLOR], 'cartridge_c_r' => $array_data['r'][PRINTERSTATE_TITLE_COLOR], 'state_f_l' => $check_filament['l'], 'state_f_r' => $check_filament['r'], 'need_filament_l' => $array_data['l'][PRINTERSTATE_TITLE_NEED_L], 'need_filament_r' => $array_data['r'][PRINTERSTATE_TITLE_NEED_L], 'temper_l' => $array_data['l'][PRINTERSTATE_TITLE_EXT_TEMPER], 'temper_r' => $array_data['r'][PRINTERSTATE_TITLE_EXT_TEMPER], 'print_button' => t('print_button'), 'left_temperature' => t('left_temperature'), 'right_temperature' => t('right_temperature'), 'chg_temperature' => t('chg_temperature'), 'change_left' => $change_filament['l'], 'change_right' => $change_filament['r'], 'error_msg' => $error, 'reslice_button' => t('reslice_button'), 'exchange_extruder' => t('exchange_extruder'), 'exchange_o1_val' => $exchange_select_snd ? 1 : 0, 'exchange_o2_val' => $exchange_select_snd ? 0 : 1, 'exchange_o2_sel' => $exchange_select_snd ? $option_selected : NULL, 'exchange_o1' => t('exchange_left'), 'exchange_o2' => t('exchange_right'), 'advanced' => t('advanced'), 'gcode_link' => t('gcode_link'), '2drender_link' => t('2drender_link'), 'filament_not_need' => t('filament_not_need'), 'filament_ok' => t('filament_ok'), 'result_title' => t('result_title'), 'temper_max' => PRINTERSTATE_TEMPER_CHANGE_MAX, 'temper_min' => PRINTERSTATE_TEMPER_CHANGE_MIN, 'temper_delta' => PRINTERSTATE_TEMPER_CHANGE_VAL, 'enable_print' => $enable_print, 'enable_exchange' => $enable_exchange, 'enable_reslice' => $error ? 'true' : 'false', 'bicolor_printer' => $bicolor_printer ? 'true' : 'false', 'bicolor_model' => $bicolor_model ? 'true' : 'false', 'extrud_multiply' => t('extrud_multiply'), 'left_extrud_mult' => t('left_extrud_mult'), 'right_extrud_mult' => t('right_extrud_mult'), 'extrud_r' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_l' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_min' => PRINTERSTATE_EXT_MULTIPLY_MIN, 'extrud_max' => PRINTERSTATE_EXT_MULTIPLY_MAX, 'title_heatbed' => t('title_heatbed'), 'button_bed_off' => t('button_bed_off'), 'heat_bed' => $heat_bed ? 'true' : 'false', 'bed_temper_pla' => PRINTERSTATE_TEMPER_BED_PLA, 'bed_temper_abs' => PRINTERSTATE_TEMPER_BED_ABS, 'bed_temper_max' => PRINTERSTATE_TEMPER_MAX_H); $this->parser->parse('sliceupload/slice_result_ajax', $template_data); $this->output->set_status_header(202); return; }
public function detail() { $model_data = array(); $template_data = array(); $cr = 0; $check_filament = array(); $change_filament = array(); $array_data = array(); $time_estimation = NULL; $body_page = NULL; $mono_model = FALSE; $bicolor = $this->config->item('nb_extruder') >= 2; $heat_bed = $this->config->item('heat_bed'); $enable_print = 'true'; $enable_exchange = 'disabled="disabled"'; // select disable $calibration = FALSE; $this->load->helper(array('printlist', 'printerstate', 'slicer', 'timedisplay')); $this->load->library('parser'); $this->lang->load('printlist', $this->config->item('language')); $this->lang->load('timedisplay', $this->config->item('language')); $mid = $this->input->get('id'); // check model id, resend user to if not valid if ($mid) { if ($mid == 'calibration') { $mid = ModelList_codeModelHash(PRINTLIST_MODEL_CALIBRATION); $calibration = TRUE; } $cr = ModelList__getDetailAsArray($mid, $model_data, TRUE); if ($cr != ERROR_OK || is_null($model_data)) { $this->output->set_header('Location: /printmodel/listmodel'); return; } } else { $this->output->set_header('Location: /printmodel/listmodel'); return; } // check the model is mono-color or 2 colors if (isset($model_data[PRINTLIST_TITLE_LENG_F2]) && $model_data[PRINTLIST_TITLE_LENG_F2] > 0) { $mono_model = FALSE; } else { $mono_model = TRUE; } // initialize variables $check_filament = array('l' => t('ok'), 'r' => t('ok')); $change_filament = array('l' => t('Change'), 'r' => t('Change')); // check quantity of filament and get cartridge information (color) // color1 => right, color2 => left foreach (array('r', 'l') as $abb_filament) { $data_cartridge = array(); $key_length = $abb_filament == 'l' ? PRINTLIST_TITLE_LENG_F2 : PRINTLIST_TITLE_LENG_F1; $key_color = $abb_filament == 'l' ? PRINTLIST_TITLE_COLOR_F2 : PRINTLIST_TITLE_COLOR_F1; if ($model_data[$key_length] <= 0) { $check_filament[$abb_filament] = t('filament_not_need'); } // check mono extruder case (normally, it's not necessary) if ($bicolor == FALSE && $abb_filament == 'l') { $cr = ERROR_MISS_LEFT_CART; } else { $cr = PrinterState_checkFilament($abb_filament, $model_data[$key_length], $data_cartridge); } if (in_array($cr, array(ERROR_OK, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_FILA, ERROR_LOW_LEFT_FILA, ERROR_LOW_RIGT_FILA))) { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => $data_cartridge[PRINTERSTATE_TITLE_COLOR], PRINTERSTATE_TITLE_EXT_TEMPER => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER]); // set default temperature if pla if ($data_cartridge[PRINTERSTATE_TITLE_MATERIAL] == PRINTERSTATE_DESP_MATERIAL_PLA) { $array_data[$abb_filament][PRINTERSTATE_TITLE_EXT_TEMPER] = PRINTERSTATE_VALUE_FILAMENT_PLA_PRINT_TEMPER; } } else { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => PRINTERSTATE_VALUE_DEFAULT_COLOR, PRINTERSTATE_TITLE_EXT_TEMPER => SLICER_VALUE_DEFAULT_TEMPER); } $array_data[$abb_filament][PRINTERSTATE_TITLE_NEED_L] = $model_data[$key_length]; // treat error switch ($cr) { case ERROR_OK: // do nothing if no error break; case ERROR_LOW_RIGT_FILA: $check_filament['r'] = t('not enough'); break; case ERROR_MISS_RIGT_FILA: $check_filament['r'] = t('unloaded'); $change_filament['r'] = t('Load'); break; case ERROR_MISS_RIGT_CART: $check_filament['r'] = t('empty'); $change_filament['r'] = t('Load'); break; case ERROR_LOW_LEFT_FILA: $check_filament['l'] = t('not enough'); break; case ERROR_MISS_LEFT_FILA: $check_filament['l'] = t('unloaded'); $change_filament['l'] = t('Load'); break; case ERROR_MISS_LEFT_CART: $check_filament['l'] = t('empty'); $change_filament['l'] = t('Load'); break; default: $this->load->helper('printerlog'); PrinterLog_logError('not previewed return code for checking filament ' . $abb_filament, __FILE__, __LINE__); // assign error message if necessary $check_filament[$abb_filament] = t('error'); break; } if ($cr != ERROR_OK && $model_data[$key_length] > 0) { $enable_print = 'false'; } } // get a more legible time of estimation $time_estimation = TimeDisplay__convertsecond($model_data[PRINTLIST_TITLE_TIME], t('Time estimation: '), t('unknown')); // check if we can inverse filament / exchange extruder or not $cr = PrinterState_checkFilaments(array('l' => $array_data['r'][PRINTERSTATE_TITLE_NEED_L], 'r' => $array_data['l'][PRINTERSTATE_TITLE_NEED_L])); if ($cr == ERROR_OK && $calibration == FALSE) { $enable_exchange = NULL; } else { if ($mono_model == TRUE) { if ($array_data['l'][PRINTERSTATE_TITLE_NEED_L] == 0) { $check_filament['l'] = t('filament_not_enough_for_switch'); } else { // ($array_data['r'][PRINTERSTATE_TITLE_NEED_L] == 0) $check_filament['r'] = t('filament_not_enough_for_switch'); } } } // show detail page if valid, parse the body of page $template_data = array('home' => t('Home'), 'title' => $model_data[PRINTLIST_TITLE_NAME], 'image' => $model_data[PRINTLIST_TITLE_PIC][0], 'model_c_r' => $model_data[PRINTLIST_TITLE_COLOR_F1], 'model_c_l' => $model_data[PRINTLIST_TITLE_COLOR_F2], 'time' => $time_estimation, 'desp' => $model_data[PRINTLIST_TITLE_DESP], 'state_c_l' => $array_data['l'][PRINTERSTATE_TITLE_COLOR], 'state_c_r' => $array_data['r'][PRINTERSTATE_TITLE_COLOR], 'state_f_l' => $check_filament['l'], 'state_f_r' => $check_filament['r'], 'model_id' => $mid, 'title_current' => t('Filament'), 'change_filament_l' => $change_filament['l'], 'change_filament_r' => $change_filament['r'], 'need_filament_l' => $model_data[PRINTLIST_TITLE_LENG_F2], 'need_filament_r' => $model_data[PRINTLIST_TITLE_LENG_F1], 'temper_filament_l' => $array_data['l'][PRINTERSTATE_TITLE_EXT_TEMPER], 'temper_filament_r' => $array_data['r'][PRINTERSTATE_TITLE_EXT_TEMPER], 'print_model' => t('Print'), 'back' => t('back'), 'preview_title' => t('Preview'), 'desp_title' => t('Description'), 'color_suggestion' => t('color_suggestion'), 'temp_adjustments_l' => t('temp_adjustments_l'), 'temp_adjustments_r' => t('temp_adjustments_r'), 'chg_temperature' => t('chg_temperature'), 'error' => t('error'), 'filament_not_need' => t('filament_not_need'), 'filament_ok' => t('ok'), 'temper_max' => PRINTERSTATE_TEMPER_CHANGE_MAX, 'temper_min' => PRINTERSTATE_TEMPER_CHANGE_MIN, 'temper_delta' => PRINTERSTATE_TEMPER_CHANGE_VAL, 'exchange_on' => t('exchange_left'), 'exchange_off' => t('exchange_right'), 'exchange_extruder' => t('exchange_extruder'), 'random_prefix' => $mid . '_' . rand() . '_', 'enable_exchange' => $enable_exchange, 'enable_print' => $enable_print, 'bicolor_model' => $mono_model ? 'false' : 'true', 'bicolor_printer' => $bicolor ? 'true' : 'false', 'advanced' => t('advanced'), 'extrud_multiply' => t('extrud_multiply'), 'left_extrud_mult' => t('left_extrud_mult'), 'right_extrud_mult' => t('right_extrud_mult'), 'extrud_r' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_l' => PRINTERSTATE_EXT_MULTIPLY_DEFAULT, 'extrud_min' => PRINTERSTATE_EXT_MULTIPLY_MIN, 'extrud_max' => PRINTERSTATE_EXT_MULTIPLY_MAX, 'title_heatbed' => t('title_heatbed'), 'button_bed_off' => t('button_bed_off'), 'heat_bed' => $heat_bed ? 'true' : 'false', 'bed_temper_pla' => PRINTERSTATE_TEMPER_BED_PLA, 'bed_temper_abs' => PRINTERSTATE_TEMPER_BED_ABS, 'bed_temper_max' => PRINTERSTATE_TEMPER_MAX_H); $this->_parseBaseTemplate(t('ZeePro Personal Printer 21 - Printing details'), $this->parser->parse('printlist/detail', $template_data, TRUE)); return; }
function PrinterState__setSlicedJson($array_slicer, &$array_ret = array()) { $array_data = array(); $CI =& get_instance(); $CI->load->helper('slicer'); // copy the data we need and check filament foreach ($array_slicer as $abb_filament => $volume_need) { $data_cartridge = array(); $tmp_ret = 0; $tmp_ret = PrinterState_checkFilament($abb_filament, $volume_need, $data_cartridge); // we will ignore the error of cartridge checking if slicing is well done (default value assigned even if not true) if (in_array($tmp_ret, array(ERROR_OK, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_FILA, ERROR_LOW_LEFT_FILA, ERROR_LOW_RIGT_FILA))) { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => $data_cartridge[PRINTERSTATE_TITLE_COLOR], PRINTERSTATE_TITLE_EXT_TEMPER => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER], PRINTERSTATE_TITLE_EXT_TEMP_1 => $data_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1], PRINTERSTATE_TITLE_NEED_L => $volume_need, PRINTERSTATE_TITLE_MATERIAL => $data_cartridge[PRINTERSTATE_TITLE_MATERIAL]); } else { $array_data[$abb_filament] = array(PRINTERSTATE_TITLE_COLOR => PRINTERSTATE_VALUE_DEFAULT_COLOR, PRINTERSTATE_TITLE_EXT_TEMPER => SLICER_VALUE_DEFAULT_TEMPER, PRINTERSTATE_TITLE_EXT_TEMP_1 => SLICER_VALUE_DEFAULT_FIRST_TEMPER, PRINTERSTATE_TITLE_NEED_L => $volume_need, PRINTERSTATE_TITLE_MATERIAL => PRINTERSTATE_DESP_MATERIAL_PLA); } //TODO use the exact fail code in parameter error_type of PrinterState_getCartridgeAsArray to decide whether we break and return error or not $array_ret[$abb_filament] = $tmp_ret; if ($tmp_ret != ERROR_OK) { $CI->load->helper('printerlog'); PrinterLog_logError('check filament error after slicing, cr: ' . $tmp_ret, __FILE__, __LINE__); } } // save the json file try { $fp = fopen($CI->config->item('temp') . SLICER_FILE_TEMP_DATA, 'w'); if ($fp) { fwrite($fp, json_encode($array_data)); fclose($fp); } else { throw new Exception('can not open file'); } } catch (Exception $e) { $CI->load->helper('printerlog'); PrinterLog_logError('can not save temp json file', __FILE__, __LINE__); return ERROR_INTERNAL; } return ERROR_OK; }