public function load() { $cr = 0; $array_cartridge = array(); $abb_cartridge = $this->input->get('v'); $this->load->helper('printerstate'); if ($abb_cartridge) { switch ($abb_cartridge) { case 'l': case 'r': $cr = PrinterState_getCartridgeAsArray($array_cartridge, $abb_cartridge); if ($cr != ERROR_OK) { break; } $cr = PrinterState_loadFilament($abb_cartridge); break; default: $cr = ERROR_WRONG_PRM; break; } } else { $cr = ERROR_MISS_PRM; } $this->_return_cr($cr); return; }
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; }
public function readnwrite($side = 'r') { $cr = 0; $cartridge_code = NULL; $err_code = NULL; $error = NULL; $cartridge_data = array(); $initial_length_value = 0; $used_length_value = 0; $temper_value = 0; $temper_first = 0; $material_value = 0; $cartridge_value = 0; $color_value = '#ffffff'; $option_selected = 'selected="selected"'; $packdate_val = 'N/A'; // right as default if (in_array($side, array('l', 'left'))) { $side = 'l'; } else { $side = 'r'; } $this->load->library('parser'); $this->lang->load('cartridge', $this->config->item('language')); if (PrinterState_getCartridgeCode($cartridge_code, $side) != ERROR_OK) { $cartridge_code = t('error retrieving cartridge code'); } $cr = PrinterState_getCartridgeAsArray($cartridge_data, $side, TRUE, $err_code); if ($cr != ERROR_OK) { $initial_length_value = 20; $used_length_value = 10; $temper_value = 200; $temper_first = 210; if ($cr == ERROR_INTERNAL) { switch ($err_code) { case PRINTERSTATE_CARTRIDGE_ERR_MAGIC: $error = t('magic_number_error'); break; case PRINTERSTATE_CARTRIDGE_ERR_CRC: $error = t('crc_error'); break; case PRINTERSTATE_CARTRIDGE_ERR_CART: $error = t('cartridge_type_error'); break; case PRINTERSTATE_CARTRIDGE_ERR_FILA: $error = t('filament_type_error'); break; default: $error = t('internal_error'); break; } } else { if (in_array($cr, array(ERROR_MISS_LEFT_CART, ERROR_MISS_RIGT_CART))) { $error = 'No cartridge'; } } } else { $initial_length_value = $cartridge_data[PRINTERSTATE_TITLE_INITIAL] / 1000; $used_length_value = $cartridge_data[PRINTERSTATE_TITLE_USED] / 1000; // if ($length_value < 10) { // $length_value = 10; // } $temper_value = $cartridge_data[PRINTERSTATE_TITLE_EXT_TEMPER]; $temper_first = $cartridge_data[PRINTERSTATE_TITLE_EXT_TEMP_1]; $color_value = $cartridge_data[PRINTERSTATE_TITLE_COLOR]; if ($temper_value < 165) { $temper_value = 165; } $packdate_val = $cartridge_data[PRINTERSTATE_TITLE_SETUP_DATE]; } $template_data = array('material_array' => array(array('name' => t('PLA'), 'value' => PRINTERSTATE_VALUE_MATERIAL_PLA, 'on' => NULL), array('name' => t('ABS'), 'value' => PRINTERSTATE_VALUE_MATERIAL_ABS, 'on' => NULL), array('name' => t('PVA'), 'value' => PRINTERSTATE_VALUE_MATERIAL_PVA, 'on' => NULL)), 'cartridge_array' => array(array('name' => t('Normal'), 'value' => PRINTERSTATE_VALUE_CARTRIDGE_NORMAL, 'on' => NULL), array('name' => t('Refill'), 'value' => PRINTERSTATE_VALUE_CARTRIDGE_REFILL, 'on' => NULL)), 'cartridge_code' => $cartridge_code, 'initial_length_value' => $initial_length_value, 'used_length_value' => $used_length_value, 'temper_value' => $temper_value, 'temper_f_value' => $temper_first, 'rfid_color' => $color_value, 'abb_cartridge' => $side, 'side_cartridge' => $side == 'l' ? t('left') : t('right'), 'error' => $error, 'color' => t('color'), 'cartridge_type' => t('cartridge_type'), 'material_type' => t('material_type'), 'temperature' => t('temperature'), 'temperature_first' => t('temperature_first'), 'initial_length' => t('initial_length'), 'used_length' => t('used_length'), 'initial_length_mm' => t('initial_length_mm'), 'used_length_mm' => t('used_length_mm'), 'cartridge_code_hint' => t('cartridge_code_hint'), 'magic_number' => t('magic_number'), 'red_label' => t('red_label'), 'green_label' => t('green_label'), 'blue_label' => t('blue_label'), 'pack_label' => t('pack_label'), 'checksum_label' => t('checksum_label'), 'write_button' => t('write_button'), 'pack_date_val' => $packdate_val, 'info_not_changed' => t('information_not_changed'), 'writing_successed' => t('writing_successed'), 'error_writing' => t('error_writing'), 'bicolor' => $this->config->item('nb_extruder') >= 2 ? 'true' : 'false'); if ($cr == ERROR_OK) { switch ($cartridge_data[PRINTERSTATE_TITLE_MATERIAL]) { case PRINTERSTATE_DESP_MATERIAL_PLA: $material_value = PRINTERSTATE_VALUE_MATERIAL_PLA; break; case PRINTERSTATE_DESP_MATERIAL_ABS: $material_value = PRINTERSTATE_VALUE_MATERIAL_ABS; break; case PRINTERSTATE_DESP_MATERIAL_PVA: $material_value = PRINTERSTATE_VALUE_MATERIAL_PVA; break; default: $material_value = PRINTERSTATE_VALUE_MATERIAL_PLA; break; } $template_data['material_array'][$material_value]['on'] = $option_selected; switch ($cartridge_data[PRINTERSTATE_TITLE_CARTRIDGE]) { case PRINTERSTATE_DESP_CARTRIDGE_NORMAL: $cartridge_value = PRINTERSTATE_VALUE_CARTRIDGE_NORMAL; break; case PRINTERSTATE_DESP_CARTRIDGE_REFILL: $cartridge_value = PRINTERSTATE_VALUE_CARTRIDGE_REFILL; break; default: $cartridge_value = PRINTERSTATE_VALUE_CARTRIDGE_NORMAL; break; } $template_data['cartridge_array'][$cartridge_value]['on'] = $option_selected; } // parse all page $this->_parseBaseTemplate(t('readnwrite_pagetitle'), $this->parser->parse('cartridge', $template_data, TRUE)); return; }
public function filament_ajax($side) { $this->load->library('parser'); $this->load->helper('printerstate'); $this->lang->load('manage/filament_ajax', $this->config->item('language')); $json_cartridge = array(); $ret_val = PrinterState_getCartridgeAsArray($json_cartridge, $side); if ($ret_val != ERROR_MISS_LEFT_CART && $ret_val != ERROR_MISS_RIGT_CART) { $action = PrinterState_getFilamentStatus($side) ? t('loaded_action') : t('unloaded_action'); $initial = intval($json_cartridge['initial']); $used = intval($json_cartridge['used']); $template_data = array('visibility' => "visible", 'color' => $json_cartridge['color'], 'material' => "<br />" . strtoupper($json_cartridge['material']) . "<br />", 'length' => number_format(round(($initial - $used) / 1000, 2, PHP_ROUND_HALF_DOWN), 2), 'length_text' => t('length_text'), 'action' => $action); $this->parser->parse('manage/manage_filament_ajax', $template_data); } else { $template_data = array('visibility' => "hidden", 'color' => "#FFFFFF", 'material' => "", 'length' => "", 'length_text' => "", 'action' => t('insert_action') . "<br /><br /><br /><br />"); $this->parser->parse('manage/manage_filament_ajax', $template_data); } $this->output->set_status_header(202); return; }
function Slicer_changeTemperByCartridge($array_cartridge, $heat_bed = FALSE) { $json_cartridge = array(); $temperature = $first_temperature = NULL; $array_danger_return = array(ERROR_INTERNAL, ERROR_WRONG_PRM, ERROR_BUSY_PRINTER, ERROR_MISS_RIGT_CART, ERROR_MISS_LEFT_CART); $CI =& get_instance(); $CI->load->helper('printerstate'); // foreach ($array_cartridge as $abb_cartridge) { // switch ($abb_cartridge) { // case 'r': // $array_danger_return[] = ERROR_MISS_RIGT_CART; // break; // case 'l': // $array_danger_return[] = ERROR_MISS_LEFT_CART; // break; // default: // $CI->load->helper('printerlog'); // PrinterLog_logError('unknown cartridge abb value', __FILE__, __LINE__); // return ERROR_INTERNAL; // break; // never reach here // } // } foreach (array('r', 'l') as $abb_cartridge) { $ret_val = PrinterState_getCartridgeAsArray($json_cartridge, $abb_cartridge); //TODO think about if we need to set default temperature when cartridge is absent or not if (in_array($ret_val, $array_danger_return)) { //TODO notice the printerstate helper that slicer use default temperature instead of cartridge info (user can put cartridge during slicing) $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER] = SLICER_VALUE_DEFAULT_TEMPER; $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1] = SLICER_VALUE_DEFAULT_FIRST_TEMPER; $CI->load->helper('printerlog'); PrinterLog_logMessage('dangerous return detected: ' . $ret_val . ', slicer default temperature assigned for cartridge ' . $abb_cartridge, __FILE__, __LINE__); } if (is_null($temperature)) { $temperature = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER]; } else { $temperature .= ',' . $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER]; } if (is_null($first_temperature)) { $first_temperature = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]; } else { $first_temperature .= ',' . $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]; } } $array_setting = array('temperature' => $temperature, 'first_layer_temperature' => $first_temperature); if ($heat_bed) { $array_setting['bed_temperature'] = SLICER_VALUE_DEFAULT_BED_TEMPER; } $cr = Slicer_changeParameter($array_setting); return $cr; }
function Printer__changeGcode(&$gcode_path, $array_filament = array(), $exchange_extruder = FALSE, &$array_temper = array(), $temper_material = FALSE) { $temp_r = 0; // right normal temper $temp_rs = 0; // right start temper $temp_l = 0; // left normal temper $temp_ls = 0; // left start temper $temp_b = isset($array_temper['b']) && $array_temper['b'] > 0 ? $array_temper['b'] : 0; // bed temper $cr = 0; $command = NULL; $output = array(); $json_cartridge = array(); $CI =& get_instance(); $CI->load->helper('printerstate'); if ($exchange_extruder) { $command = $CI->config->item('gcdaemon') . PRINTER_PRM_EXCHANGE_E . PRINTER_PRM_FILE . $gcode_path . ' > ' . $gcode_path . '.new'; // debug message for test $CI->load->helper('printerlog'); PrinterLog_logDebug('change extruder: ' . $command, __FILE__, __LINE__); @unlink($gcode_path . '.new'); // delete old file exec($command, $output, $cr); if ($cr != ERROR_NORMAL_RC_OK) { $CI->load->helper('printerlog'); PrinterLog_logError('change extruder error', __FILE__, __LINE__); return ERROR_INTERNAL; } $gcode_path = $gcode_path . '.new'; } // temporary change - make it possible to change temperature not according to cartridge //TODO remove me when it is necessary if (array_key_exists('r', $array_temper) && $array_temper['r'] > 0) { $temp_r = $array_temper['r']; $temp_rs = $temp_r + 10; // if ($temp_r > $temp_rs) { // $temp_rs = $temp_r; // } } else { if (!array_key_exists('r', $array_filament) || $array_filament['r'] <= 0) { // ignore the cartridge which we do not need $CI->load->helper('slicer'); $temp_r = SLICER_VALUE_DEFAULT_TEMPER; $temp_rs = SLICER_VALUE_DEFAULT_FIRST_TEMPER; } else { $cr = PrinterState_getCartridgeAsArray($json_cartridge, 'r'); if ($cr == ERROR_OK) { if ($temper_material) { //TODO need to reunion all getting temperature functions switch ($json_cartridge[PRINTERSTATE_TITLE_MATERIAL]) { case PRINTERSTATE_DESP_MATERIAL_PLA: $temp_rs = PRINTERSTATE_VALUE_FILAMENT_PLA_LOAD_TEMPER; break; case PRINTERSTATE_DESP_MATERIAL_ABS: $temp_rs = PRINTERSTATE_VALUE_FILAMENT_ABS_LOAD_TEMPER; break; case PRINTERSTATE_DESP_MATERIAL_PVA: $temp_rs = PRINTERSTATE_VALUE_FILAMENT_PVA_LOAD_TEMPER; break; default: PrinterLog_logError('unknown filament type in priming', __FILE__, __LINE__); // return ERROR_INTERNAL; $temp_rs = SLICER_VALUE_DEFAULT_FIRST_TEMPER; break; } $temp_r = $temp_rs; } else { $temp_r = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER]; $temp_rs = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]; } } else { if ($cr == ERROR_MISS_RIGT_CART) { $CI->load->helper('slicer'); $temp_r = SLICER_VALUE_DEFAULT_TEMPER; $temp_rs = SLICER_VALUE_DEFAULT_FIRST_TEMPER; // $temp_r = $temp_rs = PRINTER_VALUE_DEFAULT_TEMPER; } } } } if ($temp_r * $temp_rs == 0) { // we have at least one value not initialised to call change temper program return $cr == ERROR_OK ? ERROR_INTERNAL : $cr; } else { $array_temper['r'] = $temp_r; } if ($CI->config->item('nb_extruder') >= 2) { // make it possible to change temperature not according to cartridge if (array_key_exists('l', $array_temper) && $array_temper['l'] > 0) { $temp_l = $array_temper['l']; $temp_ls = $temp_l + 10; } else { if (!array_key_exists('l', $array_filament) || $array_filament['l'] <= 0) { // ignore the cartridge which we do not need $CI->load->helper('slicer'); $temp_l = SLICER_VALUE_DEFAULT_TEMPER; $temp_ls = SLICER_VALUE_DEFAULT_FIRST_TEMPER; } else { $cr = PrinterState_getCartridgeAsArray($json_cartridge, 'l'); if ($cr == ERROR_OK) { if ($temper_material) { //TODO need to reunion all getting temperature functions switch ($json_cartridge[PRINTERSTATE_TITLE_MATERIAL]) { case PRINTERSTATE_DESP_MATERIAL_PLA: $temp_ls = PRINTERSTATE_VALUE_FILAMENT_PLA_LOAD_TEMPER; break; case PRINTERSTATE_DESP_MATERIAL_ABS: $temp_ls = PRINTERSTATE_VALUE_FILAMENT_ABS_LOAD_TEMPER; break; case PRINTERSTATE_DESP_MATERIAL_PVA: $temp_ls = PRINTERSTATE_VALUE_FILAMENT_PVA_LOAD_TEMPER; break; default: PrinterLog_logError('unknown filament type in priming', __FILE__, __LINE__); // return ERROR_INTERNAL; $temp_ls = SLICER_VALUE_DEFAULT_FIRST_TEMPER; break; } $temp_l = $temp_ls; } else { $temp_l = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER]; $temp_ls = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1]; } } else { if ($cr == ERROR_MISS_LEFT_CART) { $CI->load->helper('slicer'); $temp_l = SLICER_VALUE_DEFAULT_TEMPER; $temp_ls = SLICER_VALUE_DEFAULT_FIRST_TEMPER; } } } } if ($temp_l * $temp_ls == 0) { // we have at least one value not initialised to call change temper program return $cr == ERROR_OK ? ERROR_INTERNAL : $cr; } else { $array_temper['l'] = $temp_l; } } $command = $CI->config->item('gcdaemon') . PRINTER_PRM_TEMPER_R_F . $temp_rs . PRINTER_PRM_TEMPER_R_N . $temp_r . PRINTER_PRM_TEMPER_L_F . $temp_ls . PRINTER_PRM_TEMPER_L_N . $temp_l . PRINTER_PRM_TEMPER_BED . $temp_b . PRINTER_PRM_FILE . $gcode_path . ' > ' . $gcode_path . '.new'; // debug message for test $CI->load->helper('printerlog'); PrinterLog_logDebug('change temperature: ' . $command, __FILE__, __LINE__); @unlink($gcode_path . '.new'); // delete old file exec($command, $output, $cr); if ($cr != ERROR_NORMAL_RC_OK) { $CI->load->helper('printerlog'); PrinterLog_logError('change temperature error', __FILE__, __LINE__); return ERROR_INTERNAL; } $gcode_path = $gcode_path . '.new'; return ERROR_OK; }
function PrinterState_prepareStatsSliceLabel($end_slice = FALSE) { $stats_info = array(); $preset_id = NULL; $model_filename = array(); $array_slice = array(); $array_check = array('l' => array(PRINTERLOG_STATS_FILA_TYPE_L, PRINTERLOG_STATS_FILA_COLOR_L, PRINTERLOG_STATS_FILA_USED_L), 'r' => array(PRINTERLOG_STATS_FILA_TYPE_R, PRINTERLOG_STATS_FILA_COLOR_R, PRINTERLOG_STATS_FILA_USED_R)); $CI =& get_instance(); $CI->load->helper(array('slicer', 'zimapi')); // remove unused filament if ($end_slice == TRUE) { if (ERROR_OK == PrinterState_getSlicedJson($array_slice)) { foreach (array('r', 'l') as $abb_filament) { if (!isset($array_slice[$abb_filament])) { unset($array_check[$abb_filament]); } } } } // filament info foreach ($array_check as $abb_filament => $assign_key) { $json_cartridge = array(); if (ERROR_OK == PrinterState_getCartridgeAsArray($json_cartridge, $abb_filament)) { $stats_info[$assign_key[0]] = $json_cartridge[PRINTERSTATE_TITLE_MATERIAL]; $stats_info[$assign_key[1]] = $json_cartridge[PRINTERSTATE_TITLE_COLOR]; if ($end_slice == TRUE) { $stats_info[$assign_key[2]] = $array_slice[$abb_filament][PRINTERSTATE_TITLE_NEED_L]; } } } // model name if (ERROR_OK == Slicer_getModelFile(0, $model_filename, TRUE)) { $model_displayname = NULL; foreach ($model_filename as $model_basename) { if (strlen($model_displayname)) { $model_displayname .= ' + ' . $model_basename; } else { $model_displayname = $model_basename; } } if (strlen($model_displayname)) { $stats_info[PRINTERLOG_STATS_MODEL] = $model_displayname; } } // preset name if (ZimAPI_getPreset($preset_id)) { $array_json = array(); if (ERROR_OK == ZimAPI_getPresetInfoAsArray($preset_id, $array_json)) { $stats_info[PRINTERLOG_STATS_PRESET] = $array_json[ZIMAPI_TITLE_PRESET_NAME]; } } return $stats_info; }