Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
0
function Slicer_changeTemperByCartridge($array_cartridge, $heat_bed = FALSE)
{
    $json_cartridge = array();
    $temperature = $first_temperature = NULL;
    $array_danger_return = array(ERROR_INTERNAL, ERROR_WRONG_PRM, ERROR_BUSY_PRINTER, ERROR_MISS_RIGT_CART, ERROR_MISS_LEFT_CART);
    $CI =& get_instance();
    $CI->load->helper('printerstate');
    // 	foreach ($array_cartridge as $abb_cartridge) {
    // 		switch ($abb_cartridge) {
    // 			case 'r':
    // 				$array_danger_return[] = ERROR_MISS_RIGT_CART;
    // 				break;
    // 			case 'l':
    // 				$array_danger_return[] = ERROR_MISS_LEFT_CART;
    // 				break;
    // 			default:
    // 				$CI->load->helper('printerlog');
    // 				PrinterLog_logError('unknown cartridge abb value', __FILE__, __LINE__);
    // 				return ERROR_INTERNAL;
    // 				break; // never reach here
    // 		}
    // 	}
    foreach (array('r', 'l') as $abb_cartridge) {
        $ret_val = PrinterState_getCartridgeAsArray($json_cartridge, $abb_cartridge);
        //TODO think about if we need to set default temperature when cartridge is absent or not
        if (in_array($ret_val, $array_danger_return)) {
            //TODO notice the printerstate helper that slicer use default temperature instead of cartridge info (user can put cartridge during slicing)
            $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER] = SLICER_VALUE_DEFAULT_TEMPER;
            $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1] = SLICER_VALUE_DEFAULT_FIRST_TEMPER;
            $CI->load->helper('printerlog');
            PrinterLog_logMessage('dangerous return detected: ' . $ret_val . ', slicer default temperature assigned for cartridge ' . $abb_cartridge, __FILE__, __LINE__);
        }
        if (is_null($temperature)) {
            $temperature = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER];
        } else {
            $temperature .= ',' . $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMPER];
        }
        if (is_null($first_temperature)) {
            $first_temperature = $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1];
        } else {
            $first_temperature .= ',' . $json_cartridge[PRINTERSTATE_TITLE_EXT_TEMP_1];
        }
    }
    $array_setting = array('temperature' => $temperature, 'first_layer_temperature' => $first_temperature);
    if ($heat_bed) {
        $array_setting['bed_temperature'] = SLICER_VALUE_DEFAULT_BED_TEMPER;
    }
    $cr = Slicer_changeParameter($array_setting);
    return $cr;
}