Exemple #1
0
 public function extrude($extruder = NULL, $value = NULL, $speed = NULL)
 {
     if (is_null($extruder) || is_null($value) || is_null($speed) || (int) $value == 0 || (int) $speed == 0) {
         $this->output->set_status_header(403);
         return;
     } else {
         $cr = 0;
         $this->load->helper(array('printerstate', 'errorcode'));
         $cr = PrinterState_setExtruder($extruder);
         if ($cr == ERROR_OK) {
             $cr = PrinterState_move('E', (int) $value, (int) $speed);
         }
         if ($cr == ERROR_OK) {
             $this->output->set_status_header(200);
             return;
         }
     }
     $this->output->set_status_header(403);
     return;
 }
Exemple #2
0
 public function set()
 {
     $parameter = NULL;
     $cr = 0;
     $this->load->helper(array('printerstate', 'zimapi', 'slicer'));
     $parameter = $this->input->get('p');
     //return false if missing
     if ($parameter) {
         switch ($parameter) {
             case PRINTERSTATE_PRM_EXTRUDER:
                 $api_prm = $this->input->get('v');
                 if ($api_prm) {
                     // 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_setExtruder($api_prm);
                     }
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case PRINTERSTATE_PRM_TEMPER:
                 // check which temperature we want
                 $val_temper = 0;
                 $api_prm = NULL;
                 $val_temper = $this->input->get('v');
                 $has_e = $this->input->get('e');
                 $has_h = $this->input->get('h');
                 if ($has_e === FALSE && $has_h === FALSE) {
                     $cr = ERROR_MISS_PRM;
                 } else {
                     if (!($has_e === FALSE) && !($has_h === FALSE)) {
                         $cr = ERROR_WRONG_PRM;
                     } else {
                         $api_prm = $has_e === FALSE ? 'h' : 'e';
                         $cr = PrinterState_setTemperature($val_temper, $api_prm);
                     }
                 }
                 break;
             case PRINTERSTATE_PRM_ACCELERATION:
                 $val_acceleration = (int) $this->input->get('v');
                 if ($val_acceleration) {
                     $cr = PrinterState_setAcceleration($val_acceleration);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case PRINTERSTATE_PRM_SPEED_MOVE:
             case PRINTERSTATE_PRM_SPEED_EXTRUDE:
                 $val_speed = (int) $this->input->get('v');
                 if ($val_speed) {
                     $cr = PrinterState_setSpeed($val_speed);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case PRINTERSTATE_PRM_COLDEXTRUSION:
                 $this->_return_under_construction();
                 return;
                 break;
             case PRINTERSTATE_PRM_STRIPLED:
                 $status_set = $this->input->get('v');
                 if ($status_set) {
                     $cr = PrinterState_setStripLed($status_set);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case PRINTERSTATE_PRM_MOTOR_OFF:
                 $status_set = $this->input->get('v');
                 if ($status_set == 'off') {
                     $cr = PrinterState_disableSteppers();
                 } else {
                     if ($status_set) {
                         $cr = ERROR_WRONG_PRM;
                     } else {
                         $cr = ERROR_MISS_PRM;
                     }
                 }
                 break;
             case PRINTERSTATE_PRM_HEADLED:
                 $status_set = $this->input->get('v');
                 if ($status_set) {
                     $cr = PrinterState_setHeadLed($status_set);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case PRINTERSTATE_PRM_OFFSET:
                 $axis = $this->input->get('axis');
                 $val_offset = $this->input->get('adjustment');
                 if ($axis && $val_offset !== FALSE) {
                     $cr = PrinterState_setOffset(array($axis => $val_offset));
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case ZIMAPI_PRM_PASSWD:
                 $old_password = $this->input->get('o');
                 $password = $this->input->get('v');
                 if (ZimAPI_checkCameraPassword($old_password)) {
                     if (ZimAPI_setCameraPassword($password)) {
                         $cr = ERROR_OK;
                     } else {
                         $cr = ERROR_INTERNAL;
                     }
                 } else {
                     $cr = ERROR_WRONG_PWD;
                 }
                 break;
             case ZIMAPI_PRM_VIDEO_MODE:
                 $set_status = $this->input->get('v');
                 $password = $this->input->get('s');
                 $parameter = $this->input->get('m');
                 if (!ZimAPI_checkCameraPassword($password)) {
                     $cr = ERROR_WRONG_PWD;
                     break;
                 }
                 if ($set_status && $set_status == 'off') {
                     if (ZimAPI_cameraOff()) {
                         $cr = ERROR_OK;
                     } else {
                         $cr = ERROR_INTERNAL;
                     }
                 } else {
                     if ($set_status && $set_status == 'on') {
                         // temporary change - jump out of verification if we have no parameter 20140811
                         if (!$parameter) {
                             $parameter = ZIMAPI_PRM_CAMERA_PRINTSTART;
                         }
                         if (ZimAPI_cameraOn($parameter)) {
                             $cr = ERROR_OK;
                         } else {
                             $cr = ERROR_INTERNAL;
                         }
                         // 						}
                         // 						else {
                         // 							$cr = ERROR_MISS_PRM;
                         // 						}
                     } else {
                         if ($set_status) {
                             $cr = ERROR_WRONG_PRM;
                         } else {
                             $cr = ERROR_MISS_PRM;
                         }
                     }
                 }
                 break;
             case ZIMAPI_PRM_PRESET:
                 $id_preset = $this->input->get('id');
                 if ($id_preset) {
                     $cr = ZimAPI_setPreset($id_preset);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case SLICER_PRM_PRM:
                 $density = $this->input->get('density');
                 $skirt = $this->input->get('skirt');
                 $raft = $this->input->get('raft');
                 $support = $this->input->get('support');
                 $array_setting = array();
                 if ($density !== FALSE) {
                     $density = (int) $density / 100;
                     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 {
                     $cr = Slicer_changeParameter($array_setting);
                 }
                 break;
             case ZIMAPI_PRM_SSO_NAME:
                 $name = $this->input->get('name');
                 if ($name) {
                     $cr = ZimAPI_setPrinterSSOName($name);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case ZIMAPI_PRM_UPGRADE:
                 $status_set = $this->input->get('v');
                 $profile = $this->input->get('profile');
                 if ($status_set) {
                     $cr = ZimAPI_setUpgradeMode($status_set, $profile);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case ZIMAPI_PRM_PROXY:
                 $status_set = $this->input->get('v');
                 if ($status_set) {
                     $cr = ZimAPI_setTromboning($status_set);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case ZIMAPI_PRM_SSH:
                 $status_set = $this->input->get('v');
                 if ($status_set) {
                     $cr = ZimAPI_setSSH($status_set);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             case ZIMAPI_PRM_STATS:
                 $status_set = $this->input->get('v');
                 if ($status_set) {
                     $cr = ZimAPI_setStatistic($status_set);
                 } else {
                     $cr = ERROR_MISS_PRM;
                 }
                 break;
             default:
                 $cr = ERROR_WRONG_PRM;
                 break;
         }
     } else {
         $cr = ERROR_MISS_PRM;
     }
     $this->_return_cr($cr);
     return;
 }
Exemple #3
0
 public function cancel_ajax()
 {
     $template_data = array();
     $ret_val = 0;
     // 		$data_status = array();
     // 		$this->load->helper(array('printer', 'timedisplay'));
     $this->load->helper('printer');
     $this->load->library('parser');
     $this->lang->load('printdetail', $this->config->item('language'));
     // 		$this->lang->load('timedisplay', $this->config->item('language'));
     // 		$ret_val = Printer_checkCancelStatus($data_status);
     $ret_val = Printer_checkCancelStatus();
     if ($ret_val == FALSE) {
         $this->load->helper('corestatus');
         $ret_val = CoreStatus_setInIdle();
         if ($ret_val == FALSE) {
             // log internal error
             $this->load->helper('printerlog');
             PrinterLog_logError('can not set idle after canceling', __FILE__, __LINE__);
         }
         if ($this->config->item('simulator')) {
             // just set temperature for simulation
             $this->load->helper('printerstate');
             PrinterState_setExtruder('r');
             PrinterState_setTemperature(20);
             PrinterState_setExtruder('l');
             PrinterState_setTemperature(20);
             PrinterState_setExtruder('r');
         }
         $this->output->set_status_header(202);
         return;
     }
     // 		// treat time remaining for display
     // 		if (isset($data_status['print_remain'])) {
     // 			$time_remain = TimeDisplay__convertsecond(
     // 					$data_status['print_remain'], t('Time remaining: '), t('under calculating'));
     // 		}
     // 		else {
     // 			$time_remain = t('Time remaining: ') . t('unknown');
     // 		}
     // parse the ajax part
     $template_data = array('wait_info' => t('wait_hint_cancel'));
     $this->parser->parse('printdetail/cancel_ajax', $template_data);
     $this->output->set_content_type('text/plain; charset=UTF-8');
     return;
 }
Exemple #4
0
function Printer_printFromFile($gcode_path, $model_id, $time_estimation, $need_prime = TRUE, $exchange_extruder = FALSE, $array_filament = array(), $array_temper = array())
{
    global $CFG;
    $command = '';
    $output = array();
    $temper_json = array();
    $ret_val = 0;
    $stats_info = array();
    $CI =& get_instance();
    $CI->load->helper(array('printerstate', 'errorcode', 'corestatus', 'printerlog', 'detectos'));
    // check if we have no file
    if (!file_exists($gcode_path)) {
        return ERROR_INTERNAL;
    }
    // only check if we are in printing when we are not called stopping printing
    // 	if ($stop_printing == FALSE) {
    // check if in printing
    $ret_val = PrinterState_checkInPrint();
    if ($ret_val == TRUE) {
        // 			return ERROR_IN_PRINT;
        PrinterLog_logMessage('already in printing', __FILE__, __LINE__);
        return ERROR_BUSY_PRINTER;
    }
    // 	}
    // check extruder number
    if ($CI->config->item('nb_extruder') < 2) {
        $tmp_array = array();
        $command = $CFG->config['gcanalyser'] . $gcode_path;
        exec($command, $output, $ret_val);
        if ($ret_val != ERROR_NORMAL_RC_OK) {
            PrinterLog_logError('gcanalyser error', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
        $tmp_array = json_decode($output[0], TRUE);
        if ($tmp_array['N'] > $CI->config->item('nb_extruder')) {
            PrinterLog_logMessage('no enough extruder', __FILE__, __LINE__);
            return ERROR_INTERNAL;
        }
    }
    // check if having enough filament
    $ret_val = PrinterState_checkFilaments($array_filament);
    if ($ret_val != ERROR_OK) {
        return $ret_val;
    }
    if ($time_estimation == 0) {
        $ret_val = Printer__getEstimation($array_filament, $time_estimation);
        if ($ret_val != TRUE) {
            PrinterLog_logError('system can not get estimation time');
            return ERROR_INTERNAL;
        }
    }
    // prepare subprinting gcode files and scripts
    $ret_val = Printer_preparePrint($model_id, $need_prime);
    if ($ret_val != ERROR_OK) {
        return $ret_val;
    }
    // 	if ($stop_printing == FALSE) {
    if ($CFG->config['simulator']) {
        // just set temperature for simulation
        PrinterState_setExtruder('r');
        PrinterState_setTemperature(210);
        PrinterState_setExtruder('l');
        PrinterState_setTemperature(200);
        PrinterState_setExtruder('r');
    }
    // change status json file
    foreach ($array_temper as $abb_filament => $tmp_temper) {
        if ($abb_filament != 'b' && (!array_key_exists($abb_filament, $array_filament) || $array_filament[$abb_filament] <= 0)) {
            $temper_json[$abb_filament] = NULL;
        } else {
            $temper_json[$abb_filament] = $array_temper[$abb_filament];
        }
    }
    $ret_val = CoreStatus_setInPrinting($model_id, $time_estimation, $exchange_extruder, $temper_json);
    // 	}
    // 	else {
    // 		$ret_val = CoreStatus_setInCanceling();
    // 	}
    if ($ret_val == FALSE) {
        return ERROR_INTERNAL;
    }
    // stats info
    $stats_info[PRINTERLOG_STATS_MODEL] = $model_id;
    foreach ($temper_json as $abb_filament => $tmp_temper) {
        if (isset($tmp_temper)) {
            $json_cartridge = array();
            $arrkey_type = PRINTERLOG_STATS_FILA_TYPE_R;
            $arrkey_color = PRINTERLOG_STATS_FILA_COLOR_R;
            if ($abb_filament == 'l') {
                $arrkey_type = PRINTERLOG_STATS_FILA_TYPE_L;
                $arrkey_color = PRINTERLOG_STATS_FILA_COLOR_L;
            }
            if (ERROR_OK == PrinterState_getCartridgeAsArray($json_cartridge, $abb_filament)) {
                $stats_info[$arrkey_type] = $json_cartridge[PRINTERSTATE_TITLE_MATERIAL];
                $stats_info[$arrkey_color] = $json_cartridge[PRINTERSTATE_TITLE_COLOR];
            }
        }
    }
    PrinterLog_statsPrint(PRINTERLOG_STATS_ACTION_START, $stats_info);
    // pass gcode to printer
    //	if (!PrinterState_beforeFileCommand()) {
    //		return ERROR_INTERNAL;
    //	}
    // use different command for priming
    if ($need_prime == FALSE) {
        $command = PrinterState_getPrintCommand($array_filament, TRUE, TRUE) . $gcode_path;
    } else {
        $command = PrinterState_getPrintCommand($array_filament) . $gcode_path;
    }
    // 		exec($command, $output, $ret_val);
    // 		if ($ret_val != ERROR_NORMAL_RC_OK) {
    // 			return ERROR_INTERNAL;
    // 		}
    if ($CFG->config['simulator'] && DectectOS_checkWindows()) {
        pclose(popen($command, 'r'));
        // only for windows arcontrol client
        PrinterLog_logArduino($command);
    } else {
        // 		exec($command, $output, $ret_val);
        pclose(popen($command . ' > ' . PRINTERSTATE_FILE_PRINTLOG . ' &', 'r'));
        // 		if (!PrinterState_filterOutput($output)) {
        // 			PrinterLog_logError('filter arduino output error', __FILE__, __LINE__);
        // 			return ERROR_INTERNAL;
        // 		}
        // 		if ($ret_val != ERROR_NORMAL_RC_OK) {
        // 			return $ret_val;
        // 		}
        // 		PrinterLog_logArduino($command, $output);
        PrinterLog_logArduino($command);
    }
    //	if (!PrinterState_afterFileCommand()) {
    //		return ERROR_INTERNAL;
    //	}
    return ERROR_OK;
}