Exemplo n.º 1
0
 public function index()
 {
     $template_data = array();
     $ret_val = 0;
     $this->load->library('parser');
     $this->lang->load('manage', $this->config->item('language'));
     $this->lang->load('printerstate/index', $this->config->item('language'));
     $this->load->helper(array('zimapi', 'printerstate'));
     if (!ZimAPI_cameraOn(ZIMAPI_PRM_CAMERA_PRINTSTART)) {
         $this->load->helper('printerlog');
         PrinterLog_logError('can not set camera', __FILE__, __LINE__);
     }
     $ret_val = PrinterState_getStripLedStatus($status_strip);
     if ($ret_val != ERROR_OK) {
         $status_strip = FALSE;
     }
     $ret_val = PrinterState_getTopLedStatus($status_head);
     if ($ret_val != ERROR_OK) {
         $status_head = FALSE;
     }
     //parse the main body
     $template_data = array('back' => t('back'), 'what' => t('what'), 'loading_player' => t('loading_player'), 'platform_view_title' => t('platform_view_title'), 'reset' => t('reset_title'), 'home_text' => t('home_text'), 'head' => t('head_title'), 'head_text' => t('head_text'), 'platform' => t('platform_title'), 'platform_text' => t('platform_text'), 'filament' => t('filament_title'), 'filament_text' => t('filament_text'), 'manage_left' => t('manage_left'), 'manage_right' => t('manage_right'), 'bed_title' => t('bed_title'), 'bed_text' => t('bed_text'), 'video_error' => t('video_error'), 'video_url' => $this->config->item('video_url'), 'reboot' => t('reboot'), 'shutdown' => t('shutdown'), 'lighting_title' => t('lighting_title'), 'strip_led' => t('strip_led'), 'head_led' => t('head_led'), 'led_on' => t('led_on'), 'led_off' => t('led_off'), 'left' => t('left'), 'right' => t('right'), 'strip_led_on' => $status_strip == TRUE ? "selected=selected" : NULL, 'head_led_on' => $status_head == TRUE ? "selected=selected" : NULL, 'bicolor' => $this->config->item('nb_extruder') >= 2 ? 'true' : 'false');
     // parse all page
     $this->_parseBaseTemplate(t('manage_index_pagetitle'), $this->parser->parse('manage/index', $template_data, TRUE), '<link rel="stylesheet" href="/assets/jquery-mobile-fluid960.min.css">');
     return;
 }
Exemplo n.º 2
0
 public function index()
 {
     $display = '';
     $this->load->helper('corestatus');
     if (!CoreStatus_initialFile()) {
         $this->load->helper('printerlog');
         PrinterLog_logError('status files initialisation error when MY_Controller started', __FILE__, __LINE__);
         // let request failed
         $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
         header($protocol . ' 500');
         header('Content-type: text/plain; charset=UTF-8');
         echo 'file initialisation error';
         exit;
     }
     // 		$this->output->set_content_type('text/plain; charset=UTF-8');
     $this->output->set_content_type('txt_u');
     $display .= 'Log level: ' . $this->config->item('log_level') . "\n";
     if (file_exists($this->config->item('log_file'))) {
         $array_log = @file($this->config->item('log_file'));
         foreach ($array_log as $line) {
             $display .= $line;
         }
     } else {
         $display .= "no log file\n";
     }
     $this->load->library('parser');
     $this->parser->parse('plaintxt', array('display' => $display));
     // 		$this->output->set_header('Location: /test_log/debug');
     return;
 }
Exemplo n.º 3
0
 public function wizard_confirm($mode = NULL)
 {
     $body_page = NULL;
     $hint_txt = NULL;
     $hint_title = NULL;
     $hostname = NULL;
     $template_data = array();
     $this->load->library('parser');
     $this->load->helper(array('corestatus', 'zimapi'));
     $this->lang->load('activation/activation_wizard', $this->config->item('language'));
     if (!CoreStatus_finishActivation()) {
         $this->load->helper('printerlog');
         PrinterLog_LogError('can not finish need activation mode', __FILE__, __LINE__);
     }
     if (ERROR_OK != ZimAPI_getHostname($hostname)) {
         $this->load->helper('printerlog');
         PrinterLog_logError('can not get hostname', __FILE__, __LINE__);
     }
     switch ($mode) {
         case NULL:
             $hint_txt = t('wizard_success_hint', array($hostname, $hostname, $hostname));
             $hint_title = t('hint_title_success');
             // send email
             $email = $this->session->userdata('email');
             @file_get_contents('https://sso.zeepro.com/sendtipsmail.ashx?email=' . $email);
             break;
         case 'fail':
             $hint_txt = t('wizard_fail_hint', array($hostname, $hostname));
             $hint_title = t('hint_title');
             break;
         case 'skip':
             $this->output->set_header("Location: /menu_home");
             return;
         default:
             if ($mode != 'skip') {
                 $this->load->helper('printerlog');
                 PrinterLog_LogError('unknown mode for wizard, mode: ' . $mode, __FILE__, __LINE__);
             }
             $hint_txt = t('wizard_skip_hint', array($hostname, $hostname));
             break;
     }
     $template_data = array('hint_title' => $hint_title, 'hint_txt' => $hint_txt, 'button_ok' => t('button_ok'));
     $body_page = $this->parser->parse('template/activation/activation_wizard', $template_data, TRUE);
     // parse all page
     $template_data = array('lang' => $this->config->item('language_abbr'), 'headers' => '<title>' . t('ZeePro Personal Printer 21 - Activation') . '</title>', 'contents' => $body_page);
     $this->parser->parse('basetemplate', $template_data);
     return;
 }
