Exemple #1
0
int main(void)
{
    vuint32_t PulseNum = 0;
    
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    light_init();                                        /* LED灯初始化 */
    
    /* 初始化串口 */
    serial_initialize((intptr_t)(NULL));
    
    ftm_decoder_init(PTA8_9);

    printf("%s\n","FTM - PWM test!");
   
    while(1)
    {
        PulseNum = FTM_CNT_REG(FTM1_BASE_PTR); //读FTM1的CNT寄存器的值
        
        if(PulseNum > 5000)
        {
            light_change(LIGHT1);
        }
    }
    return 0;
}
Exemple #2
0
int main(void)
{
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    light_init();                                        /* LED灯初始化 */

    /* 初始化串口 */
    serial_initialize((intptr_t)(NULL));
    
    pit_init(PIT0, BUS_CLK_50000*1000); 
    pit_enable(PIT0);  
    
    printf("%s\n","PIT test!");

    /* 主循环 */
    while (1)
    {
        //主循环计数到一定的值,使小灯的亮、暗状态切换
        if (pit_count > 0)
        {
            light_change(LIGHT0);//指示灯的亮、暗状态切换
            pit_count = 0;
        }
        pit_enable(PIT0);
    } //end_while
}
Exemple #3
0
/* One start -----------------------------------------------------------------*/
static void startup()
{
    unsigned char err = 0;

    init_hardware();
    dbg_init();
    dbg_print_app_ver();
    crc32_init();
    pins_init();
    //spi0_init();    // used in m25pexx.c (FLASH)
    spi1_init();
    adc_init();
    err = memory_init();  // memory initialization, external EEPROM (used in pref.c, orion.c), external FLASH, internal FLASH
    if (err)
       goto err;
    pref_init();
    ds1390_init();
    evt_fifo_init();
    GPS_init();
    //SIM900_init();
    light_init();
    saveDatePorojectIP();//новые параметры связи
    vpu_init();  /*VPU start*/
    //Init_USB();
    //if (PROJ.jornal.power_on)
   //Event_Push_Str("СТАРТ");
    return;
err:
  Err_led(err);
}
Exemple #4
0
int main(int argc, char **argv)
{   
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    sys_timer_init();                                    /* 系统时钟初始化 */
    light_init();                                        /* LED灯初始化 */
    switch_init();                                       /* 开关初始化 */
    speaker_init();                                      /* 蜂鸣器初始化 */
    motor_init();                                        /* 电机初始化 */
    steer_init();                                        /* 舵机初始化 */
    decoder_init();                                      /* 编码器初始化 */
    serial_initialize((intptr_t)(NULL));                 /* 初始化串口 */
    //sd_init(&Fatfs);                                   /* 初始化SD卡,并创建文件 */
    //sd_create_file(&test_data, test_data_name);
    
    /* 命令注册 */
    help_cmd_initialize((intptr_t)(NULL));
    light_cmd_initialize((intptr_t)(NULL));
    switch_cmd_initialize((intptr_t)(NULL));
    speaker_cmd_initialize((intptr_t)(NULL));
    motor_cmd_initialize((intptr_t)(NULL));
    decoder_cmd_initialize((intptr_t)(NULL));
    control_cmd_initialize((intptr_t)(NULL));
    //sd_cmd_initialize((intptr_t)(NULL));

    printf("\n Welcome to k60 software platform!");
    printf("\n Press 'help' to get the help! \n");
    
    //light_open(LIGHT4); 

    /* ntshell测试 */
    task_ntshell((intptr_t)(NULL));
}
Exemple #5
0
/* initialize blue and opengl stuff */
void blue_gl_init(INITFUNC_ARGS){
    /* Blue type initialization */
    window_type = window_init(lib, Module);
    view_type   = view_init(lib, Module);
    layer_type  = layer_init(lib, Module);
    shape_type  = shape_init(lib, Module);
    image_type  = image_init(lib, Module);
    light_type  = light_init(lib, Module);
    text_type  = text_init(lib, Module);
}
Exemple #6
0
void board_init_devices(void) {
#if defined(ENVIRONMENT_SENSOR)
    kputs("Initializing i2c\n");
    i2c_init();

    kputs("Initializing Devices... Light,");
    light_init();
#ifdef REPORT_TYPE_GYRO
    kputs("Gyro, ");
    gyro_init();
#endif
#ifdef REPORT_TYPE_ACCEL
    kputs("Accell, ");
    accel_init();
#endif
#ifdef REPORT_TYPE_HUMID
    kputs("Humid, ");
    humid_init();
#endif
    kputs("PIR\n");
    pir_init();
#elif defined POWER_STRIP_MONITOR
    kputs("Initializing Devices... Power\n");
    powermon_init();
#endif

#ifdef USE_PN532
    kputs("Initializing RFID reader... \n");
    rfid_init();
#endif

#ifdef USE_MACHXO2_PMCO2
    kputs("Initializing CO2 and PM extension...\n");
    machxo2_init();
#endif

#ifdef USE_DOOR_SENSORS
    kputs("Initializing Door Sensors...\n");
    door_sensors_init();
#endif
}
/** \brief          Read current light's raw value
 * \return          EOF on error
 */
