void stepperSim::setEndstops(int minEndstopPinNr, int maxEndstopPinNr) { minEndstopPin = minEndstopPinNr; maxEndstopPin = maxEndstopPinNr; writeInput(minEndstopPin, stepValue != minStepValue); writeInput(maxEndstopPin, stepValue != maxStepValue); }
void stepperSim::stepPinUpdate(int pinNr, bool high) { if (high)//Only step on high->low transition. return; if (readOutput(enablePin)) return; if (readOutput(dirPin) == invertDir) stepValue --; else stepValue ++; if (minStepValue == -1) return; if (stepValue < minStepValue) stepValue = minStepValue; if (stepValue > maxStepValue) stepValue = maxStepValue; if (minEndstopPin > -1) writeInput(minEndstopPin, stepValue != minStepValue); if (maxEndstopPin > -1) writeInput(maxEndstopPin, stepValue != maxStepValue); }
void sim_setup_main() { setupGui(); sim_setup(guiUpdate); adcSim* adc = new adcSim(); arduinoIOSim* arduinoIO = new arduinoIOSim(); stepperSim* xStep = new stepperSim(arduinoIO, X_ENABLE_PIN, X_STEP_PIN, X_DIR_PIN, INVERT_X_DIR); stepperSim* yStep = new stepperSim(arduinoIO, Y_ENABLE_PIN, Y_STEP_PIN, Y_DIR_PIN, INVERT_Y_DIR); stepperSim* zStep = new stepperSim(arduinoIO, Z_ENABLE_PIN, Z_STEP_PIN, Z_DIR_PIN, INVERT_Z_DIR); stepperSim* e0Step = new stepperSim(arduinoIO, E0_ENABLE_PIN, E0_STEP_PIN, E0_DIR_PIN, INVERT_E0_DIR); stepperSim* e1Step = new stepperSim(arduinoIO, E1_ENABLE_PIN, E1_STEP_PIN, E1_DIR_PIN, INVERT_E1_DIR); float stepsPerUnit[4] = DEFAULT_AXIS_STEPS_PER_UNIT; xStep->setRange(0, X_MAX_POS * stepsPerUnit[X_AXIS]); yStep->setRange(0, Y_MAX_POS * stepsPerUnit[Y_AXIS]); zStep->setRange(0, Z_MAX_POS * stepsPerUnit[Z_AXIS]); xStep->setEndstops(X_MIN_PIN, X_MAX_PIN); yStep->setEndstops(Y_MIN_PIN, Y_MAX_PIN); zStep->setEndstops(Z_MIN_PIN, Z_MAX_PIN); (new printerSim(xStep, yStep, zStep, e0Step, e1Step))->setDrawPosition(5, 70); e0Step->setDrawPosition(130, 100); e1Step->setDrawPosition(130, 110); (new heaterSim(HEATER_0_PIN, adc, TEMP_0_PIN))->setDrawPosition(130, 70); (new heaterSim(HEATER_1_PIN, adc, TEMP_1_PIN))->setDrawPosition(130, 80); (new heaterSim(HEATER_BED_PIN, adc, TEMP_BED_PIN, 0.2))->setDrawPosition(130, 90); // new sdcardSimulation("c:/models/", 5000); new sdcardSimulation("./models/", 5000); (new serialSim())->setDrawPosition(150, 0); #if defined(ULTIBOARD_V2_CONTROLLER) || defined(ENABLE_ULTILCD2) i2cSim* i2c = new i2cSim(); (new displaySDD1309Sim(i2c))->setDrawPosition(0, 0); (new ledPCA9632Sim(i2c))->setDrawPosition(1, 66); #endif #if defined(ULTIPANEL) && !defined(ULTIBOARD_V2_CONTROLLER) (new displayHD44780Sim(arduinoIO, LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7))->setDrawPosition(0, 0); #endif // Initialize sd card detect signal writeInput(SDCARDDETECT, !cardInserted); }
void Tutorial2::on_n_valueChanged( int value ) { writeInput( "n", value ); }
void guiUpdate() { for(unsigned int n=0; n<simComponentList.size(); n++) simComponentList[n]->tick(); if (SDL_GetTicks() - lastUpdate < 25) return; lastUpdate = SDL_GetTicks(); int clickX = -1, clickY = -1; SDL_Event event; while (SDL_PollEvent(&event)) { switch (event.type) { case SDL_KEYDOWN: key_delay = 0; break; case SDL_KEYUP: // If escape is pressed, quit if (event.key.keysym.sym == SDLK_ESCAPE) { FILE* f = fopen("eeprom.save", "wb"); fwrite(__eeprom__storage, sizeof(__eeprom__storage), 1, f); fclose(f); exit(0); } if (event.key.keysym.sym == SDLK_p) { SDL_Surface* tmpSurface = SDL_CreateRGBSurface(SDL_SWSURFACE, 128*SCALE,64*SCALE,32, 0, 0, 0, 0); SDL_Rect src = {SCALE, SCALE, 128*SCALE,64*SCALE}; SDL_Rect dst = {0, 0, 128*SCALE,64*SCALE}; SDL_BlitSurface(screen, &src, tmpSurface, &dst); char filename[128]; static int screenshotNr = 0; sprintf(filename, "screen%i.bmp", screenshotNr); screenshotNr++; SDL_SaveBMP(tmpSurface, filename); SDL_FreeSurface(tmpSurface); } break; case SDL_MOUSEMOTION: if (event.motion.state) { #ifdef ENABLE_ULTILCD2 lcd_lib_encoder_pos_interrupt += event.motion.xrel / 2; #endif } break; case SDL_MOUSEBUTTONDOWN: clickX = event.button.x; clickY = event.button.y; break; case SDL_QUIT: { FILE* f = fopen("eeprom.save", "wb"); fwrite(__eeprom__storage, sizeof(__eeprom__storage), 1, f); fclose(f); exit(0); } } } Uint8* keys = SDL_GetKeyState(NULL); writeInput(BTN_ENC, !keys[SDLK_RETURN]); if (keys[SDLK_RIGHT]) { if (key_delay == 0) { #ifdef ENABLE_ULTILCD2 lcd_lib_encoder_pos_interrupt+=2; #endif #ifdef ULTIPANEL encoderDiff+=2; #endif key_delay = KEY_REPEAT_DELAY; }else key_delay--; } if (keys[SDLK_LEFT]) { if (key_delay == 0) { #ifdef ENABLE_ULTILCD2 lcd_lib_encoder_pos_interrupt-=2; #endif #ifdef ULTIPANEL encoderDiff-=2; #endif key_delay = KEY_REPEAT_DELAY; }else key_delay--; } SDL_FillRect(screen, NULL, 0x000000); for(unsigned int n=0; n<simComponentList.size(); n++) simComponentList[n]->doDraw(); SDL_Rect rect; rect.w = 32; rect.h = 32; rect.x = 128 * SCALE + 32; rect.y = 32; if (clickX >= rect.x && clickX <= rect.x + rect.w && clickY >= rect.y && clickY <= rect.y + rect.h) cardInserted = !cardInserted; SDL_FillRect(screen, &rect, cardInserted ? 0x00FF00 : 0xFF0000); rect.y += 48; writeInput(SDCARDDETECT, !cardInserted); if (clickX >= rect.x && clickX <= rect.x + rect.w && clickY >= rect.y && clickY <= rect.y + rect.h) stoppedValue = !stoppedValue; writeInput(SAFETY_TRIGGERED_PIN, stoppedValue); SDL_FillRect(screen, &rect, stoppedValue ? 0x00FF00 : 0xFF0000); rect.y += 48; SDL_Flip(screen); }
int main(int argc, char *argv[]) { bool_t analyze_output, equilibria_only; int niter, nact; Atom *atom; Molecule *molecule; /* --- Read input data and initialize -- -------------- */ setOptions(argc, argv); getCPU(0, TIME_START, NULL); SetFPEtraps(); readInput(); spectrum.updateJ = TRUE; getCPU(1, TIME_START, NULL); readAtmos(&atmos, &geometry); if (atmos.Stokes) Bproject(); fillMesh(&geometry); readAtomicModels(); readMolecularModels(); SortLambda(); getBoundary(&atmos, &geometry); Background(analyze_output=TRUE, equilibria_only=FALSE); getProfiles(); initSolution(); initScatter(); getCPU(1, TIME_POLL, "Total initialize"); /* --- Solve radiative transfer for active ingredients -- --------- */ Iterate(input.NmaxIter, input.iterLimit); adjustStokesMode(atom); niter = 0; while (niter < input.NmaxScatter) { if (solveSpectrum(FALSE, FALSE) <= input.iterLimit) break; niter++; } /* --- Write output files -- ------------------ */ getCPU(1, TIME_START, NULL); writeInput(); writeAtmos(&atmos); writeGeometry(&geometry); writeSpectrum(&spectrum); writeFlux(FLUX_DOT_OUT); for (nact = 0; nact < atmos.Nactiveatom; nact++) { atom = atmos.activeatoms[nact]; writeAtom(atom); writePopulations(atom); writeRadRate(atom); writeCollisionRate(atom); writeDamping(atom); } for (nact = 0; nact < atmos.Nactivemol; nact++) { molecule = atmos.activemols[nact]; writeMolPops(molecule); } writeOpacity(); getCPU(1, TIME_POLL, "Write output"); printTotalCPU(); }