Exemplo n.º 4
0
 public function __construct()
 {
     parent::__construct();
     $this->load->helper('corestatus');
     if (!CoreStatus_initialFile()) {
         $this->load->helper('printerlog');
         PrinterLog_logError('status files initialisation error when MY_Controller started', __FILE__, __LINE__);
         // let request failed
         $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
         header($protocol . ' 500');
         header('Content-type: text/plain; charset=UTF-8');
         echo 'file initialisation error';
         exit;
     }
     return;
 }
Exemplo n.º 5
0
 public function index()
 {
     $this->load->helper('printerlog');
     if ($this->input->server('REQUEST_METHOD') == 'POST') {
         $token_post = $this->input->post('token');
         $token_json = json_decode($token_post, TRUE);
         PrinterLog_logDebug('remote token: ' . $token_post);
         if (is_array($token_json) && isset($token_json['token'])) {
             // new token system
             $this->input->set_cookie('auth', $token_json['token'], 0);
             $this->input->set_cookie('token_system', 'new', 1800);
             // 30 mins
             if (isset($token_json['redirect']) && is_array($token_json['redirect']) && isset($token_json['redirect']['url'])) {
                 $redirect_url = $token_json['redirect']['url'] . '?from=remote';
                 // treat get parameter
                 if (isset($token_json['redirect']['prm']) && is_array($token_json['redirect']['prm'])) {
                     foreach ($token_json['redirect']['prm'] as $prm_key => $prm_val) {
                         $redirect_url .= '&' . $prm_key . '=' . $prm_val;
                     }
                 }
                 // treat cookie parameter
                 if (isset($token_json['redirect']['cookie']) && is_array($token_json['redirect']['cookie'])) {
                     $array_cookie = array();
                     foreach ($token_json['redirect']['cookie'] as $cookie_key => $cookie_value) {
                         $array_cookie[$cookie_key] = $cookie_value;
                     }
                     $this->input->set_cookie('redirectData', json_encode($array_cookie), 60);
                     // 1 min
                 }
                 // filter outside redirection
                 if ($redirect_url[0] != '/') {
                     $redirect_url = '/' . $redirect_url;
                 }
                 $this->output->set_header('Location: ' . $redirect_url);
             }
         } else {
             // old token system
             $this->input->set_cookie('auth', $token_post, 0);
             $this->input->set_cookie('token_system', 'old', 1800);
             // 30 mins
             $this->output->set_header('Location: /');
         }
     } else {
         PrinterLog_logError("SetCookie: method != POST");
         echo '<script>alert("denied")</script>';
     }
 }
Exemplo n.º 6
0
 public function index()
 {
     $template_data = array();
     $need_update = FALSE;
     $this->load->library('parser');
     $this->lang->load('menu_home', $this->config->item('language'));
     $this->load->helper('zimapi');
     if (!ZimAPI_cameraOff()) {
         $this->load->helper('printerlog');
         PrinterLog_logError('can not turn off camera', __FILE__, __LINE__);
     }
     $need_update = !(ZimAPI_getVersion(TRUE) == ZimAPI_getVersion(FALSE));
     //parse the main body
     $template_data = array('update_available' => $need_update ? t('update_available') : "", 'update_hint' => t('update_available'), 'my_library' => t('my_library'), 'my_zim_shop' => t('my_zim_shop'), 'menu_printlist' => t('Quick print'), 'menu_printerstate' => t('Configuration'), 'manage' => t('manage'), 'upload' => t('upload'), 'about' => t('about'), 'library_visible' => $this->config->item('use_sdcard') == TRUE ? 'block' : 'none');
     // parse all page
     $this->_parseBaseTemplate(t('ZeePro Personal Printer 21 - Home'), $this->parser->parse('menu_home', $template_data, TRUE));
     return;
 }