int16_t
sensor_light_get_raw()
{
  int16_t result;
  if (!light_initialized) {
    light_init();
  }
  /* Power up sensor */
  LIGHT_PORT |= (1 << LIGHT_BIT);

  /* Init ADC and measure */
  adc_init(ADC_CHAN_ADC4, ADC_TRIG_FREE_RUN, ADC_REF_AVCC, ADC_PS_128);
  adc_conversion_start();
  while ((result = adc_result_get(ADC_ADJ_RIGHT)) == EOF ){
    ;
  }
  adc_deinit();

  /* Power down sensor */
  LIGHT_PORT &= ~(1 << LIGHT_BIT);

  return result;
}
Exemple #8
0
int main(void)
{
    int32_t e_ftm_timer = 0;

    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    e_ftm_timer = ftm_timer_init(FTM0);
    light_init();                                        /* LED灯初始化 */

    /* 使能ftm定时器中断 */
    ftm_timer_enable(FTM0);

    /* 主循环 */
    while (1)
    {
        /* 主循环1s计数,使小灯的亮、暗状态切换 */
        if(ftm_count >= 1000)
        {
            ftm_count = 0;
            light_change(Light_Run_PORT,Light_Run2);
        } /* end_if */

    } /* end_while */
}
Exemple #9
0
/*************************** LIGHT CLASS FUNCTIONS ****************************/
LIGHT :: LIGHT(uint8_t priority) :scheduler_task("LIGHT", 2048, priority)
{
    light_init();
    setRunDuration(50); //run after every 50mS
}
Exemple #10
0
void* upm_light_init_str(const char* protocol, const char* params)
{
    fprintf(stderr, "String initialization - not implemented, using ain0: %s\n", __FILENAME__);
    return light_init(0);
}
Exemple #11
0
int run_simulation(struct simulation *sim)
{
struct device cell;
log_clear(sim);

printf_log(sim,_("Run_simulation\n"));

device_init(&cell);
cell.onlypos=FALSE;

dump_init(sim,&cell);

set_dump_status(sim,dump_stop_plot, FALSE);
set_dump_status(sim,dump_print_text, TRUE);


char temp[1000];

cell.kl_in_newton=FALSE;

//if (strcmp(outputpath,"")!=0) strcpy(get_output_path(sim),outputpath);

//if (strcmp(inputpath,"")!=0) strcpy(get_input_path(sim),inputpath);

dump_load_config(sim,&cell);

int i;
int z;
int x;
int y;


join_path(2,temp,get_output_path(sim),"error.dat");
remove(temp);

join_path(2,temp,get_output_path(sim),"equilibrium");
remove_dir(sim,temp);

join_path(2,temp,get_output_path(sim),"snapshots");
remove_dir(sim,temp);

join_path(2,temp,get_output_path(sim),"light_dump");
remove_dir(sim,temp);

join_path(2,temp,get_output_path(sim),"dynamic");
remove_dir(sim,temp);

join_path(2,temp,get_output_path(sim),"frequency");
remove_dir(sim,temp);



load_config(sim,&cell);

if (strcmp(sim->force_sim_mode,"")!=0)
{
	strcpy(cell.simmode,sim->force_sim_mode);
}

if (strcmp(cell.simmode,"opticalmodel@optics")!=0)
{
	solver_init(sim,cell.solver_name);
	newton_init(sim,cell.newton_name);

	printf_log(sim,_("Loading DoS for %d layers\n"),cell.my_epitaxy.electrical_layers);
	char tempn[100];
	char tempp[100];
	i=0;

	for (i=0;i<cell.my_epitaxy.electrical_layers;i++)
	{
		dos_init(&cell,i);
		printf_log(sim,"Load DoS %d/%d\n",i,cell.my_epitaxy.electrical_layers);
		sprintf(tempn,"%s_dosn.dat",cell.my_epitaxy.dos_file[i]);
		sprintf(tempp,"%s_dosp.dat",cell.my_epitaxy.dos_file[i]);
		load_dos(sim,&cell,tempn,tempp,i);
	}

	device_alloc_traps(&cell);

	if (get_dump_status(sim,dump_write_converge)==TRUE)
	{
	sim->converge = fopena(get_output_path(sim),"converge.dat","w");
	fclose(sim->converge);

	sim->tconverge=fopena(get_output_path(sim),"tconverge.dat","w");
	fclose(sim->tconverge);
	}

	mesh_cal_layer_widths(&cell);

	long double depth=0.0;
	long double percent=0.0;
	long double value=0.0;
	for (z=0;z<cell.zmeshpoints;z++)
	{
		for (x=0;x<cell.xmeshpoints;x++)
		{
			for (y=0;y<cell.ymeshpoints;y++)
			{

				depth=cell.ymesh[y]-cell.layer_start[cell.imat[z][x][y]];
				percent=depth/cell.layer_width[cell.imat[z][x][y]];
				cell.Nad[z][x][y]=get_dos_doping_start(&cell,cell.imat[z][x][y])+(get_dos_doping_stop(&cell,cell.imat[z][x][y])-get_dos_doping_start(&cell,cell.imat[z][x][y]))*percent;
			}
		}		
		
	}

	init_mat_arrays(&cell);




	for (z=0;z<cell.zmeshpoints;z++)
	{
		for (x=0;x<cell.xmeshpoints;x++)
		{
			for (y=0;y<cell.ymeshpoints;y++)
			{
				cell.phi[z][x][y]=0.0;
				cell.R[z][x][y]=0.0;
				cell.n[z][x][y]=0.0;
			}
		}
	}

	contacts_load(sim,&cell);

	cell.C=cell.xlen*cell.zlen*epsilon0*cell.epsilonr[0][0][0]/(cell.ylen+cell.other_layers);
	if (get_dump_status(sim,dump_print_text)==TRUE) printf_log(sim,"C=%Le\n",cell.C);
	cell.A=cell.xlen*cell.zlen;
	cell.Vol=cell.xlen*cell.zlen*cell.ylen;

	///////////////////////light model
	char old_model[100];
	gdouble old_Psun=0.0;
	old_Psun=light_get_sun(&cell.mylight);
	light_init(&cell.mylight);
	light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]);
	light_load_config(sim,&cell.mylight);

	if (cell.led_on==TRUE)
	{
		strcpy(old_model,cell.mylight.mode);
		strcpy(cell.mylight.mode,"ray");
	}
	
	light_load_dlls(sim,&cell.mylight);
	light_setup_ray(sim,&cell,&cell.mylight);

	if (cell.led_on==TRUE)
	{
		cell.mylight.force_update=TRUE;

		light_set_sun(&(cell.mylight),1.0);
		light_set_sun_delta_at_wavelength(&(cell.mylight),cell.led_wavelength);
		light_solve_all(sim,&(cell.mylight));
		
		cell.mylight.force_update=FALSE;
		strcpy(cell.mylight.mode,old_model);
		light_set_sun(&(cell.mylight),old_Psun);
		light_free_dlls(sim,&cell.mylight);
		light_load_dlls(sim,&cell.mylight);
	}
	///////////////////////

	//update_arrays(&cell);

	contact_set_all_voltages(sim,&cell,0.0);
	get_initial(sim,&cell);

	remesh_shrink(&cell);

	if (cell.math_enable_pos_solver==TRUE)
	{
		for (z=0;z<cell.zmeshpoints;z++)
		{
			for (x=0;x<cell.xmeshpoints;x++)
			{
				solve_pos(sim,&cell,z,x);
			}
		}
	}


	time_init(sim,&cell);

	cell.N=0;
	cell.M=0;

	solver_realloc(sim,&cell);



	plot_open(sim);


	cell.go_time=FALSE;

	plot_now(sim,"plot");
	//set_solver_dump_every_matrix(1);

	find_n0(sim,&cell);
	//set_solver_dump_every_matrix(0);
	draw_gaus(&cell);


	if (cell.onlypos==TRUE)
	{
		join_path(2,temp,get_output_path(sim),"equilibrium");
		dump_1d_slice(sim,&cell,temp);
		device_free(sim,&cell);
		device_free_traps(&cell);
		mesh_free(sim,&cell);
		return 0;
	}
}


