public function get() { $parameter = NULL; $cr = 0; $display = NULL; $api_prm = NULL; $this->load->helper(array('printerstate', 'zimapi')); $parameter = $this->input->get('p'); //return false if missing if ($parameter) { switch ($parameter) { case PRINTERSTATE_PRM_EXTRUDER: $cr = PrinterState_getExtruder($display); //$abb_extruder break; case PRINTERSTATE_PRM_TEMPER: // check which temperature we want $has_e = $this->input->get('e'); $has_h = $this->input->get('h'); $has_v = $this->input->get('v'); if ($has_e === FALSE && $has_h === FALSE) { $cr = ERROR_MISS_PRM; } else { if (!($has_e === FALSE) && !($has_h === FALSE)) { $cr = ERROR_WRONG_PRM; } else { if (!($has_e === FALSE) && !($has_v === FALSE)) { // refuse getting data not existed for mono extruder if ($has_v == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { if (in_array($has_v, array('l', 'r'))) { // $tmp_array = PrinterState_getExtruderTemperaturesAsArray(); // $cr = ERROR_OK; // $display = ($has_v == 'l') // ? $tmp_array[PRINTERSTATE_LEFT_EXTRUD] // : $tmp_array[PRINTERSTATE_RIGHT_EXTRUD]; $cr = PrinterState_getTemperature($display, 'e', $has_v); } else { $cr = ERROR_WRONG_PRM; } } } else { $api_prm = $has_e === FALSE ? 'h' : 'e'; $cr = PrinterState_getTemperature($display, $api_prm); } } } break; case PRINTERSTATE_PRM_CARTRIDGE: $api_prm = $this->input->get('v'); // refuse getting data not existed for mono extruder if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { $cr = PrinterState_getCartridge($display, $api_prm); } break; case PRINTERSTATE_PRM_INFO: //TODO need add SSO account $cr = ERROR_OK; $display = PrinterState_getInfo(); break; case 'render': $this->_return_under_construction(); return; break; case PRINTERSTATE_PRM_ACCELERATION: $cr = PrinterState_getAcceleration($display); break; case PRINTERSTATE_PRM_SPEED_MOVE: case PRINTERSTATE_PRM_SPEED_EXTRUDE: $cr = PrinterState_getSpeed($display); break; case PRINTERSTATE_PRM_COLDEXTRUSION: $value = NULL; $cr = PrinterState_getColdExtrusion($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_FILAMENT: $value = NULL; $api_prm = $this->input->get('v'); // refuse getting data not existed for mono extruder if ($api_prm == 'l' && $this->config->item('nb_extruder') == 1) { $cr = ERROR_WRONG_PRM; } else { if ($api_prm) { $cr = ERROR_OK; $value = PrinterState_getFilamentStatus($api_prm); if ($value == TRUE) { $display = 'true'; } else { $display = 'false'; } } else { $cr = ERROR_MISS_PRM; } } break; case PRINTERSTATE_PRM_ENDSTOP: $status = NULL; $abb_endstop = $this->input->get('axis'); $cr = PrinterState_getEndstop($abb_endstop, $status); if ($cr == ERROR_OK) { $display = $status ? 'on' : 'off'; } break; case PRINTERSTATE_PRM_STRIPLED: $value = NULL; $cr = PrinterState_getStripLedStatus($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_HEADLED: $value = NULL; $cr = PrinterState_getTopLedStatus($value); if ($cr == ERROR_OK) { if ($value == TRUE) { $display = 'on'; } else { $display = 'off'; } } break; case PRINTERSTATE_PRM_OFFSET: $value = NULL; $axis = $this->input->get('axis'); if ($axis) { $cr = PrinterState_getOffset($axis, $value); if ($cr == ERROR_OK) { $display = $value; } } else { $cr = ERROR_MISS_PRM; } break; case PRINTERSTATE_PRM_POSITION: $cr = PrinterState_getPosition($display); break; case ZIMAPI_PRM_CAPTURE: $path_capture = ''; $password = $this->input->get('password'); if (!ZimAPI_checkCameraPassword($password)) { $cr = ERROR_WRONG_PWD; break; } $this->load->helper('file'); if (ZimAPI_cameraCapture($path_capture)) { $this->output->set_content_type(get_mime_by_extension($path_capture))->set_output(@file_get_contents($path_capture)); return; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_VIDEO_MODE: if (ZimAPI_checkCamera($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_PRESET: if (ZimAPI_getPreset($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_UPGRADE: if (ZimAPI_getUpgradeMode($display)) { $cr = ERROR_OK; } else { $cr = ERROR_INTERNAL; } if ($display != 'off') { $display = 'on'; } break; case ZIMAPI_PRM_PROXY: if (ZimAPI_getTromboning()) { $display = 'on'; } else { $display = 'off'; } $cr = ERROR_OK; break; case ZIMAPI_PRM_SSH: $status_current = NULL; if (ZimAPI_getSSH($status_current)) { $cr = ERROR_OK; if ($status_current) { $display = 'on'; } else { $display = 'off'; } } else { $cr = ERROR_INTERNAL; } break; case ZIMAPI_PRM_STATS: if (ZimAPI_getStatistic()) { $display = 'on'; } else { $display = 'off'; } $cr = ERROR_OK; break; default: $cr = ERROR_WRONG_PRM; break; } } else { $cr = ERROR_MISS_PRM; } if ($cr != ERROR_OK) { $display = $cr . " " . t(MyERRMSG($cr)); } $this->output->set_status_header($cr, $display); // http_response_code($cr); $this->output->set_content_type(RETURN_CONTENT_TYPE); // echo $display; $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); return; }
public function changecartridge_temper() { $ret_val = 0; $temp_data = 0; $abb_cartridge = $this->input->get('v'); if (!$abb_cartridge && !in_array($abb_cartridge, array('l', 'r'))) { $this->output->set_status_header(403); // invalid request return; } $ret_val = PrinterState_getTemperature($temp_data, 'e', $abb_cartridge); if ($ret_val == ERROR_OK && $temp_data >= PRINTERSTATE_VALUE_MAXTEMPER_BEFORE_UNLOAD) { $ret_val = 202; // change status header to stop signal } $this->output->set_status_header($ret_val); return; }
function CoreStatus_initialFile() { $CI =& get_instance(); $state_file = NULL; $sdcard = FALSE; $check_onboot = FALSE; $nb_extruder = 0; $heat_bed = 0; // for the first time, check if we can use all files in sdcard instead of config partition // then save the choice in a status file in the temp to remember it if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_SD_ON)) { $sdcard = TRUE; } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_SD_OFF)) { $sdcard = FALSE; } else { if (is_writable($CI->config->item('sdcard'))) { $cr = 0; $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('sdcard') . '.phptest.tmp'; $output = array(); $CI->load->helper('errorcode'); exec($command, $output, $cr); if ($cr == ERROR_NORMAL_RC_OK) { $sdcard = TRUE; $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('temp') . CORESTATUS_FILE_SD_ON; } else { $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('temp') . CORESTATUS_FILE_SD_OFF; } } else { $command = CORESTATUS_CMD_CHECK_SD . $CI->config->item('temp') . CORESTATUS_FILE_SD_OFF; } exec($command); $check_onboot = TRUE; } } $array_change = array('conf' => CORESTATUS_SUFFIX_CONF, 'presetlist' => CORESTATUS_SUFFIX_PRESET); foreach ($array_change as $key => $value) { $folder_path = NULL; if ($sdcard == TRUE) { $folder_path = $CI->config->item('sdcard') . $value; } else { $folder_path = $CI->config->item('nandconf') . $value; } // check folder exists or not, if not, create it if (!file_exists($folder_path)) { mkdir($folder_path); } // change config setting to right path $CI->config->set_item($key, $folder_path); } $CI->config->set_item('use_sdcard', $sdcard); // initialization of preset $CI->load->helper('zimapi'); if (!ZimAPI_initialFile()) { return FALSE; } // initialization of library if ($sdcard) { $CI->load->helper('printerstoring'); if (!PrinterStoring_initialFile()) { return FALSE; } } $state_file = $CI->config->item('conf') . CORESTATUS_FILENAME_WORK; if (!file_exists($state_file) || 0 == filesize($state_file)) { // prepare data array $CI->load->helper('printerstate'); $data_json = array(CORESTATUS_TITLE_VERSION => '1.0', CORESTATUS_TITLE_STATUS => CORESTATUS_VALUE_IDLE, CORESTATUS_TITLE_LASTERROR => NULL, CORESTATUS_TITLE_MESSAGE => NULL, CORESTATUS_TITLE_SUBSTATUS => NULL, CORESTATUS_TITLE_PRINTMODEL => CORESTATUS_VALUE_MID_CALIBRATION, CORESTATUS_TITLE_ELAPSED_TIME => 0, CORESTATUS_TITLE_P_TEMPER_L => 0, CORESTATUS_TITLE_P_TEMPER_R => 0, CORESTATUS_TITLE_P_TEMPER_B => 0, CORESTATUS_TITLE_P_EXCH_BUS => 0, CORESTATUS_TITLE_FILA_MAT => PRINTERSTATE_DESP_MATERIAL_PLA, CORESTATUS_TITLE_GUID => random_string('numeric', CORESTATUS_VALUE_RAND_STRING_LENGTH), CORESTATUS_TITLE_ESTIMATE_T => 0); // write json file $fp = fopen($state_file, 'w'); if ($fp) { fwrite($fp, json_encode($data_json)); fclose($fp); chmod($state_file, 0777); } else { return FALSE; } } else { if ($check_onboot == TRUE) { // change loading and unloading status into idle on the first boot checking $status_check = NULL; CoreStatus_checkInIdle($status_check); if (in_array($status_check, array(CORESTATUS_VALUE_LOAD_FILA_L, CORESTATUS_VALUE_UNLOAD_FILA_L, CORESTATUS_VALUE_LOAD_FILA_R, CORESTATUS_VALUE_UNLOAD_FILA_R))) { CoreStatus_setInIdle(); } } } // debug level if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_DEBUG)) { $CI->config->set_item('log_level', 3); } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_MESSAGE)) { $CI->config->set_item('log_level', 2); } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_ERROR)) { $CI->config->set_item('log_level', 1); } else { if (file_exists($CI->config->item('temp') . CORESTATUS_FILE_LEVEL_NONE)) { $CI->config->set_item('log_level', 0); } } } } // extruder number $state_file = $CI->config->item('temp') . CORESTATUS_FILE_NB_EXTRUDER; if (file_exists($state_file)) { $nb_extruder = (int) @file_get_contents($state_file); } if ($nb_extruder == 0) { // check again if status file indicate 0 extruder $CI->load->helper('printerstate'); $nb_extruder = PrinterState_getNbExtruder(); // write status file $fp = fopen($state_file, 'w'); if ($fp) { fwrite($fp, $nb_extruder); fclose($fp); } else { return FALSE; } } if ($nb_extruder != 0) { // set printer in default mode (2) if error (0 extruder detected) $CI->config->set_item('nb_extruder', $nb_extruder); } // heat bed $state_file = $CI->config->item('temp') . CORESTATUS_FILE_HEAT_BED; if (file_exists($state_file)) { $heat_bed = (int) @file_get_contents($state_file); if ($heat_bed) { $CI->config->set_item('heat_bed', TRUE); } } else { $CI->load->helper('printerstate'); $ret_val = PrinterState_getTemperature($heat_bed, 'b'); if ($ret_val == ERROR_OK) { $tmp_bool = $heat_bed != PRINTERSTATE_TEMPER_NO_HEAT_BED; $fp = fopen($state_file, 'w'); if ($fp) { fwrite($fp, $tmp_bool ? 1 : 0); fclose($fp); $CI->config->set_item('heat_bed', $tmp_bool); } else { return FALSE; } } } return TRUE; }