Exemplo n.º 7
0
function Slicer__getColorString($color, &$color_string)
{
    $array_color = array();
    if (strlen($color) != 7) {
        $CI =& get_instance();
        $CI->load->helper('printerlog');
        PrinterLog_logError('color code error', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    $offset = 5;
    do {
        $array_color[] = hexdec(substr($color, $offset, 2)) / 255;
        $offset = $offset - 2;
    } while ($offset >= 1);
    $color_string = json_encode($array_color);
    return ERROR_OK;
}
Exemplo n.º 8
0
function CoreStatus__checkCallURI($array_URI)
{
    $CI =& get_instance();
    if (array_key_exists($CI->router->uri->uri_string, $array_URI)) {
        if (is_null($array_URI[$CI->router->uri->uri_string])) {
            return TRUE;
        } else {
            if (!is_array($array_URI[$CI->router->uri->uri_string])) {
                $CI->load->helper('printerlog');
                PrinterLog_logError('check call URI internal API error', __FILE__, __LINE__);
                return FALSE;
            } else {
                foreach ($array_URI[$CI->router->uri->uri_string] as $key => $value) {
                    $real_value = $CI->input->get($key);
                    if (is_array($value) && in_array($real_value, $value)) {
                        continue;
                        // compare with a data array
                        // 					return TRUE;
                    } else {
                        if ($real_value == $value) {
                            continue;
                            // compare with an alone data
                            // 					return TRUE;
                        } else {
                            return FALSE;
                            break;
                            // never reach here
                            // 					continue;
                        }
                    }
                }
            }
        }
    } else {
        return FALSE;
    }
    return TRUE;
    // 	return FALSE;
}
Exemplo n.º 9
0
 public function recovery_ajax()
 {
     //TODO finish me for recovery
     $template_data = array();
     $ret_val = 0;
     $status_current = NULL;
     $data_status = array();
     $this->load->helper('corestatus');
     $this->load->library('parser');
     $this->lang->load('printdetail', $this->config->item('language'));
     $template_data = array('wait_info' => t('wait_hint_recovery'));
     $ret_val = CoreStatus_checkInIdle($status_current, $data_status);
     if ($ret_val == TRUE) {
         // log recovery finish
         $this->load->helper('printerlog');
         PrinterLog_logMessage('recovery status finish', __FILE__, __LINE__);
         $this->output->set_status_header(202);
         return;
     } else {
         if ($status_current == CORESTATUS_VALUE_RECOVERY) {
             if ($data_status[CORESTATUS_TITLE_SUBSTATUS] == CORESTATUS_VALUE_PRINT) {
                 $template_data['wait_info'] = t('wait_hint_recovery_printing');
             } else {
                 $template_data['wait_info'] = t('wait_hint_recovery_unknown');
                 $this->load->helper('printerlog');
                 PrinterLog_logError('unknown substatus value in recovery ' . $data_status[CORESTATUS_TITLE_SUBSTATUS], __FILE__, __LINE__);
             }
         } else {
             $this->output->set_status_header(403);
             $this->load->helper('printerlog');
             PrinterLog_logError('call recovery status check when not in recovery', __FILE__, __LINE__);
             return;
         }
     }
     // parse the ajax part
     $this->parser->parse('printdetail/cancel_ajax', $template_data);
     // we can use the same view for recovery
     $this->output->set_content_type('text/plain; charset=UTF-8');
     return;
 }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
 public function getrenderv1()
 {
     $cr = 0;
     $path_model = NULL;
     $status_array = array();
     $color_array = array('r' => NULL, 'l' => NULL);
     $this->load->helper(array('printerstate', 'slicer'));
     // 		$status_array = PrinterState_checkStatusAsArray();
     // 		// check if we are in sliced status, assign colors if so
     // 		if ($status_array[PRINTERSTATE_TITLE_STATUS] == CORESTATUS_VALUE_SLICED
     // 				&& array_key_exists(PRINTERSTATE_TITLE_EXTEND_PRM, $status_array)) {
     // 			// check all extruders
     // 			foreach (array('r' => PRINTERSTATE_TITLE_EXT_LENG_R, 'l' => PRINTERSTATE_TITLE_EXT_LENG_L)
     // 					as $abb_cartridge => $status_length) {
     // 				// check if we use selected extruder
     // 				if (array_key_exists($status_length, $status_array[PRINTERSTATE_TITLE_EXTEND_PRM])) {
     // 					$json_cartridge = array();
     // 					$ret_val = PrinterState_getCartridgeAsArray($json_cartridge, $abb_cartridge);
     // 					// check if cartridge info is all right
     // 					if (in_array($ret_val, array(
     // 							ERROR_OK, ERROR_MISS_LEFT_FILA, ERROR_MISS_RIGT_FILA,
     // 							ERROR_LOW_LEFT_FILA, ERROR_LOW_RIGT_FILA,
     // 					))) {
     // 						$color_array[$abb_cartridge] = $json_cartridge[PRINTERSTATE_TITLE_COLOR];
     // 					}
     // 				}
     // 			}
     // 		}
     // check existed file for time-saving
     foreach (array(SLICER_FILE_PREVIEW_M, SLICER_FILE_PREVIEW_S) as $filename) {
         $path_model = $this->config->item('temp') . $filename;
         if (file_exists($path_model)) {
             $cr = ERROR_OK;
             break;
         }
     }
     if ($cr != ERROR_OK) {
         $cr = Slicer_exportRenderModel($path_model, $color_array['r'], $color_array['l']);
     }
     if ($cr == ERROR_OK) {
         if (file_exists($path_model)) {
             // check mobile device and assign max filesize limit
             @(include_once BASEPATH . '/../assets/mobile_detect.php');
             // check system only if class is well loaded, ignore limit if loading error
             if (class_exists('Mobile_Detect')) {
                 $detect_os = new Mobile_Detect();
                 $size_limit = NULL;
                 if ($detect_os->isiOS()) {
                     $size_limit = 9437184;
                     // 9M
                 } else {
                     if ($detect_os->isAndroidOS()) {
                         $size_limit = 83886080;
                         // 80M
                     }
                 }
                 if ($size_limit && $size_limit < filesize($path_model)) {
                     $cr = ERROR_WRONG_PRM;
                 }
             }
             if ($cr == ERROR_OK) {
                 $fileinfo = pathinfo($path_model);
                 $fileext = NULL;
                 if (is_array($fileinfo) && isset($fileinfo['extension']) && in_array(strtolower($fileinfo['extension']), array('stl', 'amf'))) {
                     $fileext = strtolower($fileinfo['extension']);
                 } else {
                     $fileext = 'bin';
                 }
                 $this->_sendFileContent($path_model, 'rendering.' . $fileext);
                 return;
             }
         } else {
             $this->load->helper('printerlog');
             PrinterLog_logError('export render model function returns ok, but file not found', __FILE__, __LINE__);
             $cr = ERROR_INTERNAL;
         }
     }
     $this->_return_cr($cr);
     return;
 }
Exemplo n.º 12
0
 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;
 }
Exemplo n.º 13
0
function ModelList__listAsArray($set_localization = FALSE)
{
    global $CFG;
    $printlist_basepath = $CFG->config['printlist'];
    $json_data = array();
    $tmp_array = NULL;
    $model_array = directory_map($printlist_basepath, 1);
    // 	sort($model_array); // force make the order of model by alphabet of folder
    foreach ($model_array as $model_name) {
        $model_path = $printlist_basepath . $model_name . '/';
        $nb_pic = 0;
        // jump through the special models
        // 		if ($model_name == PRINTLIST_MODEL_PRIME_L || $model_name == PRINTLIST_MODEL_PRIME_R) {
        if ($model_name[0] == PRINTLIST_MODEL_PREFIX_S) {
            continue;
        }
        // jump through the files (no folder object)
        if (!is_dir($model_path)) {
            continue;
        }
        try {
            $tmp_array = json_read($model_path . PRINTLIST_FILE_JSON, TRUE);
            if ($tmp_array['error']) {
                throw new Exception('read json error');
            }
        } catch (Exception $e) {
            // log internal error
            $CI =& get_instance();
            $CI->load->helper('printerlog');
            PrinterLog_logError('catch exception when getting print model ' . $model_name, __FILE__, __LINE__);
            continue;
            // just jump through the wrong data file
            // 			return json_encode($json_data);
        }
        // 		$tmp_array['json'][PRINTLIST_TITLE_ID] = ModelList_codeModelHash($model_name); //add model id to data array
        //blind picture url
        ModelList__blindUrl($tmp_array['json']);
        if ($set_localization) {
            ModelList__setLocalization($tmp_array['json']);
        }
        $json_data[PRINTLIST_TITLE_MODELS][] = $tmp_array['json'];
        //asign final data
    }
    $json_data[PRINTLIST_TITLE_VERSION] = PRINTLIST_VALUE_VERSION;
    return $json_data;
}
Exemplo n.º 14
0
function PrinterState__updateCartridge(&$code_cartridge, $abb_cartridge)
{
    $CI =& get_instance();
    $file_path = $CI->config->item('base_data') . PRINTERSTATE_FILE_UPDATE_RFID;
    if (file_exists($file_path)) {
        $data_json = array();
        $temp_code = NULL;
        try {
            $CI->load->helper('json');
            $tmp_array = @json_read($file_path, TRUE);
            if ($tmp_array['error']) {
                throw new Exception('read json error');
            } else {
                $data_json = $tmp_array['json'];
            }
        } catch (Exception $e) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('read cartridge update data error', __FILE__, __LINE__);
            return;
            // log error and return
        }
        $temp_code = substr($code_cartridge, 0, 26);
        if (array_key_exists($temp_code, $data_json)) {
            $temp_hex = 0;
            $ret_val = 0;
            $CI->load->helper('printerlog');
            PrinterLog_logDebug('detected a cartridge to update', __FILE__, __LINE__);
            // add date in the end
            $temp_code = $data_json[$temp_code] . substr($code_cartridge, 26, 4);
            // calculate checksum
            for ($i = 0; $i <= 14; $i++) {
                $string_tmp = substr($temp_code, $i * 2, 2);
                $hex_tmp = hexdec($string_tmp);
                $temp_hex = $temp_hex ^ $hex_tmp;
            }
            $temp_hex = dechex($temp_hex);
            if (strlen($temp_hex) == 1) {
                $temp_hex = '0' . $temp_hex;
            }
            $temp_code .= strtoupper($temp_hex);
            $code_cartridge = $temp_code;
            $ret_val = PrinterState_setCartridgeCode($temp_code, $abb_cartridge);
            if ($ret_val != ERROR_OK) {
                // log error and return
                $CI->load->helper('printerlog');
                PrinterLog_logError('write cartridge error when in updating cartridge from database', __FILE__, __LINE__);
            }
        }
    }
    return;
}
Exemplo n.º 15
0
function PrinterLog_setStats($mode)
{
    $mode = strtolower($mode);
    switch ($mode) {
        case 'off':
            try {
                $fp = fopen(PRINTERLOG_STATS_FILEPATH_OFF, 'w');
                if ($fp) {
                    fwrite($fp, 'off');
                    fclose($fp);
                } else {
                    throw new Exception('write file error');
                }
            } catch (Exception $e) {
                PrinterLog_logError('write stats file error', __FILE__, __LINE__);
                return FALSE;
            }
            break;
        case 'on':
            @unlink(PRINTERLOG_STATS_FILEPATH_OFF);
            break;
        default:
            return FALSE;
            break;
    }
    return TRUE;
}
Exemplo n.º 16
0
 public function wait()
 {
     $name = NULL;
     $array_type = array();
     $type = $this->input->post('type');
     $year = (int) $this->input->post('year');
     $month = (int) $this->input->post('month');
     $day = (int) $this->input->post('day');
     $times = (int) $this->input->post('times');
     $side = $this->input->post('side');
     $hint_left = 'Attention, you are trying to write on left side 注意,您正在尝试写入左侧墨盒';
     if ($side != 'l') {
         $side = 'r';
     }
     if ($this->_get_type_array($array_type)) {
         $cr = FALSE;
         $template_data = array();
         $body_page = NULL;
         foreach ($array_type as $ele_type) {
             if ($ele_type['code'] == $type) {
                 $cr = TRUE;
                 $name = $ele_type['name'];
                 break;
             }
         }
         if ($cr) {
             if ($times == 0) {
                 $this->output->set_header('Location: /setupcartridge/input?v=' . $side);
                 return;
             } else {
                 if ($year * $month * $day == 0) {
                     $this->load->helper('printerlog');
                     PrinterLog_logError('user input error', __FILE__, __LINE__);
                     $this->output->set_header('Location: /setupcartridge/input?v=' . $side);
                     return;
                 }
             }
             // all right to wait for writing
             $this->load->library('parser');
             $template_data = array('type' => $type, 'year' => $year, 'month' => $month, 'day' => $day, 'times' => $times, 'name' => $name, 'side' => $side, 'hint' => $side == 'l' ? $hint_left : NULL);
             $body_page = $this->parser->parse('setupcartridge/wait', $template_data, TRUE);
             // parse all page
             $template_data = array('lang' => 'en', 'headers' => '<title>SetupCartridge 设置标签</title>', 'contents' => $body_page);
             $this->parser->parse('basetemplate', $template_data);
         } else {
             $this->load->helper('printerlog');
             PrinterLog_logError('unknown filament type', __FILE__, __LINE__);
             $this->output->set_header('Location: /setupcartridge/input?v=' . $side);
         }
     } else {
         $this->output->set_header('Location: /setupcartridge/input?v=' . $side);
     }
     return;
 }