//Load the dll
if (is_domain(cell.simmode)!=0)
{
	char gussed_full_mode[200];
	if (guess_whole_sim_name(sim,gussed_full_mode,get_input_path(sim),cell.simmode)==0)
	{
		printf_log(sim,"I guess we are using running %s\n",gussed_full_mode);
		strcpy(cell.simmode,gussed_full_mode);
	}else
	{
		ewe(sim,"I could not guess which simulation to run from the mode %s\n",cell.simmode);
	}


}

run_electrical_dll(sim,&cell,strextract_domain(cell.simmode));


if (strcmp(cell.simmode,"opticalmodel@optics")!=0)
{
	device_free(sim,&cell);
	device_free_traps(&cell);
	mesh_free(sim,&cell);
	plot_close(sim);

	for (i=0;i<cell.my_epitaxy.electrical_layers;i++)
	{
		dos_free(&cell,i);
	}
	solver_free_memory(sim,&cell);

	newton_interface_free(sim);
	light_free(sim,&cell.mylight);
}



return cell.odes;
}
Exemple #12
0
int main(int argc, char **argv)
{   
    uint8_t n = 1, p = 2, q = 0, f = 0;
    uint32_t e = 0;
    uint32_t test_time = 0;
    
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    sys_timer_init();                                    /* 系统时钟初始化 */
    light_init();                                        /* LED灯初始化 */
//    motor_init();
//    serial_initialize((intptr_t)(NULL));                 /* 初始化串口 */
    sd_init(&Fatfs);                                     /* 初始化SD卡,并创建文件 */
    sd_create_file(&test_data, test_data_name);           /* create a file */
    
//    printf("\n Welcome to k60 software platform! \n");
//    printf(" *** This is a test for SD module! *** \n");
//    light_open(LIGHT4);
//
//    printf(" \n>>>> The data will be writen into the SD card! \n");
    
//    for(test_time = 0;test_time < 65535; test_time++)
//    {
//        test_sd_data[test_time] = test_time;
//    }
    
    /* 写数据 */
    if (test_data.fs)
    {
        f_printf(&test_data, "Hello SD Card!\n");
        f_printf(&test_data, "This is a test!\n");
        f_printf(&test_data, "1 2 3 4 5 6 7 8 9\n");
        f_printf(&test_data, "~ ! # $ % ^ & * (\n");

//        for(test_time = 0;test_time < 65535; test_time++)
//        {
//            f_printf(&test_data, "%d\t", test_sd_data[test_time]);
//        }
    }
    f_printf(&test_data, "TEST OVER\n");

    sd_close_file(&test_data); /* 关闭文件 */
    
    //for(n=0;n<128;n++)
//    while(1)
//    {
//        SD_SendData(n);
//        SD_SendData(p);
//        SD_SendData(q);
//        SD_SendData(f);
//        SD_SendData(CRLF);
//
//        for(e = 0; e< 65535; e++);
//    }
//
//    printf(" \n>>>> A test for SD module is over!\n");
    while(1)
    {
        light_open(LIGHT6); 
    }
}
Exemple #13
0
void main()
{
	unsigned char i;
	unsigned char savemode;
	

	//
	// Core Hardware Initialization
	

	
	mcu_initialize();	// Initialize MCU resources and 8KHz interrupt...
	
	nvreadbuf();		// Load the NV buffer from flash (get badge Addr and properties)
	proc_btn1();		// Process Buttons
	
	sound_config_polled(); 		// Configure the sound subsystem chip
	




	etoh_init();			// Initialize the Alcohol Sensor Subsystem
	MRF49XA_Init();			// Initialize the RF tranceiver
	usb_ser_init(); 		// Initialize the serial port
	light_init();
	
	

	
	
	//
	// Preliminary setup and interaction
	// These setup a precurser items will occur prior to going into the main worker loop. 
	// This is mainly the one-time powerup and "boot" sequence
	//

    // Show the address of the badge on the LEDs (since there are only 7 LED's
    // the binary number will show in green if the badge is < 128 and red if >  
    // 128 with the badge addresses 0 and 128 showing up as nothing (typically illegal 
    // numbers anyway
    
    // Note, led_showbin does not interact with the interrupt driven light show well. 
    // So only use if you may not be in interrupt mode yet of if a show is not running
    delay_s(1);
    led_showbin(LED_SHOW_RED, nvget_badgetype() | 0x40); // Startup Indicator
    delay_10us(100);
    led_showbin(LED_SHOW_RED, 0);
    delay_s(1);
    led_showbin(LED_SHOW_RED, nvget_badgeperm() | 0x40); // Same
    delay_10us(100);
    led_showbin(LED_SHOW_RED, 0);
    delay_s(1);
    
    
    // 
    // Shows address as described above
    //
    MyBadgeID = nvget_badgeid();
    led_showbin(MyBadgeID & 0x80 ? LED_SHOW_RED : LED_SHOW_GRN, MyBadgeID & 0x7f );
    delay_s(TIME_ADDR);
    led_showbin(LED_SHOW_NONE, 0);
    
    init_rnd(nvget_badgetype()+1, MyBadgeID, 0x55); // Seed tha random number generator
    
    
    //
    // Perform POV credits (spin the badge on your wrist :)
    //
    led_pov(LED_SHOW_AUTO, TIME_POV);
    
    // Enable Global Interrupts
	// Use Interrupts. ISR is interrupt(), below	
	intcon.GIE=1;
    




	//sample_play();
	
	//delay_s(2);
	
	
	MyMode = MODE_IDLE;
	
	
	modelights();  // Sets lightshow based on a few state parameters

	
	// Calculate initial elevation time
	elevatemsecs = elapsed_msecs + ELEVATE_BASE + (unsigned long) rnd_randomize() * ELEVATE_VAR;

	
	
	// 
	// Main Worker Loop
	//	
	while(1) {
		//
		// Handle the elapsed time clocks
		//
		clear_bit(intcon, TMR0IE);
		loop_msecs = intr_msecs; // Take copy to avoid race conditions
		intr_msecs = 0;
		set_bit(intcon, TMR0IE);
		elapsed_msecs += loop_msecs; // Update elapsed time in msecs
		
		
		savemode = MyMode;	// Used to detact mode changes when command processers set new mode
		switch(MyMode) {
		  case MODE_IDLE:
		    // If button pressed, handle it
		    if(btn_commandwork(loop_msecs) == BTN_WORKING) {
				MyMode = MODE_GETCMD;
				modelights();
				playsong = 0;
				//light_pause();
				break;
		    }
		    // Look for incoming RF packet
		    if(MRF49XA_Receive_Packet(rfrxbuf,&rfrxlen) == PACKET_RECEIVED) {
				MRF49XA_Reset_Radio();
				//led_showbin(LED_SHOW_RED, 2);
				//delay_10us(10);
				//led_showbin(LED_SHOW_RED, 0);
				rfcmd_execute(rfrxbuf, rfrxlen);
		        
			}
			if(savemode != MyMode) {	// Don't process remainder of idle switch if state change
				break;
			}
			// If time to send a beacon, send it. Also process quorum sounds. 
			if(elapsed_msecs > (last_beacon + (unsigned long)BEACON_BASE +  ((unsigned long)rnd_randomize()* BEACON_RNDSCALE))) { // time for beacon
				rfcmd_3send(RFCMD_BEACON, MyBadgeID, nvget_socvec1());

				last_beacon = elapsed_msecs;
				rfcmd_clrcden();
				if(have_quorum) {
					if(rfcmd_getdensity() <= DENSITY_QUORUM_LO) {
						have_quorum = 0;
						 if(!playsong) tune_startsong(SONG_CHIRP2);
					}
				}
				else {
					if(rfcmd_getdensity() >= DENSITY_QUORUM_HI) {
						have_quorum = 1;
						if (!playsong) tune_startsong(SONG_303);
					}
				}
				modelights();
			}
			break;
		case MODE_ETOH:  // Run the alcohol sensor state machine
		  if(etoh_breathtest(ETOH_DOWORK,  loop_msecs ) == ETOH_DONE) {  // worker for ETOH
			switch(etoh_getreward()) {
			  case REWARD_SOBER:
			    tune_startsong(SONG_BUZZER);
			    break;
			  case REWARD_TIPSY: 
			    tune_startsong(SONG_PEWPEW);
			    break;
			  case REWARD_DRUNK:
			    tune_startsong(SONG_CACTUS);
			    break;
			    
			 }
			 MyMode = MODE_IDLE;
		 
			 light_show(LIGHTSHOW_SOCFLASH, 5);
			 break;	 
	      }
	      break;
	    case MODE_ATTEN:
	        // Puts all badges into visual attention mode to see who's in range
	        if(MyMode != lastmode) {
				attelapsed  = 0;
			}
			attelapsed += loop_msecs;
			if(attelapsed > 120000) {	// Stays there 2 min (should be in #def)
				MyMode = MODE_IDLE;
			}
			
			if(MRF49XA_Receive_Packet(rfrxbuf,&rfrxlen) == PACKET_RECEIVED) {
				MRF49XA_Reset_Radio();
			
				rfcmd_execute(rfrxbuf, rfrxlen);
		        
			}
			modelights();
	      break;
	    case MODE_GETCMD:
	      if (btn_commandwork( loop_msecs) != BTN_WORKING) {
			MyMode = MODE_IDLE;
			modelights();
		  }
	      break;	     
		    
		} // switch
		  
		tune_songwork();					// Worker thread for songs				 
		light_animate(loop_msecs);			// worker thread for lights
		
		if(MyElev) {	// Handle the privilege elevation timer
			if(elapsed_msecs > (elevatemsecs + ELEVATE_DUR)) {
			    MyElev = 0;
			    elevatemsecs = elapsed_msecs + ELEVATE_BASE + (unsigned long) rnd_randomize() * ELEVATE_VAR;
			    modelights();
			}
		} else {
			if(elapsed_msecs > elevatemsecs) {
				MyElev = 1;
				sample_play();
				modelights();
			}
		}

				
		lastmode = MyMode;
		
	}	
	
    	
}
Exemple #14
0
int main(int argc, char **argv)
{   
    uint32_t buff_r;
    FRESULT res;
    uint32_t n = 0, j = 0;
    int32_t y_temp = -1;
    int temp = 0;
    uint32_t time[64];
    uint32_t time_temp[4];
    uint32_t time_start = 0;
    uint32_t time_end = 0;
    
    /* 模块初始化 */
    exc_init();                                          /* 中断初始化 */
    sys_timer_init();                                    /* 系统时钟初始化 */
    light_init();                                        /* LED灯初始化 */
    serial_initialize((intptr_t)(NULL));                 /* 初始化串口 */
    sd_init(&Fatfs);                                     /* 初始化SD卡,并创建文件 */
    sd_create_file(&image_data, image_data_name);        /* create a file */
    
    printf("\n Welcome to k60 software platform! \n");
    light_open(LIGHT4); 

    res = f_open(&image_data, "0:DATA.TXT", FA_OPEN_EXISTING | FA_READ);
    res = f_read(&image_data, buffer, sizeof(buffer), &buff_r);  
   
//////    for(n=0; n<64; n++)
//////    {
//////        for(j=0;j<4;j++)
//////        {    
//            sys_timer_read(&time_start);
            compress_image();
//            sys_timer_read(&time_end);     
//////
//////            time_temp[j] = time_start - time_end;         
//////
//////        }
//////        time[n] = (time_temp[0] +time_temp[1]+time_temp[2]+time_temp[3])/4;
//////    }
//    
    res = f_open(&image_data, "0:A_IMAGE.TXT", FA_OPEN_EXISTING | FA_WRITE);
//    /* 取出制表符 */
//    if (image_data.fs)
//    {
//        for (n = 0; n < ((12800*2) +100) ; n++)
//        {
//            if((buffer[n] == '0') || (buffer[n] == '1'))
//            f_printf(&image_data, "%c", buffer[n]);        
//        }
//    }
//    /* 写原始数据 */
////    if (image_data.fs)
////    {
////        for (n = 0; n < 12800 ; n++)
////        {
////            if(n%128 == 0)
////            {
////                y_temp ++;
////            }
////            
////            if(buffer[n]  == '0')
////            {
////                f_printf(&image_data, "%d\t", (n%128));
////                f_printf(&image_data, "%d\n", y_temp);      
////            }
////        }
////    }
    /* 写压缩后图像 */
//    if (image_data.fs)
//    {
//        for (n = gl_SRNum; n >0 ; n--)
//        {
//            f_printf(&image_data, "%d\t%d\n", 
//                    (int)StrRoadFind[n].CenterX, (int)StrRoadFind[n].CenterY);      
//        }
//    }
    for (n = 0; n <12800 ; n++)
    {
       buffer[n] = 0;   
    }
    for (n = gl_SRNum; n >0 ; n--)
    {
        if((int)StrRoadFind[n].Width<12)
        buffer[(int)StrRoadFind[n].CenterY * 128 + (int)StrRoadFind[n].CenterX] = 1;    
    }
    
    if (image_data.fs)
    {
        for (n = 12800; n >0 ; n--)
        {
            if(n%128 == 0)
            {
                f_printf(&image_data, "\n%d\t", (int)buffer[n]);      
            }
            else
            {
                f_printf(&image_data, "%d\t", (int)buffer[n]);      
            }
            
        }
    }

//    for (n = gl_SRNum; n > 0; n--)
//    {
//        printf("%d\t%d\n", (int) StrRoadFind[n].CenterX,
//                (int) StrRoadFind[n].CenterY);
//    }
//    printf("time cost is %d\n", (time_start - time_end)/100);

////    for(n=0;n<64;n++)
////    {
////        f_printf(&image_data, "%d\t%d\n", 
////                            n, time[n]);  
////    }
////
//    f_printf(&image_data, "COMPRESS OVER");
//    sys_timer_read(&time_start);
//    find_road();
//    sys_timer_read(&time_end);
    //printf("time cost is %d\n", (time_start - time_end)/100);
    
    sd_close_file(&image_data); /* 关闭文件 */
    
    while(1)
    {
        light_open(LIGHT6); 
    }
}
Exemple #15
0
//extern void drawModelSetMax(void);
int glInit(void){
	cvar_register(&cvar_gl_MSAA_Samples);
	cvar_pset(&cvar_gl_MSAA_Samples, "0");
//	console_printf("cvar id is %i\n", cvar_gl_MSAA_Samples.myid);
//	console_printf("cvar name is %s\n", cvar_gl_MSAA_Samples.name);
//	console_printf("cvar value is %s\n", cvar_gl_MSAA_Samples.valuestring);
	glewExperimental = TRUE;
	GLenum glewError = glewInit();
	CHECKGLERROR
	if(glewError != GLEW_OK){
		console_printf("ERROR with the glew: %s\n", glewGetErrorString(glewError));
		return FALSE;
	}
	shader_init();
	CHECKGLERROR
	if(!shader_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	texture_init();
	CHECKGLERROR
	if(!texture_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	framebuffer_init();
	CHECKGLERROR
	if(!framebuffer_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
	vbo_init();
	CHECKGLERROR
	if(!vbo_ok){
		return FALSE;
		//todo call some sort of shutdown of everything
	}
	ubo_init();
	CHECKGLERROR
	if(!ubo_ok){
		return FALSE;
		//todo call some sort of shutdown of everything
	}
	anim_init();
	CHECKGLERROR
	if(!anim_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	model_init();
	CHECKGLERROR
	if(!model_ok){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
/*
	initParticleSystem(128);
	if(!particlesOK){
		//todo call some sort of shutdown of everything
		 return FALSE;
	}
*/
	light_init();
	CHECKGLERROR
	if(!light_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	lighttile_init();
	CHECKGLERROR
	if(!lighttile_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	viewport_init();
	CHECKGLERROR
	if(!viewport_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	text_init();
	CHECKGLERROR
	if(!text_ok){
		//todo call some sort of shutdown of everything
		return FALSE;
	}
	rendermodel_init();
	CHECKGLERROR
	//todo errorcheck
	drawbb_init();
	CHECKGLERROR
	//todo errorcheck

	states_enableForce(GL_MULTISAMPLE);
	glClearDepth(1.0);
	glClearColor(0.0, 0.0, 0.0, 0.0);
	CHECKGLERROR
//	states_disableForce(GL_FOG);
	states_enableForce(GL_DEPTH_TEST);
	CHECKGLERROR
//	glDepthFunc(GL_LESS);
	states_depthFunc(GL_LESS);
	states_enableForce(GL_CULL_FACE);
	states_cullFace(GL_BACK);
//	states_depthMask(GL_TRUE);

	int maxSamples = 0, maxIntSamples = 0, maxColorTextureSamples = 0, maxDepthTextureSamples = 0;
	glGetIntegerv(GL_MAX_SAMPLES, &maxSamples);
	glGetIntegerv(GL_MAX_INTEGER_SAMPLES, &maxIntSamples);
	glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &maxColorTextureSamples);
	glGetIntegerv(GL_MAX_DEPTH_TEXTURE_SAMPLES, &maxDepthTextureSamples);
	maxMSAASamples = maxSamples;
	if(maxIntSamples < maxMSAASamples) maxMSAASamples = maxIntSamples;
	if(maxColorTextureSamples < maxMSAASamples) maxMSAASamples = maxColorTextureSamples;
	if(maxDepthTextureSamples < maxMSAASamples) maxMSAASamples = maxDepthTextureSamples;
	console_printf("Max multisample samples: %i\n", maxMSAASamples);


	cam = createAndAddViewportRPOINT("cam", 1);
	camid = cam->myid;
	cam->outfbid = findFramebufferByNameRINT("screen");

	unsigned char dflags[] = {3, 7, 3};
//	unsigned char drb = FRAMEBUFFERRBFLAGSDEPTH| 2;
	unsigned char drb = FRAMEBUFFERRBFLAGSDEPTH;
	unsigned char dcount = 3;
	cam->dfbid = createAndAddFramebufferRINT("screend", dcount, drb, dflags);
	resizeViewport(cam, 800, 600);
	screenWidth = 800;
	screenHeight = 600;

	glGenBuffers(1, &instancevbo);
	glGenBuffers(1, &instancevbo2);

	//temporary
	CHECKGLERROR
	vbo_t * tvbo = createAndAddVBORPOINT("text", 2);
	textvbo = tvbo->myid;
	textshaderid = shader_createAndAddRINT("text");
	fsblendshaderid = shader_createAndAddRINT("fsblend");
	depthonlyid = shader_createAndAddRINT("depthmodel");
	forwardmodelid = shader_createAndAddRINT("forwardmodel");
	fsquadmodel = model_findByNameRINT("fsquad");

	readyRenderQueueBuffers();



	return TRUE; // so far so good
}
Exemple #16
0
int main(int argc, char **argv)
{
	int robot_state = FORWARD;
	int last_robot_state = FORWARD;
	int front_infrared_value = 0;
	int back_infrared_value = 0;
	int front_infrared_num = 0;
	int back_infrared_num = 0;
	int front_infrared_amount = 0;
	int back_infrared_amount = 0;
	int front_infrared_weight = 0;
	int back_infrared_weight = 0;
	uint32_t car_distence = 0;
	uint8_t get_char = 0;
	int change_num = 0;
	bool_t switch_state = 0;
	int detect_num = 0;
	int angle = 0;

	/* 模块初始化 */
	exc_init(); /* 中断初始化 */
	sys_timer_init(); /* 系统时钟初始化 */
	light_init(); /* 灯初始化 */
	switch_init(); /* 开关初始化 */
	serial_initialize((intptr_t) (NULL)); /* 初始化串口 */
	motor_init(); /* 电机初始化 */
	steer_init(); /* 舵机初始化 */
	decoder_init((intptr_t) (NULL)); /* 编码器初始化 */
	infrared_init(); /* 红外初始化 */

	while(1)
	{
		light_open(LIGHT2);
		light_open(LIGHT3);
	}
//    gpio_init(PORT_NO_GET(PTC0), PIN_NO_GET(PTC0), OUT_PUT, 0);
//    gpio_init(PORT_NO_GET(PTC2), PIN_NO_GET(PTC2),OUT_PUT, 1);
//    while(1)
//    {
//    	motor_output(MOTOR_LEFT, 50);
//    	motor_output(MOTOR_RIGHT, 50);
//    }

	while((get_char != 's') && (switch_state != SWITCH_ON))
	{
		 light_open_some(0x0f);
		 get_char = serial_get_char(UART_NO_GET(UART_NO));
		 switch_state = switch_read(SWITCH0);
	}

	while (1)
	{
		get_char = serial_get_char(UART_NO_GET(UART_NO));
		if(get_char == 'p')
		{
			last_robot_state = robot_state;
			robot_state = STOP;
		}

		/* 读取光电管的数据 */
		front_infrared_value = infrared_read_loc(INFRARED_FRONT);
		back_infrared_value = infrared_read_loc(INFRARED_BACK);

		/* 读取红外从右第一个亮灯的位置 */
		front_infrared_num = infrared_read_num(front_infrared_value);
		back_infrared_num = infrared_read_num(back_infrared_value);

		/* 读取传感器亮灯的总数 */
		front_infrared_amount = infrared_read_amount(front_infrared_value);
		back_infrared_amount = infrared_read_amount(back_infrared_value);

		/* 读取权值 */
		front_infrared_weight = infrared_read_weight(front_infrared_value);
		back_infrared_weight = infrared_read_weight(back_infrared_value);

		switch (robot_state)
		{
/**********************************前进*************************************/
		case FORWARD:
			light_open_some(0x01);
			light_bar_open(LIGHT_BAR0);
			light_bar_close(LIGHT_BAR1);
			if (front_infrared_amount == 1)
			{
				if (front_infrared_weight == 3)
				{
					angle = 40;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -3)
				{
					angle = -40;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 2)
				{
					angle = 20;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -2)
				{
					angle = -20;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 1)
				{
					angle = 5;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -1)
				{
					angle = -5;
					//motor_output2(13, 13);
				}
			}
			else if (front_infrared_amount == 2)
			{
				if (front_infrared_weight == 5)
				{
					angle = 30;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -5)
				{
					angle = -30;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 3)
				{
					angle = 10;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == -3)
				{
					angle = -10;
					//motor_output2(13, 13);
				}
				else if (front_infrared_weight == 0)
				{
					angle = 0;
					//motor_output2(13, 13);
				}
			}
			steer_output_angle(STEER_DIR, angle);
			speed_control_forward(30,angle);

			if (front_infrared_amount > 4)
			{
				if(change_num == 4)
				{
					robot_state = STOP;
				}

				detect_num ++;
				if(detect_num > 2)
				{
					detect_num = 0;
					robot_state = FORWARD_CHANGE;
					car_distence = gl_distanceTotal;
				}
			}
			else
			{
				detect_num = 0;
			}
			break;

/**********************************前进转换1*************************************/
		case FORWARD_CHANGE:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x02);
			steer_output_angle(STEER_DIR, 40);
			//motor_output2(-25, -10);
			speed_control_backward(30,angle);

            if((gl_distanceTotal - car_distence)>9)
            {
            	robot_state = FORWARD_CHANGE2;
            }
		    break;

/**********************************前进转换2*************************************/
		case FORWARD_CHANGE2:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x02);
			steer_output_angle(STEER_DIR, 40);
			//motor_output2(-25, -10);
			speed_control_backward(30,angle);
			if((back_infrared_value & 0x30) && (!(back_infrared_value & 0x03)) && (front_infrared_amount < 3))
			{
				robot_state = BACKWARD;
				car_distence = gl_distanceTotal;
				change_num ++;
			}
			break;

/************************************后退****************************************/
		case BACKWARD:
			light_bar_open(LIGHT_BAR1);
			light_bar_close(LIGHT_BAR0);
			light_open_some(0x04);
			if (back_infrared_amount == 1)
			{
				if (back_infrared_weight == 3)
				{
					angle = -40;
					//motor_output2(-5, -22);
				}
				else if (back_infrared_weight == -3)
				{
					angle = 40;
					//motor_output2(-22, -5);
				}
				else if (back_infrared_weight == 2)
				{
					angle = -40;
					//motor_output2(-5, -20);
				}
				else if (back_infrared_weight == -2)
				{
					angle = 40;
					//motor_output2(-20, -5);
				}
				else if (back_infrared_weight == 1)
				{
					angle = -5;
					//motor_output2(-14, -14);
				}
				else if (back_infrared_weight == -1)
				{
					angle = 5;
					//motor_output2(-14, -14);
				}
			}
			else if (back_infrared_amount == 2)
			{
				if (back_infrared_weight == 5)
				{
					angle = -40;
					//motor_output2(-5, -20);
				}
				else if (back_infrared_weight == -5)
				{
					angle = 40;
					//motor_output2(-20, -5);
				}
				else if (back_infrared_weight == 3)
				{
					angle = -20;
					//motor_output2(-5, -20);
				}
				else if (back_infrared_weight == -3)
				{
					angle = 20;
					//motor_output2(-20, -5);
				}
				else if (back_infrared_weight == 0)
				{
					angle = 0;
					//motor_output2(-14, -14);
				}
			}
			steer_output_angle(STEER_DIR, angle);
			speed_control_backward(30,angle);

			if(back_infrared_amount > 4)
			{
				detect_num ++;
				if(detect_num > 2)
				{
					detect_num = 0;
					robot_state = BACKWARD_CHANGE;
					car_distence = gl_distanceTotal;
				}
			}
			else
			{
				detect_num  = 0;
			}
			break;

/************************************后退转换1****************************************/
		case BACKWARD_CHANGE:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x8);
			steer_output_angle(STEER_DIR, -35);
			speed_control_forward(30,angle);
            if((gl_distanceTotal - car_distence)>7)
            {
            	robot_state = BACKWARD_CHANGE2;
            }
		    break;

/************************************后退转换2****************************************/
		case BACKWARD_CHANGE2:
			light_bar_open(LIGHT_BAR0);
			light_bar_open(LIGHT_BAR1);
			light_open_some(0x8);
			steer_output_angle(STEER_DIR, -35);
			speed_control_forward(30,angle);
			if((front_infrared_value & 0x38) && (!(front_infrared_value & 0x03)) && (back_infrared_amount < 3))
			{
				robot_state = FORWARD;
				change_num ++;
			}
			break;

/************************************停车****************************************/
		case STOP:
			light_open_some(0x03);
			light_bar_close(LIGHT_BAR0);
			light_bar_close(LIGHT_BAR1);
			motor_output2(0, 0);
			steer_output_angle(STEER_DIR, 0);
			if(get_char == 's')
			{
				robot_state = last_robot_state;
			}
			break;
		}
	}
}
Exemple #17
0
int main(int argc, char **argv)
{
    uint8_t speaker_no = 0;
    uint8_t speaker_total_no = 2;
    uint8_t get_char = 0;
    uint8_t n = 0;
    ER speaker_msg = 0;

    /* 模块初始化 */
    // exc_init();                                          /* 中断初始化 */
    //sys_timer_init();                                    /* 系统时钟初始化 */
    speaker_init();                                      /* 蜂鸣器初始化 */
    light_init();
    //serial_initialize((intptr_t)(NULL));                 /* 初始化串口 */

    // printf("\n Welcome to k60 software platform! \n");

    while(1)
    {
        speaker_msg = speaker_close(SPEAKER0);
        light_open(LIGHT0);
    }
    //printf(" *** This is a test for speaker module! *** \n");

    // printf(" \n>>>> The speaker will be ringing! \n");
//        for(speaker_no = 0; speaker_no < speaker_total_no; speaker_no++)
//        {
//            delay(200);
//            switch (speaker_no)
//            {
//                case 0:
//                    speaker_msg = speaker_open(SPEAKER0);
//                    break;
//                case 1:
//                    speaker_msg = speaker_open(SPEAKER1);
//                    break;
//                default:
//                    //printf("The speaker number is error!\n");
//                    break;
//
//            }
//            if (speaker_msg == E_ID)
//            {
//                //printf(" The ID of speaker%d is error!\n", speaker_no);
//            }
//            else if (speaker_msg == E_ILUSE)
//            {
//               // printf(" The port of speaker%d is not open!\n", speaker_no);
//            }
//            else
//            {
//               // printf(" The speaker%d is ringing now!\n", speaker_no);
//            }
//        }
//
//        //printf(" \n>>>> The speaker will be not ringing! \n");
//        for (speaker_no = 0; speaker_no < speaker_total_no; speaker_no++)
//        {
//            delay(200);
//            switch (speaker_no)
//            {
//                case 0:
//                    speaker_msg = speaker_close(SPEAKER0);
//                    break;
//                case 1:
//                    speaker_msg = speaker_close(SPEAKER1);
//                    break;
//                default:
//                    //printf("The speaker number is error!");
//                    break;
//
//            }
//            if (speaker_msg == E_ID)
//            {
//               // printf(" The ID of speaker%d is error !\n", speaker_no);
//            }
//            else if (speaker_msg == E_ILUSE)
//            {
//                //printf(" The port of speaker%d is not open!\n", speaker_no);
//            }
//            else
//            {
//                //printf(" The speaker%d is not ringing now!\n", speaker_no);
//            }
//        }
//
//        //printf(" \n>>>> The speaker will change frequence! \n");
//
//        for(n=0;n<10;n++)
//        {
//            delay(10);
//            if(speaker_read(SPEAKER0))
//            {
//                speaker_close(SPEAKER0);
//            }
//            else
//            {
//                speaker_open(SPEAKER0);
//            }
//        }
//        for(n=0;n<10;n++)
//        {
//            delay(5);
//            if(speaker_read(SPEAKER0))
//            {
//                speaker_close(SPEAKER0);
//            }
//            else
//            {
//                speaker_open(SPEAKER0);
//            }
//        }
//        for(n=0;n<20;n++)
//        {
//            delay(1);
//            if(speaker_read(SPEAKER0))
//            {
//                speaker_close(SPEAKER0);
//            }
//            else
//            {
//                speaker_open(SPEAKER0);
//            }
//        }
//        for(n=0;n<10;n++)
//        {
//            delay(10);
//            if(speaker_read(SPEAKER0))
//            {
//                speaker_close(SPEAKER0);
//            }
//            else
//            {
//                speaker_open(SPEAKER0);
//            }
//        }
//        for(n=0;n<10;n++)
//        {
//            delay(20);
//            if(speaker_read(SPEAKER0))
//            {
//                speaker_close(SPEAKER0);
//            }
//            else
//            {
//                speaker_open(SPEAKER0);
//            }
//        }
//
//        speaker_close(SPEAKER0);
//       // printf(" \n>>>> A test for speaker module is over!\n");
//        while (1)
//        {
//           // printf(" \n>>>> Press 'n' to test once more.\n");
//            serial_rea_dat(NTSHELL_PORTID, &get_char, 1);
//
//            if (get_char == 'n')
//            {
//               // printf("Once more \n");
//                delay(200);
//                break;
//            }
//        }
//    }

}
Exemple #18
0
int main(int argc, char *argv[])
{
    cal_path();
    setlocale(LC_MESSAGES, "");
    bindtextdomain("opvdm", get_lang_path());
    textdomain("opvdm");

    timer_init(0);
    timer_init(1);
    dbus_init();
    set_ewe_lock_file("", "");
    cell.onlypos = FALSE;

    char pwd[1000];
    if (getcwd(pwd, 1000) == NULL) {
        ewe("IO error\n");
    }

    dump_init(&cell);
    dump_load_config(&cell);

    remove("snapshots.zip");
    remove("light_dump.zip");

    hard_limit_init();

//char path[PATH_MAX];
//char dest[PATH_MAX];
//pid_t pid = getpid();
//sprintf(path, "/proc/%d/exe", pid);

//if (readlink(path, dest, PATH_MAX) == -1)
//{
//      printf("error\n");
//      exit(1);
//}
//  char *base = strrchr(dest, '/');
//*base='/';
//*(base+1)=0;
    set_plot_script_dir(pwd);

//set_plot_script_dir(char * in)
    if (scanarg(argv, argc, "--help") == TRUE) {
        printf("opvdm_core - Organic Photovoltaic Device Model\n");
        printf(copyright);
        printf("\n");
        printf("Usage: opvdm_core [options]\n");
        printf("\n");
        printf("Options:\n");
        printf("\n");
        printf("\t--outputpath\toutput data path");
        printf("\t--inputpath\t sets the input path\n");
        printf("\t--version\tdisplays the current version\n");
        printf("\t--zip_results\t zip the results\n");
        printf("\t--optics\t runs only optical simulation\n");
        printf("\t--cpus\t sets the number of CPUs\n");
        printf("\n");
        printf
        ("Additional information about opvdm is available at www.opvdm.com.\n");
        printf("\n");
        printf
        ("Report bugs to: [email protected]\n\n");
        exit(0);
    }
    if (scanarg(argv, argc, "--version") == TRUE) {
        printf("opvdm_core, Version %s\n", opvdm_ver);
        printf(copyright);
        printf(this_is_free_software);
        printf
        ("There is ABSOLUTELY NO WARRANTY; not even for MERCHANTABILITY or\n");
        printf("FITNESS FOR A PARTICULAR PURPOSE.\n");
        printf("\n");
        exit(0);
    }

    if (geteuid() == 0) {
        ewe("Don't run me as root!\n");
    }

    set_dump_status(dump_stop_plot, FALSE);
    set_dump_status(dump_print_text, TRUE);

    set_io_dump(FALSE);
    srand(time(0));
    textcolor(fg_green);
    randomprint(_("Organic Photovoltaic Device Model (www.opvdm.com)\n"));
    randomprint(_
                ("You should have received a copy of the GNU General Public License\n"));
    randomprint(_
                ("along with this software.  If not, see www.gnu.org/licenses/.\n"));
    randomprint("\n");
    randomprint(_
                ("If you wish to collaborate in anyway please get in touch:\n"));
    randomprint(_("[email protected]\n"));
    randomprint(_("www.roderickmackenzie.eu/contact.html\n"));
    randomprint("\n");
    textcolor(fg_reset);

    globalserver.on = FALSE;
    globalserver.cpus = 1;
    globalserver.readconfig = TRUE;

    if (scanarg(argv, argc, "--outputpath") == TRUE) {
        strcpy(sim_output_path(),
               get_arg_plusone(argv, argc, "--outputpath"));
    } else {
        strcpy(sim_output_path(), pwd);
    }

    if (scanarg(argv, argc, "--inputpath") == TRUE) {
        strcpy(sim_input_path(),
               get_arg_plusone(argv, argc, "--inputpath"));
    } else {
        strcpy(sim_input_path(), sim_output_path());
    }

    dump_load_config(&cell);

    if (scanarg(argv, argc, "--onlypos") == TRUE) {
        cell.onlypos = TRUE;
    }

    char name[200];
    struct inp_file inp;
    inp_init(&inp);
    inp_load_from_path(&inp, sim_input_path(), "ver.inp");
    inp_check(&inp, 1.0);
    inp_search_string(&inp, name, "#core");
    inp_free(&inp);

    if (strcmp(name, opvdm_ver) != 0) {
        printf
        ("Software is version %s and the input files are version %s\n",
         opvdm_ver, name);
        exit(0);
    }

    gui_start();
    if (scanarg(argv, argc, "--optics") == FALSE)
        server_init(&globalserver);

    if (scanarg(argv, argc, "--lock") == TRUE) {
        server_set_dbus_finish_signal(&globalserver,
                                      get_arg_plusone(argv, argc,
                                              "--lock"));
    }

    int ret = 0;

    int do_fit = FALSE;

    if (scanarg(argv, argc, "--fit") == TRUE)
        do_fit = TRUE;

    FILE *f = fopen("fit.inp", "r");
    if (f != NULL) {
        fclose(f);
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "fit.inp");
        int fit_temp;
        inp_search_int(&inp, &fit_temp, "#do_fit");
        if (fit_temp == 1) {
            do_fit = TRUE;
        }

        inp_free(&inp);
    }

    if (do_fit == TRUE) {
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_print_text, FALSE);
        set_dump_status(dump_iodump, FALSE);
        set_dump_status(dump_optics, FALSE);
        set_dump_status(dump_newton, FALSE);
        set_dump_status(dump_plot, FALSE);
        set_dump_status(dump_stop_plot, FALSE);
        set_dump_status(dump_opt_for_fit, FALSE);
        set_dump_status(dump_print_newtonerror, FALSE);
        set_dump_status(dump_print_converge, FALSE);
        set_dump_status(dump_print_pos_error, FALSE);
        set_dump_status(dump_lock, TRUE);
    }
#include "main_args.c"
    if (scanarg(argv, argc, "--optics") == TRUE) {
        gui_start();
        struct light two;
        light_init(&two, &cell, pwd);
        //light_set_dx(&cell.mylight,cell.ymesh[1]-cell.ymesh[0]);
        light_load_config(&two);
        two.disable_transfer_to_electrical_mesh = TRUE;
        set_dump_status(dump_lock, FALSE);
        set_dump_status(dump_optics, TRUE);
        set_dump_status(dump_optics_verbose, TRUE);
        double Psun;
        inp_init(&inp);
        inp_load_from_path(&inp, pwd, "light.inp");
        inp_search_double(&inp, &(Psun), "#Psun");
        Psun = 1.0;	//fabs(Psun);
        inp_free(&inp);

        light_solve_and_update(&cell, &two, Psun, 0.0);
        light_dump(&two);
        light_free(&two);
        complex_solver_free();
    } else {
        gen_dos_fd_gaus_fd();

        server_add_job(&globalserver, cell.outputpath, cell.inputpath);
        print_jobs(&globalserver);
        ret = server_run_jobs(&globalserver);

    }

    server_shut_down(&globalserver);

    if (scanarg(argv, argc, "--zip_results") == TRUE) {
        printf("zipping results\n");
        int ret;
        char temp[200];
        DIR *dir = opendir("snapshots");
        if (dir) {
            closedir(dir);
            ret =
                system("zip -r -j -q snapshots.zip ./snapshots/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "snapshots");
            remove_dir(temp);

        }

        dir = opendir("light_dump");
        if (dir) {
            closedir(dir);
            ret =
                system
                ("zip -r -j -q light_dump.zip ./light_dump/*");
            if (ret == -1) {
                printf("tar returned error\n");
            }

            join_path(2, temp, cell.outputpath, "light_dump");
            remove_dir(temp);

        }

    }

    hard_limit_free();
    if (ret != 0) {
        return 1;
    }
    return 0;
}