public function get() { $parameter = NULL; $cr = 0; $display = NULL; $api_prm = NULL; $this->load->helper(array('printerstate', 'zimapi')); $parameter = $this->input->get('p'); //return false if missing if ($parameter) { switch ($parameter) { case PRINTERSTATE_PRM_EXTRUDER: $cr = PrinterState_getExtruder($display); //$abb_extruder break; case PRINTERSTATE_PRM_TEMPER: // check which temperature we want $has_e = $this->input->get('e'); $has_h = $this->input->get('h'); $has_v = $this->input->get('v'); if ($has_e === FALSE && $has_h === FALSE) { $cr = ERROR_MISS_PRM; } else { if (!($has_e === FALSE) && !($has_h === FALSE)) { $cr = ERROR_WRONG_PRM; } else { if (!($has_e === FALSE) && !($has_v === FALSE)) { // refuse getting data not existed for mono extruder if ($has_v == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { if (in_array($has_v, array('l', 'r'))) { // $tmp_array = PrinterState_getExtruderTemperaturesAsArray(); // $cr = ERROR_OK; // $display = ($has_v == 'l') // ? $tmp_array[PRINTERSTATE_LEFT_EXTRUD] // : $tmp_array[PRINTERSTATE_RIGHT_EXTRUD]; $cr = PrinterState_getTemperature($display, 'e', $has_v); } else { $cr = ERROR_WRONG_PRM; } } } else { $api_prm = $has_e === FALSE ? 'h' : 'e'; $cr = PrinterState_getTemperature($display, $api_prm); } } } break; case PRINTERSTATE_PRM_CARTRIDGE: $api_prm = $this->input->get('v'); // refuse getting data not existed for mono extruder if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { $cr = PrinterState_getCartridge($display, $api_prm); } break; case PRINTERSTATE_PRM_INFO: //TODO need add SSO account $cr = ERROR_OK; $display = PrinterState_getInfo(); break; case 'render': $this->_return_under_construction(); return; break; case PRINTERSTATE_PRM_ACCELERATION: $cr = PrinterState_getAcceleration($display); break; case PRINTERSTATE_PRM_SPEED_MOVE: case PRINTERSTATE_PRM_SPEED_EXTRUDE: $cr = PrinterState_getSpeed($display); break; case PRINTERSTATE_PRM_COLDEXTRUSION: $value = NULL; $cr = PrinterState_getColdExtrusion($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_FILAMENT: $value = NULL; $api_prm = $this->input->get('v'); // refuse getting data not existed for mono extruder if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { if ($api_prm) { $cr = ERROR_OK; $value = PrinterState_getFilamentStatus($api_prm); if ($value == TRUE) { $display = 'true'; } else { $display = 'false'; } } else { $cr = ERROR_MISS_PRM; } } break; case PRINTERSTATE_PRM_ENDSTOP: $status = NULL; $abb_endstop = $this->input->get('axis'); $cr = PrinterState_getEndstop($abb_endstop, $status); if ($cr == ERROR_OK) { $display = $status ? 'on' : 'off'; } break; case PRINTERSTATE_PRM_STRIPLED: $value = NULL; $cr = PrinterState_getStripLedStatus($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_HEADLED: $value = NULL; $cr = PrinterState_getTopLedStatus($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_OFFSET: $value = NULL; $axis = $this->input->get('axis'); if ($axis) { $cr = PrinterState_getOffset($axis, $value); if ($cr == ERROR_OK) { $display = $value; } } else { $cr = ERROR_MISS_PRM; } break; case PRINTERSTATE_PRM_POSITION: $cr = PrinterState_getPosition($display); break; case ZIMAPI_PRM_CAPTURE: $path_capture = ''; $password = $this->input->get('password'); if (!ZimAPI_checkCameraPassword($password)) { $cr = ERROR_WRONG_PWD; break; } $this->load->helper('file'); if (ZimAPI_cameraCapture($path_capture)) { $this->output->set_content_type(get_mime_by_extension($path_capture))->set_output(@file_get_contents($path_capture)); return; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_VIDEO_MODE: if (ZimAPI_checkCamera($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_PRESET: if (ZimAPI_getPreset($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_UPGRADE: if (ZimAPI_getUpgradeMode($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } if ($display != 'off') { $display = 'on'; } break; case ZIMAPI_PRM_PROXY: if (ZimAPI_getTromboning()) { $display = 'on'; } else { $display = 'off'; } $cr = ERROR_OK; break; case ZIMAPI_PRM_SSH: $status_current = NULL; if (ZimAPI_getSSH($status_current)) { $cr = ERROR_OK; if ($status_current) { $display = 'on'; } else { $display = 'off'; } } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_STATS: if (ZimAPI_getStatistic()) { $display = 'on'; } else { $display = 'off'; } $cr = ERROR_OK; break; default: $cr = ERROR_WRONG_PRM; break; } } else { $cr = ERROR_MISS_PRM; } if ($cr != ERROR_OK) { $display = $cr . " " . t(MyERRMSG($cr)); } $this->output->set_status_header($cr, $display); // http_response_code($cr); $this->output->set_content_type(RETURN_CONTENT_TYPE); // echo $display; $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); return; }
public function timelapse() { $template_data = array(); $array_info = array(); $status_current = NULL; $array_status = array(); $restart_url = NULL; $model_displayname = NULL; $show_storegcode = FALSE; $this->load->library('parser'); $this->load->helper('zimapi'); $this->lang->load('printdetail', $this->config->item('language')); if (CoreStatus_checkInIdle($status_current, $array_status) && array_key_exists(CORESTATUS_TITLE_PRINTMODEL, $array_status)) { $model_id = NULL; $abb_cartridge = NULL; $model_temper = NULL; if (strpos($array_status[CORESTATUS_TITLE_PRINTMODEL], CORESTATUS_VALUE_MID_PREFIXGCODE) === 0) { // gcode library model $gcode_info = array(); $gid = (int) substr($array_status[CORESTATUS_TITLE_PRINTMODEL], strlen(CORESTATUS_VALUE_MID_PREFIXGCODE)); $model_displayname = t('timelapse_info_modelname_unknown'); $this->load->helper('printerstoring'); $gcode_info = PrinterStoring_getInfo("gcode", $gid); if (!is_null($gcode_info) && array_key_exists("name", $gcode_info)) { $model_displayname = $gcode_info["name"]; } $array_info[] = array('title' => t('timelapse_info_modelname_title'), 'value' => $model_displayname); $restart_url = '/printdetail/printgcode?id=' . $gid; } else { switch ($array_status[CORESTATUS_TITLE_PRINTMODEL]) { case CORESTATUS_VALUE_MID_SLICE: $preset_id = NULL; $model_filename = array(); $preset_name = t('timelapse_info_presetname_unknown'); $this->load->helper('slicer'); if (ERROR_OK == Slicer_getModelFile(0, $model_filename, TRUE)) { foreach ($model_filename as $model_basename) { if (strlen($model_displayname)) { $model_displayname .= ' + ' . $model_basename; } else { $model_displayname = $model_basename; } } } else { $model_displayname = t('timelapse_info_modelname_slice'); } $array_info[] = array('title' => t('timelapse_info_modelname_title'), 'value' => $model_displayname); if (ZimAPI_getPreset($preset_id)) { $array_json = array(); if (ERROR_OK == ZimAPI_getPresetInfoAsArray($preset_id, $array_json)) { $preset_name = $array_json[ZIMAPI_TITLE_PRESET_NAME]; } } $array_info[] = array('title' => t('timelapse_info_presetname_title'), 'value' => $preset_name); $restart_url = '/printdetail/printslice'; $show_storegcode = TRUE; break; case CORESTATUS_VALUE_MID_PRIME_R: $abb_cartridge = 'r'; // treat priming in the same way // treat priming in the same way case CORESTATUS_VALUE_MID_PRIME_L: // never reach here normally (no timelapse for priming in principe, just for safety) $array_info[] = array('title' => t('timelapse_info_modelname_title'), 'value' => t('timelapse_info_modelname_prime')); if (is_null($abb_cartridge)) { $abb_cartridge = 'l'; } $restart_url = '/printdetail/printprime?r&v=' . $abb_cartridge; //TODO we lose callback info here break; case CORESTATUS_VALUE_MID_CALIBRATION: // never reach here normally (no timelapse for calibration model, just for safety) $this->load->helper('printlist'); $model_id = ModelList_codeModelHash(PRINTLIST_MODEL_CALIBRATION); $restart_url = '/printmodel/detail?id=calibration'; // treat as a normal pre-sliced model // treat as a normal pre-sliced model default: // treat as pre-sliced model $model_data = array(); $model_displayname = t('timelapse_info_modelname_unknown'); if (is_null($model_id)) { $this->load->helper('printlist'); $model_id = $array_status[CORESTATUS_TITLE_PRINTMODEL]; } if (ERROR_OK == ModelList__getDetailAsArray($model_id, $model_data, TRUE)) { $model_displayname = $model_data[PRINTLIST_TITLE_NAME]; } $array_info[] = array('title' => t('timelapse_info_modelname_title'), 'value' => $model_displayname); if (is_null($restart_url)) { $restart_url = '/printdetail/printmodel?id=' . $model_id; } break; } } if (array_key_exists(CORESTATUS_TITLE_ELAPSED_TIME, $array_status)) { $display_time = NULL; $this->load->helper('timedisplay'); $display_time = TimeDisplay__convertsecond($array_status[CORESTATUS_TITLE_ELAPSED_TIME], ''); $array_info[] = array('title' => t('timelapse_info_elapsedtime_title'), 'value' => $display_time); } if ($this->config->item('nb_extruder') < 2 && array_key_exists(CORESTATUS_TITLE_P_TEMPER_R, $array_status) && $array_status[CORESTATUS_TITLE_P_TEMPER_R] > 0) { $model_temper = t('timelapse_info_temperature_value_mono', array($array_status[CORESTATUS_TITLE_P_TEMPER_R])); } else { if (array_key_exists(CORESTATUS_TITLE_P_TEMPER_L, $array_status) && $array_status[CORESTATUS_TITLE_P_TEMPER_L] > 0 && array_key_exists(CORESTATUS_TITLE_P_TEMPER_R, $array_status) && $array_status[CORESTATUS_TITLE_P_TEMPER_R] > 0) { $model_temper = t('timelapse_info_temperature_values', array($array_status[CORESTATUS_TITLE_P_TEMPER_L], $array_status[CORESTATUS_TITLE_P_TEMPER_R])); } else { if (array_key_exists(CORESTATUS_TITLE_P_TEMPER_R, $array_status) && $array_status[CORESTATUS_TITLE_P_TEMPER_R] > 0) { $model_temper = t('timelapse_info_temperature_value_r', array($array_status[CORESTATUS_TITLE_P_TEMPER_R])); } else { if (array_key_exists(CORESTATUS_TITLE_P_TEMPER_L, $array_status) && $array_status[CORESTATUS_TITLE_P_TEMPER_L] > 0) { $model_temper = t('timelapse_info_temperature_value_l', array($array_status[CORESTATUS_TITLE_P_TEMPER_L])); } } } } if ($model_temper) { if (array_key_exists(CORESTATUS_TITLE_P_TEMPER_B, $array_status) && $array_status[CORESTATUS_TITLE_P_TEMPER_B] > 0) { $model_temper .= t('timelapse_info_extra_temperature_value_b', array($array_status[CORESTATUS_TITLE_P_TEMPER_B])); } $array_info[] = array('title' => t('timelapse_info_temperature_title'), 'value' => $model_temper); } } else { $this->load->helper('printerlog'); PrinterLog_logError('unintended status detected in timelapse page: ' . $status_current, __FILE__, __LINE__); $this->output->set_header('Location: /'); return; } // parse the main body $template_data = array('internet_ok' => @file_get_contents("https://sso.zeepro.com/login.ashx") === FALSE ? 'false' : 'true', 'loading_player' => t('timelapse_info'), 'finish_info' => t('Congratulation, your printing is complete!'), 'home_button' => t('Home'), 'home_popup_text' => t('home_popup_text'), 'yes' => t('Yes'), 'no' => t('No'), 'video_error' => t('video_error'), 'timelapse_title' => t('timelapse_title'), 'send_email_button' => t('send_email_button'), 'send_yt_button' => t('send_yt_button'), 'send_fb_button' => t('send_fb_button'), 'send_email_hint' => t('send_email_hint'), 'send_email_action' => t('send_email_action'), 'send_email_error' => t('send_email_error'), 'send_email_wrong' => t('send_email_wrong'), 'send_email_multi' => t('send_email_multi'), 'video_url' => '/tmp/' . ZIMAPI_FILENAME_TIMELAPSE . '?_=' . time(), 'timelapse_info_title' => t('timelapse_info_title'), 'timelapse_info' => $array_info, 'again_button' => t('Print again'), 'restart_url' => $restart_url ? $restart_url : '/', 'send_email_modelname' => $model_displayname, 'display_storegocde' => $show_storegcode ? 'true' : 'false', 'storegcode_checkbox' => t('storegcode_info'), 'storegcode_hint' => t('storegcode_name'), 'storegcode_err_cfm' => t('storegcode_err_cfm'), 'storegcode_title' => t('storegcode_title')); // parse all page $this->_parseBaseTemplate(t('ZeePro Personal Printer 21 - Printing details'), $this->parser->parse('printdetail/timelapse', $template_data, TRUE)); return; }
function PrinterStoring_storeGcode($name) { global $CFG; $CI =& get_instance(); $gcode_library_path = $CFG->config['gcode_library']; $data_json = NULL; $array_length = array(); $array_material = array(); $nb_models = 0; $preset_id = NULL; // check if library folder exist if (@is_dir($gcode_library_path) == false) { $CI->load->helper('printerlog'); PrinterLog_logError('gcode library folder does not exist', __FILE__, __LINE__); return ERROR_INTERNAL; } // get last unused ID if (($model_id = PrinterStoring__getLastId($gcode_library_path)) < 0) { $CI->load->helper('printerlog'); PrinterLog_logError('could not get the last id from gcode library', __FILE__, __LINE__); return ERROR_INTERNAL; } // create model folder $model_folder = $gcode_library_path . sprintf('%06d', $model_id) . '/'; if (@mkdir($model_folder) == false) { $CI->load->helper('printerlog'); PrinterLog_logError('could not create the model folder', __FILE__, __LINE__); return ERROR_DISK_FULL; } // get length and material info $CI->load->helper('printerstate'); if (ERROR_OK != PrinterState_getSlicedJson($data_json)) { return ERROR_INTERNAL; } foreach (array('r', 'l') as $abb_cartridge) { if (array_key_exists($abb_cartridge, $data_json) && array_key_exists(PRINTERSTATE_TITLE_NEED_L, $data_json[$abb_cartridge]) && $data_json[$abb_cartridge][PRINTERSTATE_TITLE_NEED_L] > 0) { $array_length[$abb_cartridge] = $data_json[$abb_cartridge][PRINTERSTATE_TITLE_NEED_L]; $array_material[$abb_cartridge] = $data_json[$abb_cartridge][PRINTERSTATE_TITLE_MATERIAL]; ++$nb_models; } else { $array_length[$abb_cartridge] = 0; $array_material[$abb_cartridge] = NULL; } } // get preset id $CI->load->helper('zimapi'); if (!ZimAPI_getPreset($preset_id)) { $preset_id = NULL; } // create info file $info_file = $model_folder . PRINTERSTORING_FILE_INFO_JSON; $info = array("id" => $model_id, "name" => $name, PRINTERSTORING_TITLE_CREATE_TIME => time(), PRINTERSTORING_TITLE_LENG_R => $array_length['r'], PRINTERSTORING_TITLE_LENG_L => $array_length['l'], PRINTERSTORING_TITLE_MATER_R => $array_material['r'], PRINTERSTORING_TITLE_MATER_L => $array_material['l'], PRINTERSTORING_TITLE_PRESET_ID => $preset_id); if (!PrinterStoring__createInfoFile($info_file, $info)) { PrinterStoring_deleteGcode($model_id); $CI->load->helper('printerlog'); PrinterLog_logError('could not create the model info file', __FILE__, __LINE__); return ERROR_DISK_FULL; } // store captured image $CI->load->helper('zimapi'); $image_path = ZIMAPI_FILEPATH_CAPTURE; if (file_exists($image_path) === false) { $CI->load->helper('printerlog'); PrinterLog_logError('could not find the captured image', __FILE__, __LINE__); return ERROR_IMG_NOTFOUND; } elseif (!copy($image_path, $model_folder . PRINTERSTORING_FILE_IMG_JPG)) { $CI->load->helper('printerlog'); PrinterLog_logError('could not store the captured image', __FILE__, __LINE__); return ERROR_DISK_FULL; } // store file(s) $CI->load->helper('slicer'); $file_path = $CI->config->item('temp') . SLICER_FILE_MODEL; if (@file_exists($file_path) == false) { PrinterStoring_deleteGcode($model_id); $CI->load->helper('printerlog'); PrinterLog_logError('could not find the gcode model', __FILE__, __LINE__); return ERROR_GCODE_NOTFOUND; } elseif (!PrinterStoring__storeModelFile($model_folder . PRINTERSTORING_FILE_GCODE_BZ2, $file_path)) { PrinterStoring_deleteGcode($model_id); $CI->load->helper('printerlog'); PrinterLog_logError('disk full, could not store the gcode file', __FILE__, __LINE__); return ERROR_DISK_FULL; } // check disk free space if (!PrinterStoring__checkFreeSpace()) { PrinterStoring_deleteGcode($model_id); $CI->load->helper('printerlog'); PrinterLog_logError('overpass user library minimum free space limit', __FILE__, __LINE__); return ERROR_DISK_FULL; } // stats info $CI->load->helper('printerlog'); PrinterLog_statsLibraryGcode(PRINTERLOG_STATS_LABEL_LOAD, $nb_models); return ERROR_OK; }
function slice_model_ajax() { $cr = 0; $array_cartridge = array(); $display = NULL; $id_preset = $this->input->get('id'); // $density = $this->input->get('density'); // $skirt = $this->input->get('skirt'); // $raft = $this->input->get('raft'); // $support = $this->input->get('support'); $heat_bed = $this->config->item('heat_bed') && (int) $this->input->get('hb') > 0; $array_setting = array(); $custom_change = FALSE; $this->load->helper('slicer'); // set and load preset into slicer if ($id_preset) { if ($id_preset == 'previous') { $cr = ZimAPI_getPreset($id_preset); } else { $cr = ZimAPI_setPreset($id_preset); } } else { $cr = ERROR_MISS_PRM; } if ($cr == ERROR_OK) { $cr = Slicer_reloadPreset(); } // load 4 extra parameters //TODO finish me (syntax in comment need be changed to function) // if ($density !== FALSE) { // if (FALSE == strpos('%', $density)) { // $density = (float)$density; // if ($density <= 0 || $density >= 1) { // $cr = ERROR_MISS_PRM; // break; // } // } // $array_setting['fill_density'] = $density; // } // if ($skirt !== FALSE) { // $array_setting['skirts'] = ((int)$skirt == 1) ? 1 : 0; // } // if ($raft !== FALSE) { // $array_setting['raft_layers'] = ((int)$raft == 1) ? 1 : 0; // } // if ($support !== FALSE) { // $array_setting['support_material'] = ((int)$support == 1) ? 1 : 0; // } // if (count($array_setting) == 0) { // $cr = ERROR_MISS_PRM; // } // else if ($cr == ERROR_OK) { // $cr = Slicer_changeParameter($array_setting); // } // check platform and filament present (do not check filament quantity) if ($cr == ERROR_OK) { $cr = Slicer_checkPlatformColor($array_cartridge, $custom_change); } if ($cr == ERROR_OK) { $cr = Slicer_changeTemperByCartridge($array_cartridge, $heat_bed); } // start slice command after checking filament if ($cr == ERROR_OK) { // we prefer to slice remotely except modified AMF if ($this->config->item('simulator')) { $custom_change = TRUE; // force local slicing for simulator } $cr = Slicer_slice(!$custom_change); } $display = $cr . " " . t(MyERRMSG($cr)); $this->output->set_status_header($cr, $display); $this->output->set_content_type('txt_u'); $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); //optional return; }
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; }