Exemplo n.º 17
0
function PrinterState_getCartridgeTemper(&$temper_cartridge, $abb_cartridge, $power_off = TRUE)
{
    $last_output = NULL;
    $ret_val = 0;
    $ret_val = PrinterState_getCartridgeCode($last_output, $abb_cartridge, $power_off);
    if ($ret_val != ERROR_OK) {
        return $ret_val;
    }
    // check and treat output data
    if ($last_output) {
        $version_rfid = 0;
        $string_tmp = NULL;
        $hex_checksum = 0;
        $hex_cal = 0;
        $hex_tmp = 0;
        $offset_temp = 0;
        $length_temp = 0;
        $data_json = array();
        // checksum 0 to 14
        for ($i = 0; $i <= 14; $i++) {
            $string_tmp = substr($last_output, $i * 2, 2);
            $hex_tmp = hexdec($string_tmp);
            $hex_cal = $hex_cal ^ $hex_tmp;
        }
        $hex_checksum = hexdec(substr($last_output, 30, 2));
        if ($hex_cal != $hex_checksum) {
            PrinterLog_logError('checksum error, $hex_cal: ' . $hex_cal . ', $hex_data: ' . $hex_checksum, __FILE__, __LINE__);
            return ERROR_INTERNAL;
            // checksum failed
        }
        // magic number
        $string_tmp = substr($last_output, 0, 4);
        switch (hexdec($string_tmp)) {
            case PRINTERSTATE_MAGIC_NUMBER_V1:
                $version_rfid = 1;
                break;
            case PRINTERSTATE_MAGIC_NUMBER_V2:
                $version_rfid = 2;
                break;
            case PRINTERSTATE_MAGIC_NUMBER_V3:
                $version_rfid = 3;
                break;
            case PRINTERSTATE_MAGIC_NUMBER_V4:
                $version_rfid = 4;
                break;
            default:
                PrinterLog_logError('magic number error', __FILE__, __LINE__);
                return ERROR_INTERNAL;
                break;
        }
        if ($version_rfid == 1) {
            $offset_temp = 22;
            $length_temp = 2;
        } else {
            if ($version_rfid == 2) {
                //$version_rfid == 2
                $offset_temp = 24;
                $length_temp = 2;
            } else {
                if ($version_rfid == 3) {
                    //$version_rfid == 3
                    $offset_temp = 24;
                    $length_temp = 1;
                } else {
                    //$version_rfid == 4
                    $offset_temp = 22;
                    $length_temp = 2;
                }
            }
        }
        // normal extrusion temperature
        $string_tmp = substr($last_output, $offset_temp, $length_temp);
        if ($version_rfid == 3) {
            $temper_cartridge = hexdec($string_tmp) + PRINTERSTATE_OFFSET_TEMPER_V2;
        } else {
            $temper_cartridge = hexdec($string_tmp) + PRINTERSTATE_OFFSET_TEMPER;
        }
    } else {
        PrinterLog_logMessage('missing cartridge', __FILE__, __LINE__);
        $temp_cartridge = NULL;
        if ($abb_cartridge == 'l') {
            return ERROR_MISS_LEFT_CART;
        } else {
            return ERROR_MISS_RIGT_CART;
        }
    }
    return ERROR_OK;
}
Exemplo n.º 18
0
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;
}
Exemplo n.º 19
0
 public function __construct()
 {
     global $CFG;
     parent::__construct();
     // 		$this->load->helper(array('corestatus', 'url'));
     $this->load->helper(array('corestatus', 'printerlog'));
     // set proper error handler
     set_error_handler(array($this, 'errorToSSO'));
     // add header to disable cache (IE need these headers)
     $this->output->set_header('Pragma: no-cache');
     $this->output->set_header('Cache-Control: no-cache');
     // initialisation status files
     if (!CoreStatus_initialFile()) {
         $this->load->helper('printerlog');
         PrinterLog_logError('status files initialisation error when MY_Controller started', __FILE__, __LINE__);
         // let request failed
         $this->_exitWithError500('file initialisation error');
     }
     // check tromboning autorisation
     if (CoreStatus_checkTromboning(FALSE)) {
         $this->load->helper(array('printerlog', 'errorcode'));
         PrinterLog_logMessage('detected and refused tromboning connection', __FILE__, __LINE__);
         // let request failed
         $this->_exitWithError500(ERROR_REMOTE_REFUSE . ' ' . MyERRMSG(ERROR_REMOTE_REFUSE), ERROR_REMOTE_REFUSE);
     }
     // Workflow management
     if (CoreStatus_checkCallREST()) {
         // we place the control for REST web service in his own class
         // because there are the special error codes for REST web service
         // and we do not need them in normal condition
         return;
     } else {
         $status_current = '';
         $url_redirect = '';
         $array_status = array();
         // stats info (do not stats rest, app can initialize cookies in each request)
         $this->load->library('session');
         if (FALSE === $this->input->cookie('stats_browserLog')) {
             $this->input->set_cookie('stats_browserLog', 'ok', 2592000);
             // 30 days for browser stats
             PrinterLog_statsWebAgent();
         }
         // check initialization issue
         if (CoreStatus_checkInInitialization()) {
             if (CoreStatus_checkCallInitialization($url_redirect)) {
                 return;
                 // we are calling the right page
             }
         } else {
             if (CoreStatus_checkCallInitialization()) {
                 $url_redirect = '/';
             } else {
                 if (CoreStatus_checkInUSB()) {
                     if (CoreStatus_checkCallUSB($url_redirect)) {
                         return;
                         // we are calling the right page
                     }
                 } else {
                     if (CoreStatus_checkCallUSB()) {
                         $url_redirect = '/';
                     } else {
                         if (CoreStatus_checkCallDebug()) {
                             // we always let these interfaces go for debug
                             return;
                         } else {
                             if (CoreStatus_checkInConnection()) {
                                 if (CoreStatus_checkCallNoBlockPageInConnection()) {
                                     return;
                                     // we are calling set hostname, activation or account page
                                 }
                                 if (CoreStatus_checkCallConnection($url_redirect)) {
                                     return;
                                     // we are calling the right page
                                 }
                             } else {
                                 if (CoreStatus_checkCallConnection()) {
                                     $url_redirect = '/';
                                 } else {
                                     if (!CoreStatus_checkInIdle($status_current, $array_status)) {
                                         switch ($status_current) {
                                             case CORESTATUS_VALUE_RECOVERY:
                                                 //TODO finish and test me
                                                 if (CoreStatus_checkCallRecovery($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_PRINT:
                                                 if (CoreStatus_checkCallPrinting($array_status, $url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_CANCEL:
                                                 if (CoreStatus_checkCallCanceling($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_LOAD_FILA_L:
                                             case CORESTATUS_VALUE_LOAD_FILA_R:
                                                 if (CoreStatus_checkCallloading($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 // 						return; // we do not block users when charging filament
                                                 break;
                                             case CORESTATUS_VALUE_UNLOAD_FILA_L:
                                             case CORESTATUS_VALUE_UNLOAD_FILA_R:
                                                 //FIXME finish here to block users
                                                 if (CoreStatus_checkCallUnloading($url_redirect)) {
                                                     return;
                                                     // we are calling the right page
                                                 }
                                                 break;
                                             case CORESTATUS_VALUE_SLICE:
                                                 if (CoreStatus_checkCallSlicing($url_redirect)) {
                                                     return;
                                                 }
                                                 break;
                                             default:
                                                 $url_redirect = '/';
                                                 // internal error, never reach here normally
                                                 break;
                                         }
                                     } else {
                                         if (CoreStatus_checkCallPrintingAjax() || CoreStatus_checkCallCancelingAjax()) {
                                             // let ajax request failed when we finishing printing / canceling
                                             $protocol = isset($_SERVER['SERVER_PROTOCOL']) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0';
                                             header($protocol . ' 403');
                                             header('Content-type: text/plain; charset=UTF-8');
                                             echo 'Not in printing / canceling';
                                             exit;
                                         } else {
                                             if (CoreStatus_checkCallPrinting() || CoreStatus_checkCallCanceling()) {
                                                 $url_redirect = '/';
                                             } else {
                                                 if (CoreStatus_checkInPrinted()) {
                                                     if (CoreStatus_checkCallEndPrinting($url_redirect) || CoreStatus_checkCallEndPrintingPlus()) {
                                                         return;
                                                     }
                                                 } else {
                                                     if (CoreStatus_checkCallEndPrinting()) {
                                                         $url_redirect = '/';
                                                         // redirect to homepage when we have no timelapse
                                                     }
                                                 }
                                             }
                                         }
                                         if ($url_redirect) {
                                             header('Location: ' . $url_redirect);
                                             exit;
                                         }
                                         return;
                                         // continue to generate the current page
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         // log error if we have no redirect url when reaching here
         if (is_null($url_redirect)) {
             $this->load->helper('printerlog');
             PrinterLog_logError('no redirect place when MY_Controller finished', __FILE__, __LINE__);
         }
         header('Location: ' . $url_redirect);
         exit;
     }
 }
Exemplo n.º 20
0
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;
}
Exemplo n.º 21
0
function ZimAPI_setPresetSetting($id_preset, $array_input, &$error_parameter, $name_preset = NULL, $overwrite = FALSE)
{
    // $name_preset is NULL when creating preset from an old id
    $ret_val = 0;
    $array_setting = array();
    $preset_path = NULL;
    $system_preset = FALSE;
    // 	$rewrite_json = FALSE;
    $CI =& get_instance();
    if (!is_array($array_input)) {
        return ERROR_INTERNAL;
    }
    // check if we have same name, and define preset path
    if ($name_preset != NULL) {
        $old_path = NULL;
        $ret_val = ZimAPI_checkPreset(ZimAPI_codePresetHash($name_preset), $old_path, $system_preset);
        if ($ret_val == TRUE) {
            $CI->load->helper('printerlog');
            if ($system_preset == TRUE) {
                PrinterLog_logMessage('system can not modify default preset');
                return ERROR_WRONG_PRM;
            } else {
                if ($overwrite == FALSE) {
                    PrinterLog_logMessage('system has already the same preset name: ' . $name_preset);
                    return ERROR_FULL_PRTLST;
                    // just use another error code
                } else {
                    PrinterLog_logMessage('system detects a same preset name, and will overwrite it: ' . $name_preset);
                }
            }
        }
        $preset_path = $CI->config->item('presetlist') . ZimAPI_codePresetHash($name_preset) . '/';
    } else {
        $ret_val = ZimAPI_checkPreset($id_preset, $preset_path, $system_preset);
        if ($ret_val == FALSE) {
            $CI->load->helper('printerlog');
            PrinterLog_logError('system can not find preset: ' . $id_preset);
            return ERROR_WRONG_PRM;
            // just use another error code
        }
        if ($system_preset == TRUE) {
            $CI->load->helper('printerlog');
            PrinterLog_logMessage('system can not modify default preset');
            return ERROR_WRONG_PRM;
        }
        $preset_path .= '/' . $id_preset . '/';
    }
    $ret_val = ZimAPI_checkPresetSetting($array_input, $error_parameter);
    if ($ret_val != TRUE) {
        $CI->load->helper('printerlog');
        PrinterLog_logError('user input preset setting has wrong parameter');
        return ERROR_WRONG_PRM;
    }
    $ret_val = ZimAPI_getPresetSettingAsArray($id_preset, $array_setting);
    if ($ret_val != ERROR_OK) {
        return $ret_val;
    }
    if (!ZimAPI_fixPresetSetting($array_setting)) {
        return ERROR_INTERNAL;
    }
    // check if 4 parameters are changed in same preset name saving (preset json is forced generated in different preset name saving)
    if ($name_preset == NULL) {
        foreach (array(ZIMAPI_TITLE_PRESET_INFILL, ZIMAPI_TITLE_PRESET_SKIRT, ZIMAPI_TITLE_PRESET_RAFT, ZIMAPI_TITLE_PRESET_SUPPORT) as $key) {
            if ($array_setting[$key] != $array_input[$key]) {
                $json_data = array();
                if (ERROR_OK == ZimAPI_getPresetInfoAsArray($id_preset, $json_data)) {
                    $name_preset = $json_data[ZIMAPI_TITLE_PRESET_NAME];
                    // assign preset name as the case in same name overwrite case
                } else {
                    $CI->load->helper('printerlog');
                    PrinterLog_logError('read preset info error in reassignment of 4 parameters', __FILE__, __LINE__);
                    return ERROR_INTERNAL;
                }
                // 				$rewrite_json = TRUE;
            }
        }
    }
    // assign new setting
    foreach ($array_input as $key => $value) {
        $array_setting[$key] = $value;
    }
    // save preset
    if (!file_exists($preset_path)) {
        mkdir($preset_path);
    }
    if ($name_preset != NULL) {
        // || $rewrite_json == TRUE
        $json_data = array(ZIMAPI_TITLE_PRESET_ID => ZimAPI_codePresetHash($name_preset), ZIMAPI_TITLE_PRESET_NAME => $name_preset, ZIMAPI_TITLE_PRESET_INFILL => $array_setting[ZIMAPI_TITLE_PRESET_INFILL], ZIMAPI_TITLE_PRESET_SKIRT => (int) $array_setting[ZIMAPI_TITLE_PRESET_SKIRT], ZIMAPI_TITLE_PRESET_RAFT => (int) $array_setting[ZIMAPI_TITLE_PRESET_RAFT], ZIMAPI_TITLE_PRESET_SUPPORT => (int) $array_setting[ZIMAPI_TITLE_PRESET_SUPPORT]);
        $CI->load->helper('json');
        //write model json info
        try {
            $fp = fopen($preset_path . ZIMAPI_FILE_PRESET_JSON, 'w');
            if ($fp) {
                fwrite($fp, json_encode_unicode($json_data));
                fclose($fp);
            } else {
                return ERROR_INTERNAL;
            }
        } catch (Exception $e) {
            return ERROR_INTERNAL;
        }
    }
    //write config ini file
    try {
        $fp = fopen($preset_path . ZIMAPI_FILE_PRESET_INI, 'w');
        if ($fp) {
            foreach ($array_setting as $key => $value) {
                fwrite($fp, $key . " = " . $value . "\r\n");
            }
            fclose($fp);
        } else {
            return ERROR_INTERNAL;
        }
    } catch (Exception $e) {
        return ERROR_INTERNAL;
    }
    return ERROR_OK;
}
Exemplo n.º 22
0
 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;
 }
Exemplo n.º 23
0
 public function offset_setting()
 {
     $template_data = array();
     $error = '';
     $this->load->library('parser');
     $this->lang->load('printerstate/nozzles', $this->config->item('language'));
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         $this->load->helper('printerstate');
         $top_offset = $this->input->post('top_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         $bot_offset = $this->input->post('bot_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         $right_offset = $this->input->post('right_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         $left_offset = $this->input->post('left_offset') * PRINTERSTATE_VALUE_FACTOR_NOZZLE_OFFSET;
         if ($top_offset * $bot_offset != 0 || $right_offset * $left_offset != 0) {
             $error .= t('invalid_input') . '<br/>';
         } else {
             $array_data = array();
             if ($top_offset != 0) {
                 $array_data['Y'] = -$top_offset;
             } else {
                 if ($bot_offset != 0) {
                     $array_data['Y'] = $bot_offset;
                 }
             }
             if ($right_offset != 0) {
                 $array_data['X'] = -$right_offset;
             } else {
                 if ($left_offset != 0) {
                     $array_data['X'] = $left_offset;
                 }
             }
             if (count($array_data)) {
                 $cr = 0;
                 foreach (array('X', 'Y') as $axis) {
                     if (array_key_exists($axis, $array_data)) {
                         $value = 0;
                         $cr = PrinterState_getOffset($axis, $value);
                         if ($cr != ERROR_OK) {
                             $error .= t('marlin_error') . '<br/>';
                             $this->load->helper('printerlog');
                             PrinterLog_logError('get ancient offset error, axis: ' . $axis . ', cr: ' . $cr, __FILE__, __LINE__);
                             break;
                         }
                         $array_data[$axis] += $value;
                         // add new offset on the ancient offset
                     }
                 }
                 if (count($error)) {
                     // we have no error for getting ancient offset, goto setting offset
                     $cr = PrinterState_setOffset($array_data);
                     if ($cr == ERROR_WRONG_PRM) {
                         $error .= t('value_zone_error') . '<br/>';
                         $this->load->helper('printerlog');
                         PrinterLog_logError('pass value zone for offset', __FILE__, __LINE__);
                     } else {
                         if ($cr != ERROR_OK) {
                             $error .= t('marlin_error') . '<br/>';
                             $this->load->helper('printerlog');
                             PrinterLog_logError('set offset error, axis: ' . $axis . ', cr: ' . $cr, __FILE__, __LINE__);
                         } else {
                             $this->output->set_header('Location: /printerstate/nozzles_adjustment');
                             return;
                         }
                     }
                 }
             }
         }
     }
     $template_data = array('nozzles_title' => t('nozzles_title'), 'nozzles_intro' => t('nozzles_intro'), 'collapsible_1' => t('collapsible_1'), 'collapsible_2' => t('collapsible_2'), 'back' => t('back'), 'home' => t('home'), 'error' => $error);
     $this->_parseBaseTemplate(t('nozzle_offset_pagetitle'), $this->parser->parse('printerstate/offset_setting', $template_data, TRUE));
     return;
 }
Exemplo n.º 24
0
 public function in_progress($ssid = NULL)
 {
     $template_data = array();
     $body_page = NULL;
     $hostname = NULL;
     $this->load->library('parser');
     $this->load->helper('zimapi');
     $this->lang->load('connection/master', $this->config->item('language'));
     $this->lang->load('connection/in_progress', $this->config->item('language'));
     if (ERROR_OK != ZimAPI_getHostname($hostname)) {
         $this->load->helper('printerlog');
         PrinterLog_logError('cannot get hostname', __FILE__, __LINE__);
     }
     $template_data = array('hostname' => $hostname, 'printersn' => ZimAPI_getSerial(), 'config_printer' => t('config_printer'), 'connect_error_msg' => t('connect_error_msg'), 'popup' => t('popup', $ssid ? urldecode($ssid) : "XXX"));
     $body_page = $this->parser->parse('connection/in_progress', $template_data, TRUE);
     $this->_generate_framePage($body_page);
     return;
 }