Exemple #1
0
 private function _deal_with_unloading_wait_time($abb_cartridge, $array_status)
 {
     $offset_check = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_UNLOAD;
     if (array_key_exists(CORESTATUS_TITLE_FILA_MAT, $array_status) && $array_status[CORESTATUS_TITLE_FILA_MAT] == PRINTERSTATE_DESP_MATERIAL_PVA) {
         $offset_check = PRINTERSTATE_VALUE_OFFSET_TO_CHECK_UNLOAD_PVA;
     }
     if (file_exists(PRINTERSTATE_FILE_UNLOAD_HEAT)) {
         $time_start = @file_get_contents(PRINTERSTATE_FILE_UNLOAD_HEAT);
         // 			PrinterLog_logDebug('start time: ' . $time_start, __FILE__, __LINE__);
         if (is_null($time_start)) {
             PrinterLog_logError('check unload heat status file error', __FILE__, __LINE__);
             return FALSE;
         } else {
             if (time() - $time_start <= PRINTERSTATE_VALUE_TIMEOUT_UNLOAD_HEAT) {
                 // block the status if in timeout, and refresh the start time for the following state
                 CoreStatus_setInUnloading($abb_cartridge);
                 // 				PrinterLog_logDebug('rewrite status', __FILE__, __LINE__);
                 return FALSE;
             } else {
                 // always in heating when we passed timeout, we unlock the mobile site
                 PrinterLog_logError('always in heating process when we unload filament', __FILE__, __LINE__);
                 @unlink(PRINTERSTATE_FILE_UNLOAD_HEAT);
                 $ret_val = CoreStatus_setInIdle();
                 if ($ret_val == TRUE) {
                     $status_current = CORESTATUS_VALUE_IDLE;
                     return TRUE;
                 }
                 $CI =& get_instance();
                 $CI->load->helper('printerlog');
                 PrinterLog_logError('can not set status into idle', __FILE__, __LINE__);
                 return FALSE;
             }
         }
     } else {
         // wait the time for arduino before checking filament when unloading filament
         // we return TRUE only when finishing action or passing max wait time (Arduino is avaliable for command)
         if (CoreStatus_checkInWaitTime($offset_check)) {
             return FALSE;
         }
     }
     return TRUE;
 }
function PrinterState_unloadFilament($abb_filament)
{
    $CI =& get_instance();
    $output = array();
    $array_cartridge = array();
    $command = $CI->config->item('siteutil');
    $ret_val = 0;
    $temper_unload = PRINTERSTATE_TEMPER_MAX_E;
    $is_pva = FALSE;
    $ret_val = PrinterState_getCartridgeAsArray($array_cartridge, $abb_filament);
    if ($ret_val != ERROR_OK) {
        PrinterLog_logError('read cartridge error when unloading', __FILE__, __LINE__);
        return ERROR_INTERNAL;
    }
    // fix temperature according to filament type
    switch ($array_cartridge[PRINTERSTATE_TITLE_MATERIAL]) {
        case PRINTERSTATE_DESP_MATERIAL_PLA:
            $temper_unload = PRINTERSTATE_VALUE_FILAMENT_PLA_LOAD_TEMPER;
            break;
        case PRINTERSTATE_DESP_MATERIAL_ABS:
            $temper_unload = PRINTERSTATE_VALUE_FILAMENT_ABS_LOAD_TEMPER;
            break;
        case PRINTERSTATE_DESP_MATERIAL_PVA:
            $temper_unload = PRINTERSTATE_VALUE_FILAMENT_PVA_LOAD_TEMPER;
            $is_pva = TRUE;
            break;
        default:
            PrinterLog_logError('unknown filament type in unloading', __FILE__, __LINE__);
            return ERROR_INTERNAL;
            break;
            // never reach here
    }
    if ($is_pva) {
        $command .= PRINTERSTATE_UNLOAD_FILA_PVA;
    } else {
        $command .= PRINTERSTATE_UNLOAD_FILAMENT;
    }
    $command .= $abb_filament . ' ' . $temper_unload;
    $CI->load->helper('detectos');
    if ($CI->config->item('simulator') == FALSE && !DectectOS_checkWindows()) {
        // 		$command .= ' > ' . PRINTERSTATE_FILE_RESPONSE . ' &';
        $command .= ' &';
    } else {
        $command = 'start /B ' . $command;
    }
    // check already unloaded
    if (PrinterState_getFilamentStatus($abb_filament) == FALSE) {
        return ERROR_LOADED_UNLOAD;
    }
    // change status json file
    $ret_val = CoreStatus_setInUnloading($abb_filament, $array_cartridge[PRINTERSTATE_TITLE_MATERIAL]);
    if ($ret_val == FALSE) {
        return ERROR_INTERNAL;
    }
    pclose(popen($command, 'r'));
    // only for windows arcontrol client
    PrinterLog_logArduino($command);
    // we can't log return output when using this solution
    return ERROR_OK;
}