void input_state_first(u_char ch, struct input_ctx *ictx) { ictx->intermediate = '\0'; if (INPUT_C0CONTROL(ch)) { if (ch == 0x1b) input_state(ictx, input_state_escape); else input_handle_c0_control(ch, ictx); return; } #if 0 if (INPUT_C1CONTROL(ch)) { ch -= 0x40; if (ch == '[') input_state(ictx, input_state_sequence_first); else if (ch == ']') { input_start_string(ictx, STRING_SYSTEM); input_state(ictx, input_state_string_next); } else if (ch == '_') { input_start_string(ictx, STRING_APPLICATION); input_state(ictx, input_state_string_next); } else input_handle_c1_control(ch, ictx); return; } #endif if (INPUT_DELETE(ch)) return; input_handle_character(ch, ictx); }
void main(void) { printf("System enabled\n\r"); Motor_Init(PWM_PERIOD); enable_interrupts(INT_RDA); //enable_interrupts(INT_EXT0); //ext_int_edge(L_TO_H); while(true) { Set_Motor_Duty(0,0); while(!input_state(PIN_F6)&&!RUN )//&& !RUN) //While loop used for waiting an input high in D8 to start { output_toggle(PIN_E2); delay_ms(15); Read_Sensors_Digital(sensors_BIN); Get_Average_Center_Digital(sensors_BIN,2,12,¢er); printf("%c\n\r",(center+65)); } output_high(PIN_E2); delay_ms(2000); if(!RUN) RUN=0xFF; while(RUN){ //output_toggle(PIN_E2); Read_Sensors_Digital(sensors_BIN); Get_Average_Center_Digital(sensors_BIN,2,12,¢er); if(center==-1) center=last_center; Print_Center(center); last_center=center; error=SET_POINT-center; derivative=error-last_error; //if(derivative<-6||derivative>6) {derivative=0; error=last_error;} if(error>4 || error<-4) integral=integral+error; else integral=0; if(integral>100) integral=100; if(integral*(-1)>100) integral=-100; correction=error*(KP)+derivative*(KD)+integral*(KI); last_error=error; if(center>13 && center<19 && BoostCounter<24) { BoostCounter++; if(BoostCounter>3) base_speed=1400; //set_motor_pwm_duty(3,3,2500);correction=0 ;//Boost=499-BaseSpeed; } else { BoostCounter=0; base_speed=1000;//set_motor_pwm_duty(3,3,2650);} } left_correction=(base_speed)-correction; right_correction=(base_speed)+correction; Set_Motor_Duty(left_correction,right_correction); delay_us(delay_time); printf("%c\n\r",(center+65)); //for(i=2;i<=12;i++)printf("%d",Sensors_BIN[i]); //printf("%c\n",(center+65)); } } }
static int16_t core_input_state_poll(unsigned port, unsigned device, unsigned idx, unsigned id) { if (current_core.poll_type == POLL_TYPE_LATE) { if (!current_core.input_polled) input_poll(); current_core.input_polled = true; } return input_state(port, device, idx, id); }
int8 in_read_charlieplex_inputs() { int8 switches; output_drive(PI_CHARLIEPLEX_SWITCH_1_PIN); switches = input_state(PI_CHARLIEPLEX_SWITCH_3_PIN); switches <<= 1; switches |= input_state(PI_CHARLIEPLEX_SWITCH_2_PIN); output_high(PI_CHARLIEPLEX_SWITCH_1_PIN); output_float(PI_CHARLIEPLEX_SWITCH_1_PIN); output_low(PI_CHARLIEPLEX_SWITCH_1_PIN); output_drive(PI_CHARLIEPLEX_SWITCH_2_PIN); switches <<= 1; switches |= input_state(PI_CHARLIEPLEX_SWITCH_3_PIN); switches <<= 1; switches |= input_state(PI_CHARLIEPLEX_SWITCH_1_PIN); output_high(PI_CHARLIEPLEX_SWITCH_2_PIN); output_float(PI_CHARLIEPLEX_SWITCH_2_PIN); output_low(PI_CHARLIEPLEX_SWITCH_2_PIN); //Note: In this block charliplex1 must be read before charliplex2 // just to charliplex2 has enough time to recover because charliplex2 was // low in previous block. This avoid to put a delay here. output_drive(PI_CHARLIEPLEX_SWITCH_3_PIN); switches <<= 1; switches |= input_state(PI_CHARLIEPLEX_SWITCH_1_PIN); switches <<= 1; switches |= input_state(PI_CHARLIEPLEX_SWITCH_2_PIN); output_high(PI_CHARLIEPLEX_SWITCH_3_PIN); output_float(PI_CHARLIEPLEX_SWITCH_3_PIN); output_low(PI_CHARLIEPLEX_SWITCH_3_PIN); return ~switches; }
void input_state_escape(u_char ch, struct input_ctx *ictx) { /* Treat C1 control and G1 displayable as 7-bit equivalent. */ if (INPUT_C1CONTROL(ch) || INPUT_G1DISPLAYABLE(ch)) ch &= 0x7f; if (INPUT_C0CONTROL(ch)) { input_handle_c0_control(ch, ictx); return; } if (INPUT_INTERMEDIATE(ch)) { log_debug2(":: in1 %zu: %hhu (%c)", ictx->off, ch, ch); ictx->intermediate = ch; input_state(ictx, input_state_intermediate); return; } if (INPUT_PARAMETER(ch)) { input_state(ictx, input_state_first); input_handle_private_two(ch, ictx); return; } if (INPUT_UPPERCASE(ch)) { if (ch == '[') input_state(ictx, input_state_sequence_first); else if (ch == ']') { input_start_string(ictx, STRING_SYSTEM); input_state(ictx, input_state_string_next); } else if (ch == '_') { input_start_string(ictx, STRING_APPLICATION); input_state(ictx, input_state_string_next); } else { input_state(ictx, input_state_first); input_handle_c1_control(ch, ictx); } return; } if (INPUT_LOWERCASE(ch)) { input_state(ictx, input_state_first); input_handle_standard_two(ch, ictx); return; } input_state(ictx, input_state_first); }
void input_state_intermediate(u_char ch, struct input_ctx *ictx) { if (INPUT_INTERMEDIATE(ch)) { /* Multiple intermediates currently ignored. */ log_debug2(":: in2 %zu: %hhu (%c)", ictx->off, ch, ch); return; } if (INPUT_PARAMETER(ch)) { input_state(ictx, input_state_first); input_handle_private_two(ch, ictx); return; } if (INPUT_UPPERCASE(ch) || INPUT_LOWERCASE(ch)) { input_state(ictx, input_state_first); input_handle_standard_two(ch, ictx); return; } input_state(ictx, input_state_first); }
void input_init(struct window_pane *wp) { struct input_ctx *ictx = &wp->ictx; ARRAY_INIT(&ictx->args); ictx->string_len = 0; ictx->string_buf = NULL; memcpy(&ictx->cell, &grid_default_cell, sizeof ictx->cell); memcpy(&ictx->saved_cell, &grid_default_cell, sizeof ictx->saved_cell); ictx->saved_cx = 0; ictx->saved_cy = 0; input_state(ictx, input_state_first); }
int32 motores3(int32 pasos, int dir) { int32 y=0; int1 status=1; output_low(PIN_A1); //STEP (dir == 1)?output_high(PIN_A0):output_low(PIN_A0); delay_ms(100); for(y=0;y<pasos;y++) { output_low(PIN_A1); output_high(PIN_A1); status = input_state(PIN_A5); if (status == 0){ printf("status sensor ->%d<- \n\r",status); return y; } delay_us(200); } return y; }
int32 motores4(int32 pasos, int dir,int32 velocidad) { int32 y=0; int1 status=1; output_low(PIN_A1); //STEP (dir == 1)?output_high(PIN_A0):output_low(PIN_A0); delay_ms(velocidad); for(y=0;y<pasos;y++) { output_low(PIN_A1); output_high(PIN_A1); status = input_state(PIN_A5); if (status == 0){ printf("status sensor ->%d<- \n\r",status); return y; } delay_us(velocidad); } //printf("return pasos dados ->%Ld<- \n\r",y); return y; }
void in_encoder_read_and_update() { int1 channelA = input_state(PI_ENCODER_A_PIN); int1 channelB = input_state(PI_ENCODER_B_PIN); encoder_update( channelA, channelB ); }
//programa principal void main() { set_tris_A(0x00);/* 0000 0000 RA0 LED1 PIN 02 RA1 LED2 PIN 03 RA2 LED3 PIN 04 RA3 LED4 PIN 05 RA4 LED5 PIN 06 RA5 LED6 PIN 07 */ set_tris_B(0x00);/* (0000 0000) RB0 LED7 PIN 40 RB1 LED8 PIN 39 RB2 LED9 PIN 38 RB3 LED10 PIN 37 RB4 LED11 PIN 36 RB5 LED12 PIN 35 RB6 LED13 PIN 34 RB7 LED14 PIN 33 */ set_tris_C(0X00);/* RC0 ----- PIN 15 RC1 ----- PIN 16 RC2 ----- PIN 17 RC6 LED15 PIN 25 RC7 LED16 PIN 26 */ // Configuración de Leds 17 hasta 20 y Pulsadores 1 y 2 set_tris_D(0X00);/* RD0 SW01 PIN 19 --->Pulsador 1 RD1 SW02 PIN 20 --->Pulsador 2 RD2 ----- PIN 21 RD3 ----- PIN 22 RD4 LED17 PIN 27 RD5 LED18 PIN 28 RD6 LED19 PIN 29 RD7 LED20 PIN 30 */ set_tris_E(0x00);/* bits(**** 0000) RE0 ----- PIN 08 RE1 ----- PIN 09 RE2 ----- PIN 10 RE3 ----- PIN 01 */ //Habilitando y deshabilitando modulos... setup_timer_1(T1_disabled); setup_timer_2(T2_disabled,0,1); setup_timer_3(T3_disabled); setup_ccp1(CCP_OFF); setup_ADC(ADC_OFF); setup_VREF(FALSE);//no voltaje de referencia setup_COMPARATOR(NO_ANALOGS);// //limpie los puertos OUTPUT_A(0x00); OUTPUT_B(0x00); OUTPUT_C(0X00); OUTPUT_D(0X00); //limpiar registros, probar limpiar todos los registros en assembler con =0 //#ZERO_RAM limpiarRegistros(); /*condicional para lanzar secuencia cuando el pulsador esté presionado. */ output_float(SW01); output_float(SW02); while(TRUE) { if (input_state(SW01) == 1 && input_state(SW02) == 1) { secuencia1(); }else if (input_state(SW01) == 0 && input_state(SW02) == 1) { secuencia2(); }else if (input_state(SW01) == 1 && input_state(SW02) == 0) { secuencia4(); }else { } } //vuelva a inicio y vuelva y arranque reset_cpu(); }
//============================================================================================================ int main() { int N; //system size cout <<"set system size: "; cin >>N; int m; //total magnetization counted in multiples of 1 cout <<"set total magnetization (in multiples of 1/2): "; cin >>m; cout <<endl; bool testpos=0; //test the position finder of the states. Set to 1 for test. Hamiltonian testHam(N,m); //Test der Suchfunktion: if (testpos){ int pos=0; char* out; for(int i=0;i<testHam.get_dim();i++){ REP_TYPE state = testHam.get_basis_state(i); pos = testHam.find_state(state); out = int2bin(state,NULL); out = &(out[sizeof(REP_TYPE)*CHAR_BIT - N]); //cutoff string, borrowed from utilities.c cout <<"integer: " <<state<<" binary: "<<out<<" pos: "<<pos<<endl; } } cout <<"\n"; testHam.print_basis_list(); testHam.print_system_size(); testHam.print_basis_dimension(); cout <<"\n"; //GROUND STATE: Hamiltonian h1(N,m); h1.set_ham(1,0); //mu=1.1 h1.diagonalize(); Hamiltonian h2(N,m); h2.set_ham(4,0); h2.diagonalize(); plot_groundstate_quench(&h1,&h2,0.01,30); //state eingeben : char test[testHam.get_system_size()]; cout << "insert initial state:"<<endl; cin.ignore(); cin.getline(test,testHam.get_system_size()+1); cx_vec state=input_state(test,&testHam); cout <<"vector is: "<<endl; cout << state <<endl; testHam.set_ham(0,0); testHam.diagonalize(); plot_lohschmidt_echo(&testHam,state,0.01,50); /* double T=40; //60 double dt=0.1; //0.02 double mu=0; double lambda=0; while (lambda <= 1){ testHam.set_ham(mu,lambda); // mu=0,Lambda=0 cout <<endl<<"<><><><><><><><><><><><><><><><>diagonalisierung<><><><><><><><><><><><><><><>"<<endl<<endl; testHam.diagonalize(); plot_sz(&testHam,state,dt,T); T-=5; lambda+=0.1; } */ /*(kollision) mu=0; testHam.set_ham(mu,lambda); // mu=0,Lambda=0 cout <<endl<<"<><><><><><><><><><><><><><><><>diagonalisierung<><><><><><><><><><><><><><><>"<<endl<<endl; testHam.diagonalize(); plot_sz(&testHam,state,dt,T); mu=5; testHam.set_ham(mu,lambda); // mu=5,Lambda=0 cout <<endl<<"<><><><><><><><><><><><><><><><>diagonalisierung<><><><><><><><><><><><><><><>"<<endl<<endl; testHam.diagonalize(); plot_sz(&testHam,state,dt,T); */ /* (two string) mu+=1; while (mu <= 3){ testHam.set_ham(mu,lambda); // mu=0,Lambda=0 cout <<endl<<"<><><><><><><><><><><><><><><><>diagonalisierung<><><><><><><><><><><><><><><>"<<endl<<endl; testHam.diagonalize(); plot_sz(&testHam,state,dt,T); mu+=1; } */ //(kurzzeit) testHam.set_ham(0,0); cout <<endl<<"<><><><><><><><><><><><><><><><>diagonalisierung<><><><><><><><><><><><><><><>"<<endl<<endl; testHam.diagonalize(); plot_kurz_auto(&testHam,state,0.01,10); //plot_lohschmidt_echo(&testHam,state,0.01,10); //(ham,dt,T) //plot_szsz_n(&testHam,state,1,0.1,10); //(ham,n,dt,T) /* int i=0; for (;;){ cout << "enter component:"<<endl; cin.ignore(); cin >> i; cout << i<<" th spin is "<<get_sz(string_to_state(test,testHam.get_system_size()),i,testHam.get_system_size())*1/2.<<endl; } */ return 0; }