Beispiel #1
0
void associateObjects(QImage *threshed, QImage *associated)
// For use with Lab 5
// Assign a unique color to each object in the thresholded image,
// and change all pixels in each object to the color.
{
	int height,width;
	int red, green, blue;
	QRgb *pfirstthreshedrgb, *pfirstassociatedrgb, *rgbaddress;
	QRgb pixel;

	height = threshed->height();
	width = threshed->width();
	pfirstthreshedrgb=(QRgb*)threshed->bits();
	pfirstassociatedrgb=(QRgb*)associated->bits();
	
	// initialize an array of labels, assigning a label number to each pixel in the image
	int ** pixellabel = new int*[height];
	for (int i=0;i<height;i++) {
		pixellabel[i] = new int[width];
	}
	for(int row=0; row<height; row++)
	{
		for(int col=0; col<width; col++)
		{
			// read red, green, blue values of pixel in threshed image
			rgbaddress=pfirstthreshedrgb+row*width+col;
			pixel = *(rgbaddress);
			red   = qRed(pixel);			// note: r=g=b= {255 or 0}
			
			if (red==0x00)		pixellabel[row][col]=0;		// object/foreground
			else				pixellabel[row][col]=-1;	// background
		}
	}

		
	int label[2000];
	int *equiv[2000];
	for (int i = 0 ; i<2000 ; i++)
	{
		label[i]= 0;
		equiv[i] = &label[i];

	}






	int labelnum=1;
	//----------------------------FIRST RASTER SCAN---------------------------------//
	// assign the same label to all pixels in each object, a unique label for each object
	for(int row=0; row<height; row++)
	{
		for(int col=0; col<width; col++)
		{
			int pixel = pixellabel[row][col];
			int left=-1;
			int above =-1;
			if (col !=0)
				left = pixellabel[row][col-1];
			if (row != 0)
				above = pixellabel[row-1][col];
			if (pixel != -1)
			{
				if((left ==-1) && (above==-1))
				{
					pixellabel[row][col]=labelnum;
					label[labelnum]= labelnum;
					labelnum++;
				}
				else if ((left !=-1) && (above ==-1))
					pixellabel[row][col] = left;
				else if ((left==-1) && (above != -1 ))
					pixellabel[row][col] = above;

				else if ((left !=-1 ) && (above != -1))
				{
					int min =0;
					int max =0;
					int smallerbaselabel = -9999;
					if (*(equiv[left])<*(equiv[above]))
						smallerbaselabel = *equiv[left];
					else
						smallerbaselabel= *equiv[above];
					if (smallerbaselabel == *equiv[left])
					{
						min =left;
					}
					else 
					{
						min = above;
					}
					if (min == left)
						max = above;
					else
						max = left;
					pixellabel[row][col] = smallerbaselabel;
					*equiv[max] = *equiv[min];
					equiv[max]=equiv[min];
				}
			}
		}
	}

	//--------------SECOND RASTER
	for (int row = 0 ; row <height ; row ++)
	{
		for (int col = 0 ; col<width; col++)
		{

			int pixel = pixellabel[row][col];
			if (pixel != -1 )
					pixellabel[row][col] = *equiv[pixel];

		}

	}
	
		if (DEBUG_LABELS)
	{
		console_printf("generating label debugging text file RELEASE/DEBUGFILE.TXT");
		FILE *debugfile;
		fopen_s(&debugfile,"debugfile1.txt","w");
		for(int row=0; row<height; row++)
			{
			for(int col=0; col<width; col++)
				fprintf(debugfile,"%3d",pixellabel[row][col]);
			fprintf(debugfile,"\n");
			}		
		fclose(debugfile);
	}

	// determine number of objects in the image
	// specify a unique color for each object
	// assign color to all pixels in each objet
	int arr_objpixcount [2000];
	int arr_objpixcount_cent_x [2000];
	int arr_objpixcount_cent_y [2000];
	int arr_REAL_objpixcount [2000];

	for (int i = 0 ; i<2000; i++)
	{
		arr_objpixcount[i]=0;
		arr_REAL_objpixcount[i]=0;
		arr_objpixcount_cent_x[i]=0;
		arr_objpixcount_cent_y[i]=0;
	}
	for (int row = 0 ; row<height; row++)
	{
		for(int col =0 ; col<width; col++)
		{
			if(pixellabel[row][col] != -1)
			{
				int label = pixellabel[row][col];
				arr_objpixcount[label]++;

			}
		}
	}
	int count=1;
	int numobj=0;
	for (int i = 0 ; i<2000; i++)
	{
		if(arr_objpixcount[i]<500 && arr_objpixcount[i]>120)
		{
			arr_REAL_objpixcount[count] = arr_objpixcount[i];
			arr_objpixcount[i]=count;
			numobj++;
			count++;

		}
		else
		{
			arr_objpixcount[i]=0;
		}
	}
	for (int row = 0 ; row<height; row++)
	{
		for(int col =0 ; col<width; col++)
		{
			if(pixellabel[row][col] !=-1){
			if(arr_objpixcount[pixellabel[row][col]]!=0)
			{
				pixellabel[row][col]= arr_objpixcount[pixellabel[row][col]];
				arr_objpixcount_cent_x[pixellabel[row][col]] += col;
				arr_objpixcount_cent_y[pixellabel[row][col]] += row;
			}
			else
				pixellabel[row][col]=-1;
			}
		}
	}



	for (int i = 1; i < (numobj+1); i++)
	{
		arr_objpixcount_cent_x[i] = arr_objpixcount_cent_x[i]/arr_REAL_objpixcount[i];
		arr_objpixcount_cent_y[i] = arr_objpixcount_cent_y[i]/arr_REAL_objpixcount[i];
		double xw =  arr_objpixcount_cent_x[i]*.0829 - arr_objpixcount_cent_y[i]*.2612+27.5039;
		double yw =  arr_objpixcount_cent_x[i]*-.2639 -arr_objpixcount_cent_y[i]*.0784+73.7124;
		console_printf("Object %d Centroid: (%d, %d), world: %lf %lf\n", i, arr_objpixcount_cent_x[i], arr_objpixcount_cent_y[i],xw,yw);
		
	}


	
	console_printf("The number of Dan Blocks are %d\n", numobj);
	// assign UNIQUE color to each object
	for(int row=0; row<height; row++)
	{
		for(int col=0; col<width; col++)
		{
			
			switch ((pixellabel[row][col]%3)+1)
			{
				
				case 1:
					red    = 255;
					green = 0;
					blue   = 0;
					break;
				case 2:
					red    = 0;
					green = 255;
					blue   = 0;
					break;
				case 3:
					red    = 0;
					green = 0;
					blue   = 255;
					break;
				default:
					red    = 255;
					green = 255;
					blue   = 255;
					break;					
			}
			
			rgbaddress=pfirstassociatedrgb+row*width+col;
			*(rgbaddress)=qRgb(red,green,blue);
		}
	}
	//crosshairs
	for(int row=0; row<height; row++)
	{
		for(int col=0; col<width; col++)
		{
			for (int i = 1; i < (numobj+1); i++)
			{
				if((arr_objpixcount_cent_x[i] == col) || (arr_objpixcount_cent_y[i] == row))
				{
					red = 0;
					green = 0;
					blue = 0;
					rgbaddress=pfirstassociatedrgb+row*width+col;
					*(rgbaddress)=qRgb(red,green,blue);

				}
			}
		}
	}

		// prints the array of pixel labels to a text file RELEASE/DEBUGFILE.TXT for you to view
	if (DEBUG_LABELS)
	{
		console_printf("generating label debugging text file RELEASE/DEBUGFILE.TXT");
		console_printf("Width is %d , Height is %d \n", width, height);
		FILE *debugfile;
		fopen_s(&debugfile,"debugfile2.txt","w");
		for(int row=0; row<height; row++)
			{
			for(int col=0; col<width; col++)
				fprintf(debugfile,"%3d",pixellabel[row][col]);
			fprintf(debugfile,"\n");
			}		
		fclose(debugfile);
	}

	// clean up memory
	for (int i=0;i<height;i++) 
	{
		delete pixellabel[i];
    }
    delete pixellabel;
}
Beispiel #2
0
static void
print_lame_tag_leading_info(lame_global_flags * gf)
{
    if (lame_get_bWriteVbrTag(gf))
        console_printf("Writing LAME Tag...");
}
Beispiel #3
0
void user_init(void)
{
	int i;
    uint8_t buffer[16];
    loop_size = rand();
    // Data to write
    uint8_t msg1[] = "Test Message #1";
    uint8_t msg2[] = "Test Message #2";
    uint8_t msg3[] = "Hello world!";

	//Init uart
    uart_init(BIT_RATE_115200, BIT_RATE_115200);
    sleepms(1);

    console_printf("Booting...\r\n");
	console_printf("-----------------------------------------------\r\n");
    console_printf("AT24C512 Library Benchmark\r\n");
	console_printf("-----------------------------------------------\r\n");
    // i2c init
    i2c_init();

    // Erase memory
    eeprom_erase(DEVICEADDRESS, 0, 224);
	console_printf("-----------------------------------------------\r\n");

    // Write some stuff to EEPROM
	if(!eeprom_writePage(DEVICEADDRESS, 0x00, msg1, sizeof(msg1)))
		console_printf("Failed write, address: %d, data: %s\r\n", 0x00, msg1);
	else
		console_printf("Message 1 stored in the memory.\r\n");
	if(!eeprom_writePage(DEVICEADDRESS, 0x40, msg2, sizeof(msg2)))
		console_printf("Failed write, address: %d, data: %s\r\n", 0x40, msg2);
	else
		console_printf("Message 2 stored in the memory.\r\n");
	if(!eeprom_writePage(DEVICEADDRESS, 0x80, msg3, sizeof(msg3)))
		console_printf("Failed write, address: %d, data: %s\r\n",  0x80, msg3);
	else
		console_printf("Message 3 stored in the memory.\r\n");
	console_printf("-----------------------------------------------\r\n");

    // Read the first page in EEPROM memory, a byte at a time
	console_printf("EEPROM read byte, starting at 0x000:\r\n");
    for (i = 0; i < sizeof(msg1)-1; i++) {
    	uint8_t b = eeprom_readByte(DEVICEADDRESS, i);
    	console_printf("0x%02x ", b);
    }
    console_printf("\r\n");
    for (i = 0; i < sizeof(msg1)-1; i++) {
    	uint8_t b = eeprom_readByte(DEVICEADDRESS, i);
    	console_printf("%c ", isprint(b) ? b : '.');
    }
    console_printf("\r\n");
	console_printf("-----------------------------------------------\r\n");

    console_printf("EEPROM read buffer, starting at 0x000:\r\n");
    os_sprintf(buffer, "%s", eeprom_readPage(DEVICEADDRESS, 0, sizeof(buffer)), sizeof(buffer));
    //First print the hex bytes on this row
    for (i = 0; i < sizeof(buffer)-1; i++) {
        char outbuf[6];
    	console_printf("0x%02x ", buffer[i]);
    }
    console_printf("\r\n");
    for (i = 0; i < sizeof(buffer)-1; i++) {
        char outbuf[6];
    	console_printf("%c ", isprint(buffer[i]) ? buffer[i] : '.');
    }
    console_printf("\r\n");
	console_printf("-----------------------------------------------\r\n");

    // Now dump 224 bytes
    console_printf("EEPROM dump:\r\n");
    eeprom_dump(DEVICEADDRESS, 0, 224);

    // Start write benchmark test
    writeByByteTest();
    // Start read benchmark test
    readByByteTest();

    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
Beispiel #4
0
static int cc_get(const char **argv, int argc)
{
	if (argc > 0) {
		if (strcmp(argv[0], "park_rating") == 0) {
			console_printf("park_rating %d", RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_PARK_RATING, sint16));
		}
		else if (strcmp(argv[0], "money") == 0) {
			console_printf("money %d.%d0", DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)) / 10, DECRYPT_MONEY(RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_MONEY_ENCRYPTED, money32)) % 10);
		}
		else if (strcmp(argv[0], "current_loan") == 0) {
			console_printf("current_loan %d", RCT2_GLOBAL(RCT2_ADDRESS_CURRENT_LOAN, money32) / 10);
		}
		else if (strcmp(argv[0], "max_loan") == 0) {
			console_printf("max_loan %d", RCT2_GLOBAL(RCT2_ADDRESS_MAXIMUM_LOAN, money32) / 10);
		}
		else if (strcmp(argv[0], "guest_initial_cash") == 0) {
			console_printf("guest_initial_cash %d.%d0", RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_CASH, money16) / 10, RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_CASH, money16) % 10);
		}
		else if (strcmp(argv[0], "guest_initial_happiness") == 0) {
			uint32 current_happiness = RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_HAPPINESS, uint8);
			for (int i = 15; i <= 99; i++) {
				if (i == 99) {
					console_printf("guest_initial_happiness %d%%  (%d)", 15, RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_HAPPINESS, uint8));
				}
				else if (current_happiness == calculate_guest_initial_happiness(i)) {
					console_printf("guest_initial_happiness %d%%  (%d)", i, RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_HAPPINESS, uint8));
					break;
				}
			}
		}
		else if (strcmp(argv[0], "guest_initial_hunger") == 0) {
			console_printf("guest_initial_hunger %d%%  (%d)", ((255 - RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_HUNGER, uint8)) * 100) / 255, RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_HUNGER, uint8));
		}
		else if (strcmp(argv[0], "guest_initial_thirst") == 0) {
			console_printf("guest_initial_thirst %d%%  (%d)", ((255 - RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_THIRST, uint8)) * 100) / 255, RCT2_GLOBAL(RCT2_ADDRESS_GUEST_INITIAL_THIRST, uint8));
		}
		else if (strcmp(argv[0], "guest_prefer_less_intense_rides") == 0) {
			console_printf("guest_prefer_less_intense_rides %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_PREF_LESS_INTENSE_RIDES) != 0);
		}
		else if (strcmp(argv[0], "guest_prefer_more_intense_rides") == 0) {
			console_printf("guest_prefer_more_intense_rides %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_PREF_MORE_INTENSE_RIDES) != 0);
		}
		else if (strcmp(argv[0], "forbid_marketing_campagns") == 0) {
			console_printf("forbid_marketing_campagns %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_FORBID_MARKETING_CAMPAIGN) != 0);
		}
		else if (strcmp(argv[0], "forbid_landscape_changes") == 0) {
			console_printf("forbid_landscape_changes %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_FORBID_LANDSCAPE_CHANGES) != 0);
		}
		else if (strcmp(argv[0], "forbid_tree_removal") == 0) {
			console_printf("forbid_tree_removal %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_FORBID_TREE_REMOVAL) != 0);
		}
		else if (strcmp(argv[0], "forbid_high_construction") == 0) {
			console_printf("forbid_high_construction %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_FORBID_HIGH_CONSTRUCTION) != 0);
		}
		else if (strcmp(argv[0], "pay_for_rides") == 0) {
			console_printf("pay_for_rides %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_PARK_FREE_ENTRY) != 0);
		}
		else if (strcmp(argv[0], "no_money") == 0) {
			console_printf("no_money %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_NO_MONEY) != 0);
		}
		else if (strcmp(argv[0], "difficult_park_rating") == 0) {
			console_printf("difficult_park_rating %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_DIFFICULT_PARK_RATING) != 0);
		}
		else if (strcmp(argv[0], "difficult_guest_generation") == 0) {
			console_printf("difficult_guest_generation %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_DIFFICULT_GUEST_GENERATION) != 0);
		}
		else if (strcmp(argv[0], "park_open") == 0) {
			console_printf("park_open %d", (RCT2_GLOBAL(RCT2_ADDRESS_PARK_FLAGS, uint32) & PARK_FLAGS_PARK_OPEN) != 0);
		}
		else if (strcmp(argv[0], "land_rights_cost") == 0) {
			console_printf("land_rights_cost %d.%d0", RCT2_GLOBAL(RCT2_ADDRESS_LAND_COST, money16) / 10, RCT2_GLOBAL(RCT2_ADDRESS_LAND_COST, money16) % 10);
		}
		else if (strcmp(argv[0], "construction_rights_cost") == 0) {
			console_printf("construction_rights_cost %d.%d0", RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCTION_RIGHTS_COST, money32) / 10, RCT2_GLOBAL(RCT2_ADDRESS_CONSTRUCTION_RIGHTS_COST, money32) % 10);
		}
		else if (strcmp(argv[0], "climate") == 0) {
			const char* climate_names[] = { "cool_and_wet", "warm", "hot_and_dry", "cold" };
			console_printf("climate %s  (%d)", climate_names[RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8)], RCT2_GLOBAL(RCT2_ADDRESS_CLIMATE, sint8));
		}
		else if (strcmp(argv[0], "game_speed") == 0) {
			console_printf("game_speed %d", gGameSpeed);
		}
		else if (strcmp(argv[0], "console_small_font") == 0) {
			console_printf("console_small_font %d", gConfigInterface.console_small_font);
		}
		else if (strcmp(argv[0], "test_unfinished_tracks") == 0) {
			console_printf("test_unfinished_tracks %d", gConfigGeneral.test_unfinished_tracks);
		}
		else if (strcmp(argv[0], "no_test_crashes") == 0) {
			console_printf("no_test_crashes %d", gConfigGeneral.no_test_crashes);
		}
		else {
			console_writeline_warning("Invalid variable.");
		}
	}
	return 0;
}
Beispiel #5
0
static int tcc_compile_and_run(char* filename)
{
    console_printf("Compiling script %s...\n", filename);

    void* tcc = NULL;
    TCCState * script_state = NULL;
    void* script_buf = NULL;
    
    tcc = module_load("ML/MODULES/tcc.mo");
    if (!tcc)
    {
        console_printf("Could not load TCC compiler.\n");
        goto err;
    }
    
    script_state = (void*) module_exec(tcc, "tcc_new", 0);
    if (!script_state)
    {
        console_printf("Could not initialize TCC compiler.\n");
        goto err;
    }

    module_exec(tcc, "tcc_set_options", 2, script_state, "-nostdlib");
    module_exec(tcc, "tcc_set_options", 2, script_state, "-Wall");
    module_exec(tcc, "tcc_set_options", 2, script_state, "-IML/scripts");
    module_exec(tcc, "tcc_set_output_type", 2, script_state, TCC_OUTPUT_MEMORY);

    int ret_compile = module_exec(tcc, "tcc_add_file", 2, script_state, filename);
    if (ret_compile < 0)
    {
        console_printf("Compilation error.\n");
        goto err;
    }

    script_load_symbols(tcc, script_state, "ML/modules/5D3_113.sym");

    int size = module_exec(tcc, "tcc_relocate", 2, script_state, NULL);
    if (size <= 0)
    {
        console_printf("Linking error.\n");
        goto err;
    }

    script_buf = (void*) tcc_malloc(size);
    if (!script_buf)
    {
        console_printf("Malloc error.\n");
        goto err;
    }
    
    int ret_link = module_exec(tcc, "tcc_relocate", 2, script_state, script_buf);
    if (ret_link < 0)
    {
        console_printf("Relocate error.\n");
        goto err;
    }
        
    void (*script_main)() = (void*) module_exec(tcc, "tcc_get_symbol", 2, script_state, "main");
    if (!script_main)
    {
        console_printf("Your script should have a main function.\n");
        goto err;
    }

    script_define_param_variables(tcc, script_state);

    module_exec(tcc, "tcc_delete", 1, script_state); script_state = NULL;
    module_unload(tcc); tcc = NULL;

    console_printf("Running script %s...\n", filename);

    /* http://repo.or.cz/w/tinycc.git/commit/6ed6a36a51065060bd5e9bb516b85ff796e05f30 */
    sync_caches();

    script_main();

    tcc_free(script_buf); script_buf = NULL;
    return 0;

err:
    if (script_buf) tcc_free(script_buf);
    if (script_state) module_exec(tcc, "tcc_delete", 1, script_state);
    if (tcc) module_unload(tcc);
    return 1;
}
Beispiel #6
0
void
schedule(void)
{
	pid_t pid = current->p_pid;
	unsigned int lowest = 0xffffffff; // initialized to INTMAX

	switch (scheduling_algorithm) {
		case 0: // round-robin scheduling
			while (1) {
				pid = (pid + 1) % NPROCS;

				// Run the selected process, but skip
				// non-runnable processes.
				// Note that the 'run' function does not return.
				if (proc_array[pid].p_state == P_RUNNABLE)
					run(&proc_array[pid]);
			}
			break;

		case 1: // pid-priority scheduling
			while (1) {
				// run highest-priority, runnable process
				for (pid = 0; pid < NPROCS; pid++)
					if (proc_array[pid].p_state == P_RUNNABLE)
						run(&proc_array[pid]);
			}
			break;

		case 2: // set-priority scheduling
			while (1) {
				// get highest-priority number
				pid_t i;
				for (i = 0; i < NPROCS; i++)
					if (proc_array[i].p_state == P_RUNNABLE &&
						proc_array[i].p_priority < lowest)
						lowest = proc_array[i].p_priority;

				// search first highest-priority task
				pid = (pid + 1) % NPROCS; // to alternate, start with next proc
				if (proc_array[pid].p_state == P_RUNNABLE &&
					proc_array[pid].p_priority <= lowest)
					run(&proc_array[pid]);
			}
			break;

		case 3: // proportional-share scheduling
			while (1) {
				if (proc_array[pid].p_state == P_RUNNABLE) {
					// skip if run more than share
					if (proc_array[pid].p_run_t >= proc_array[pid].p_share) {
						proc_array[pid].p_run_t = 0;
					}
					else {
						proc_array[pid].p_run_t++;
						run(&proc_array[pid]);
					}
				}
				
				pid = (pid + 1) % NPROCS; // don't change procs until share up
			}
			break;

		default: break;
	};

	// If we get here, we are running an unknown scheduling algorithm.
	cursorpos = console_printf(cursorpos, 0x100, "\nUnknown scheduling algorithm %d\n", scheduling_algorithm);
	while (1)
		/* do nothing */;
}
Beispiel #7
0
int main(void) {
    /* generic hw init */
    hw_init();

    /* init uart */
    uart_init();

#ifdef DEBUG_INIT
    printf("AlceOSD hw%dv%d fw%d.%d.%d\r\n", hw_rev >> 4, hw_rev & 0xf, VERSION_MAJOR, VERSION_MINOR, VERSION_DEV);
    if (RCONbits.WDTO)
        printf("watchdog reset\r\n");
    if (RCONbits.EXTR)
        printf("external reset\r\n");
    if (RCONbits.SWR)
        printf("software reset\r\n");
    if (RCONbits.IOPUWR)
        printf("ill opcode / uninit W reset\r\n");
    if (RCONbits.WDTO)
        printf("trap conflict reset\r\n");
#endif

    /* real time clock init */
    clock_init();

    /* adc init */
    adc_init();

    /* init video driver */
    init_video();

    /* try to load config from flash */
    config_init();

    /* init widget modules */
    widgets_init();

    /* setup tabs */
    tabs_init();

    /* welcome message */
    console_printf("AlceOSD hw%dv%d fw%d.%d.%d\n", hw_rev >> 4, hw_rev & 0xf, VERSION_MAJOR, VERSION_MINOR, VERSION_DEV);

    /* init home tracking */
    init_home();

    /* init flight status tracking */
    init_flight_stats();

    /* init mavlink module */
    mavlink_init();

    /* init uavtalk module */
    uavtalk_init();

    /* link serial ports to processes */
    uart_set_config_clients(1);

    /* enable all interrupts */
    _IPL = 0;
    _IPL3 = 1;

    console_printf("Processes running...\n");
    /* main loop */
    process_run();

    return 0;
}
Beispiel #8
0
void cmd_line_help(const char *args) {
    console_printf("help:\nAvailable terminal commands:\n");
    print_all_functions();
    console_printf("\nFor help with a specific command, type \"<command> --help\"\n");
}
Beispiel #9
0
void keyboard_handler(struct isr_registers regs) {
	char c = inb(60);
	console_printf(&c);
}
/**
 * cmd bat help
 *
 * Help for the bat command.
 *
 */
static void cmd_bat_help(void)
{
    console_printf("Usage: bat <cmd> [options]\n");
    console_printf("Available bat commands:\n");
    console_printf("  pollrate <time_in_s>\n");
    console_printf("  monitor [<prop>] [off]\n");
    console_printf("  list\n");
    console_printf("  read [<prop>] | all\n");
    console_printf("  write <prop> <value>\n");

    console_printf("Examples:\n");
    console_printf("  list\n");
    console_printf("  monitor VoltageADC\n");
    console_printf("  monitor off\n");
    console_printf("  read Voltage\n");
    console_printf("  read all\n");
    console_printf("  write VoltageLoAlarmSet\n");
}
Beispiel #11
0
void cmd_line_show_prompt() {
    console_set_fgcolor(255, 100, 100);
    console_printf("%s > ", get_cur_path());
    console_set_fgcolor(255, 255, 255);
}
Beispiel #12
0
void lightHashSortPrune(lightlistdist_t * list, const vec_t lmaxdist, const unsigned int max){
	unsigned int count = list->count;
	unsigned int bucketcount = (count / 10) +1;
//	console_printf("bucketcount is %i\n", bucketcount);
	//todo fix this?
	vec_t bucketsize = lmaxdist / (vec_t)(bucketcount-1);

	lightbuckethead_t * table = malloc(bucketcount * sizeof(lightbuckethead_t));
	memset(table, 0 , bucketcount * sizeof(lightbuckethead_t));
	// int lighthash = dist / bucketsize;
	unsigned int i;
	vec_t * dist = list->dist;
	light_t ** tlist = list->list;
	//fill table
	for(i = 0; i < count; i++){
		unsigned int lighthash = (int)(dist[i] / bucketsize);
		if(lighthash > bucketcount) console_printf("u dun goofed now! %i:%i:%i:%i\n", lighthash, dist, bucketsize, bucketcount);
//		printf("lighthash is %i\n", lighthash);
		lightbuckethead_t * h = &table[lighthash];
		lightbucket_t * j = malloc(sizeof(lightbucket_t));
		j->l = tlist[i];
		j->dist = dist[i];
		j->next = 0;
		if(h->tail){
			lightbucket_t *l = h->tail;
			l->next = j;
		} else {
			h->next = j;
		}
		h->tail = j;
		h->count++;
	}

	//dont need to keep that extra data around, so im gonna prune it off now
	list->list = realloc(list->list, max * sizeof(light_t *));
	list->dist = realloc(list->dist, max * sizeof(vec_t));
	list->count = max;


	//go through table, find the "pivot" slot
	unsigned int lcount = 0;
	unsigned int pivot = 0;
	for(pivot = 0; pivot < bucketcount; pivot++){
		lcount+=table[pivot].count;
		if(lcount >= max) break;
	}
	//i should be at the pivot slot
		lightlistdist_t tosort = {0, 0, 0, 0};

	if(lcount != max){
		//organize pivot slot into a new lightlistdist
		tosort.count = table[pivot].count;
		tosort.list = malloc(tosort.count * sizeof(light_t *));
		tosort.dist = malloc(tosort.count * sizeof(vec_t));
		lightbucket_t * b = table[pivot].next;
		for(i = 0; i < tosort.count; i++){
			tosort.list[i] = b->l;
			tosort.dist[i] = b->dist;
			b = b->next;
		}
		//sort my new lightlistdist
		lightQuickSort(tosort, 0 , tosort.count-1);
	} else { // buckets lined up perfectly so that pivot slot can be full

		pivot++;
	}


	// go through buckets, pushing their data into my output list
	unsigned int outarrayloc = 0;
	for(i=0; i < pivot; i++){
		lightbucket_t * b = table[i].next;
		for(; b; b = b->next){
			list->list[outarrayloc] = b->l;
			list->dist[outarrayloc] = b->dist;
			outarrayloc++;
		}
	}

	//now copy over the temporary list
	if(lcount != max){
		unsigned int tlistlength = max - outarrayloc;
		memcpy(&list->list[outarrayloc], tosort.list, tlistlength * sizeof(light_t *));
		memcpy(&list->dist[outarrayloc], tosort.dist, tlistlength * sizeof(vec_t));
	}


	//at this point my input list should be pruned and fixed

	//free temp lightlistdist
	if(tosort.list) free(tosort.list);
	if(tosort.dist) free(tosort.dist);
	//walk and free table
	for(i=0; i < bucketcount; i++){
		lightbucket_t * b = table[i].next;
		lightbucket_t * next;
		for(; b; b = next){
			next = b->next;
			free(b);
		}
	}
	if(table)free(table);
}
Beispiel #13
0
void lab_help()
{
	console_printf("find   get color information for a pixel in any of the four images\n");
	console_printf("pick   click on an object to direct the Rhino to pick it up\n");
	console_printf("place  click on a location for the Rhino to place the object in its gripper\n");
}
Beispiel #14
0
void thresholdImage(QImage *gray, QImage *threshed)
// For use with Lab 5
// Take a grayscale bitmap and threshold it.
// The image pointer has dimension width by height pixels.
{
	int   totalpixels;
	uchar graylevel;							// think of the uchar datatype as an integer that occupies only one byte in memory.
	uchar *pfirstgraybyte, *pgraybyte; 
	QRgb  *pfirstthreshedrgb;

	totalpixels	  = gray->numBytes()/4;			// total number of pixels in image
	pfirstgraybyte	  = gray->bits();			// address of first byte of pixel data in image gray
	pfirstthreshedrgb = (QRgb*)threshed->bits();// address of first RGBA triplet in image threshed

	int zt=0; // threshold grayscale value 
	int hist [256];
	for (int i = 0 ; i<256 ; i++)
	{
		hist[i]=0;
	}
	for (int i = 0 ; i<totalpixels; i++)
	{
		int pix_val = (*(pfirstgraybyte+4*i)+*(pfirstgraybyte+4*i+1)+*(pfirstgraybyte+4*i+2))/3;
		hist[pix_val]+=1;
	}
	int max = -999;
	for (int i = 0 ; i<256 ; i++)
	{
		int test_z = i;
		double q0=0;
		double q1=0;
		double u0 = 0;
		double u1 = 0;
		int t1 = 0;
		int t0 = 0;
		for (int j=0 ;j<=test_z; j++)
		{
			q0 = q0+hist[j];
			u0 = u0+j*hist[j];
			t0 = t0+hist[j];
		}
		for (int j=test_z+1; j<256 ; j++)
		{
			q1 = q1+hist[j];
			u1 = u1+j*hist[j];
			t1 = t1+hist[j];
		}
		q0 = q0/totalpixels;
		q1 = q1/totalpixels;
		if(t0==0)
			u0 = u0/.0001;
		else
			u0 = u0/t0;
		
		if(t1==0)
			u1 = u1/.0001;
		else
			u1 = u1/t1;
		
		
		double sigmab = q0*(1-q0)*(u0-u1)*(u0-u1);
		if(sigmab>max)
		{
			zt = i;
			max =sigmab;

		}



	}
	 console_printf("The threshold is zt %d\n",zt);
	// 1. build a histogram for the gray image
	// 2. select value of zt that minimizes the within-group variance
//	zt = 127;  	// blantantly wrong, just here as an example
	
	// threshold the image



	for(int i=0; i<totalpixels; i++)
	{
		pgraybyte = pfirstgraybyte+i*4;
		graylevel = *(pgraybyte);		
		if(graylevel>zt) *(pfirstthreshedrgb+i)=0xffffffff; // set rgb to 255 (white)
		else             *(pfirstthreshedrgb+i)=0x00000000; // set rgb to 0   (black)
	}
}
/**
 * Returns true if the touchscreen was touched
 */
bool 
sense_touch_screen(
    uint_fast8_t tile_width,
    uint_fast8_t *tile_row_p,
    uint_fast8_t *tile_column_p)
{
#   define XDELTA_MAX	    16 //32 //100
#   define YDELTA_MAX	    12 //24 //100
#   define NUM_SAMPLES	    4 //4 //2
#   define RESOLUTION_BITS  10
 
#   define SETTLING_DELAY() delay_loop(10000)
    /*
     * Approx. 50000 CPU clock cycles. If The CPU clock frequency is 72MHz,
     * there are 72000 CPU clock cycles in 1 ms. So the settling delay is less
     * than 1 ms.
     */

    uint_fast16_t x_samples[NUM_SAMPLES*2];
    uint_fast16_t y_samples[NUM_SAMPLES*2];
    uint_fast16_t x_reading;
    uint_fast16_t y_reading;
    uint_fast8_t i;
    uint_fast16_t yvalue_min = 1023;
    uint_fast16_t yvalue_max = 0;
    uint_fast16_t xvalue_min = 1023;
    uint_fast16_t xvalue_max = 0;
    uint_fast16_t xdelta, ydelta;
    uint_fast16_t ts_max_value = 2 <<(RESOLUTION_BITS-1);

    for (i = 0; i < NUM_SAMPLES; i++)
    {
        /*
         * Power the "x-axis" layer of the touch panel, and use the "y-axis"
         * layer to measure voltage corresponding to the x-axis position:
         */

        touch_screen_polarize_X1_X2();
        select_input_pin_adc_channel(TOUCH_SCREEN_Y_ADC_CHANNEL);
        SETTLING_DELAY();

        x_samples[i*2] =
            read_adc_channel(g_adc_device_p, TOUCH_SCREEN_Y_ADC_CHANNEL);
        
        /*
         * Power the "y-axis" layer of the touch panel, and use the "x-axis"
         * layer to measure voltage corresponding to the y-axis position:
         */

        touch_screen_polarize_Y1_Y2();
        select_input_pin_adc_channel(TOUCH_SCREEN_X_ADC_CHANNEL);
        SETTLING_DELAY();

        y_samples[i*2] = 
            read_adc_channel(g_adc_device_p, TOUCH_SCREEN_X_ADC_CHANNEL);
        
        /*
         * Power the "x-axis" layer of the touch panel, and use the "y-axis"
         * layer to measure voltage corresponding to the x-axis position:
         */

        touch_screen_polarize_X2_X1();
        select_input_pin_adc_channel(TOUCH_SCREEN_Y_ADC_CHANNEL);
        SETTLING_DELAY();

        x_samples[(i*2)+1] = 
            read_adc_channel(g_adc_device_p, TOUCH_SCREEN_Y_ADC_CHANNEL);
        
        /*
         * Power the "y-axis" layer of the touch panel, and use the "x-axis"
         * layer to measure voltage corresponding to the y-axis position:
         */

        touch_screen_polarize_Y2_Y1();
        select_input_pin_adc_channel(TOUCH_SCREEN_X_ADC_CHANNEL);
        SETTLING_DELAY();

        y_samples[(i*2)+1] = 
            read_adc_channel(g_adc_device_p, TOUCH_SCREEN_X_ADC_CHANNEL);
    }
	
    x_reading = 0;
    y_reading = 0;
		
    for (i = 0; i < NUM_SAMPLES; i ++)
    {
        uint_fast16_t tempyval = ts_max_value - y_samples[i*2+1];
        uint_fast16_t tempxval = ts_max_value - x_samples[i*2+1];
        
        x_reading += x_samples[i*2];
        y_reading += y_samples[i*2];
            
        x_reading += (ts_max_value - x_samples[(i*2)+1]);
        y_reading += (ts_max_value - y_samples[(i*2)+1]);
        
        
        if (yvalue_min > y_samples[i*2])
        {
            yvalue_min = y_samples[i*2];
        }

        if (yvalue_max < y_samples[i*2])
        {
            yvalue_max = y_samples[i*2];
        }

        if (yvalue_min > tempyval)
        {
            yvalue_min = tempyval;
        }

        if (yvalue_min < tempyval)
        {
            yvalue_max = tempyval;
        }
        
        if (xvalue_min > x_samples[i*2])
        {
            xvalue_min = x_samples[i*2];
        }

        if (xvalue_max < x_samples[i*2])
        {
            xvalue_max = x_samples[i*2];
        }
        
        if (xvalue_min > tempxval)
        {
            xvalue_min = tempxval;
        }

        if (xvalue_min < tempxval)
        {
            xvalue_max = tempxval;
        }
    }
	
    x_reading /= NUM_SAMPLES*2;
    y_reading /= NUM_SAMPLES*2;

    xdelta = xvalue_max - xvalue_min;
    ydelta = yvalue_max - yvalue_min;
    
    if (x_reading < 1022 && y_reading > 1 &&
        xdelta < XDELTA_MAX && ydelta < YDELTA_MAX)
    {
#if 0 // XXX
        extern volatile uint32_t tile_cursor_index;
        extern volatile uint32_t same_tile_count;

        console_printf(
            "tile_cursor_index: %u, same_tile_count: %u, x_reading: %u, y_reading: %u\n",
            tile_cursor_index, same_tile_count, x_reading, y_reading);

        ATOMIC_POST_INCREMENT_UINT32(&same_tile_count);
#endif // XXX

        map_xy_reading_to_tile(
            x_reading, y_reading, tile_width, tile_row_p, tile_column_p);

        return true;
    }
    
    return false;
}
Beispiel #16
0
static void
timestatus(const lame_global_flags * const gfp)
{
    timestatus_t* real_time = &global_encoder_progress.real_time;
    timestatus_t* proc_time = &global_encoder_progress.proc_time;
    int     percent;
    double  tmx, delta;
    int samp_rate     = lame_get_out_samplerate(gfp)
      , frameNum      = lame_get_frameNum(gfp)
      , totalframes   = lame_get_totalframes(gfp)
      , framesize     = lame_get_framesize(gfp)
      ;

    if (totalframes < frameNum) {
        totalframes = frameNum;
    }
    if (global_encoder_progress.time_status_init == 0) {
        real_time->last_time = GetRealTime();
        proc_time->last_time = GetCPUTime();
        real_time->elapsed_time = 0;
        proc_time->elapsed_time = 0;
    }

    /* we need rollover protection for GetCPUTime, and maybe GetRealTime(): */
    tmx = GetRealTime();
    delta = tmx - real_time->last_time;
    if (delta < 0)
        delta = 0;      /* ignore, clock has rolled over */
    real_time->elapsed_time += delta;
    real_time->last_time = tmx;


    tmx = GetCPUTime();
    delta = tmx - proc_time->last_time;
    if (delta < 0)
        delta = 0;      /* ignore, clock has rolled over */
    proc_time->elapsed_time += delta;
    proc_time->last_time = tmx;

    if (global_encoder_progress.time_status_init == 0) {
        console_printf("\r"
                       "    Frame          |  CPU time/estim | REAL time/estim | play/CPU |    ETA \n"
                       "     0/       ( 0%%)|    0:00/     :  |    0:00/     :  |         "
                       SPEED_CHAR "|     :  \r"
                       /* , Console_IO.str_clreoln, Console_IO.str_clreoln */ );
        global_encoder_progress.time_status_init = 1;
        return;
    }

    ts_calc_times(real_time, samp_rate, frameNum, totalframes, framesize);
    ts_calc_times(proc_time, samp_rate, frameNum, totalframes, framesize);

    if (frameNum < totalframes) {
        percent = (int) (100. * frameNum / totalframes + 0.5);
    }
    else {
        percent = 100;
    }

    console_printf("\r%6i/%-6i", frameNum, totalframes);
    console_printf(percent < 100 ? " (%2d%%)|" : "(%3.3d%%)|", percent);
    ts_time_decompose(proc_time->elapsed_time, '/');
    ts_time_decompose(proc_time->estimated_time, '|');
    ts_time_decompose(real_time->elapsed_time, '/');
    ts_time_decompose(real_time->estimated_time, '|');
    console_printf(proc_time->speed_index <= 1. ?
                   "%9.4f" SPEED_CHAR "|" : "%#9.5g" SPEED_CHAR "|",
                   SPEED_MULT * proc_time->speed_index);
    ts_time_decompose((real_time->estimated_time - real_time->elapsed_time), ' ');
}
Beispiel #17
0
void
task1_handler(void *arg)
{
    int i;
    int rc;
    uint16_t rxval;
    uint8_t last_val;
    uint8_t spi_nb_cntr;
    uint8_t spi_b_cntr;

    /* Set the led pin for the E407 devboard */
    g_led_pin = LED_BLINK_PIN;
    hal_gpio_init_out(g_led_pin, 1);

    /* Use SS pin for testing */
    hal_gpio_init_out(SPI_SS_PIN, 1);
    sblinky_spi_cfg(0);
    hal_spi_set_txrx_cb(0, NULL, NULL);
    hal_spi_enable(0);

    /*
     * Send some bytes in a non-blocking manner to SPI using tx val. The
     * slave should send back 0x77.
     */
    g_spi_tx_buf[0] = 0xde;
    g_spi_tx_buf[1] = 0xad;
    g_spi_tx_buf[2] = 0xbe;
    g_spi_tx_buf[3] = 0xef;
    hal_gpio_write(SPI_SS_PIN, 0);
    for (i = 0; i < 4; ++i) {
        rxval = hal_spi_tx_val(0, g_spi_tx_buf[i]);
        assert(rxval == 0x77);
        g_spi_rx_buf[i] = (uint8_t)rxval;
    }
    hal_gpio_write(SPI_SS_PIN, 1);
    ++g_spi_xfr_num;

    /* Set up the callback to use when non-blocking API used */
    hal_spi_disable(0);
    spi_cb_arg = &spi_cb_obj;
    spi_cb_obj.txlen = 32;
    hal_spi_set_txrx_cb(0, sblinky_spi_irqm_handler, spi_cb_arg);
    hal_spi_enable(0);
    spi_nb_cntr = 0;
    spi_b_cntr = 0;

    while (1) {
        /* Wait one second */
        os_time_delay(OS_TICKS_PER_SEC);

        /* Toggle the LED */
        hal_gpio_toggle(g_led_pin);

        /* Get random length to send */
        g_last_tx_len = spi_cb_obj.txlen;
        spi_cb_obj.txlen = (rand() & 0x1F) + 1;
        memcpy(g_spi_last_tx_buf, g_spi_tx_buf, g_last_tx_len);
        last_val = g_spi_last_tx_buf[g_last_tx_len - 1];
        for (i= 0; i < spi_cb_obj.txlen; ++i) {
            g_spi_tx_buf[i] = (uint8_t)(last_val + i);
        }

        if (g_spi_xfr_num & 1) {
            /* Send non-blocking */
            ++spi_nb_cntr;
            assert(hal_gpio_read(SPI_SS_PIN) == 1);
            hal_gpio_write(SPI_SS_PIN, 0);
#if 0
            if (spi_nb_cntr == 7) {
                g_spi_null_rx = 1;
                rc = hal_spi_txrx_noblock(0, g_spi_tx_buf, NULL, 32);
            } else {
                g_spi_null_rx = 0;
                rc = hal_spi_txrx_noblock(0, g_spi_tx_buf, g_spi_rx_buf, 32);
            }
            assert(!rc);
#else
            g_spi_null_rx = 0;
            rc = hal_spi_txrx_noblock(0, g_spi_tx_buf, g_spi_rx_buf,
                                      spi_cb_obj.txlen);
            assert(!rc);
            console_printf("a transmitted: ");
            for (i = 0; i < spi_cb_obj.txlen; i++) {
                console_printf("%2x ", g_spi_tx_buf[i]);
            }
            console_printf("\n");
            console_printf("received: ");
            for (i = 0; i < spi_cb_obj.txlen; i++) {
                console_printf("%2x ", g_spi_rx_buf[i]);
            }
            console_printf("\n");
#endif
        } else {
            /* Send blocking */
            ++spi_b_cntr;
            assert(hal_gpio_read(SPI_SS_PIN) == 1);
            hal_gpio_write(SPI_SS_PIN, 0);
#if 0
            if (spi_b_cntr == 7) {
                g_spi_null_rx = 1;
                rc = hal_spi_txrx(0, g_spi_tx_buf, NULL, 32);
                spi_b_cntr = 0;
            } else {
                g_spi_null_rx = 0;
                rc = hal_spi_txrx(0, g_spi_tx_buf, g_spi_rx_buf, 32);
            }
            assert(!rc);
            hal_gpio_write(SPI_SS_PIN, 1);
            spitest_validate_last(spi_cb_obj.txlen);
#else
            rc = hal_spi_txrx(0, g_spi_tx_buf, g_spi_rx_buf, spi_cb_obj.txlen);
            assert(!rc);
            hal_gpio_write(SPI_SS_PIN, 1);
            console_printf("b transmitted: ");
            for (i = 0; i < spi_cb_obj.txlen; i++) {
                console_printf("%2x ", g_spi_tx_buf[i]);
            }
            console_printf("\n");
            console_printf("received: ");
            for (i = 0; i < spi_cb_obj.txlen; i++) {
                console_printf("%2x ", g_spi_rx_buf[i]);
            }
            console_printf("\n");
            spitest_validate_last(spi_cb_obj.txlen);
            ++g_spi_xfr_num;
#endif
        }
    }
}
Beispiel #18
0
static void
timestatus_finish(void)
{
    console_printf("\n");
}
Beispiel #19
0
camera_t * camera_open(const char *portname, int highres)
{
	camera_internal_t *camera = (camera_internal_t*)malloc(sizeof(camera_internal_t));
	camera->reader = NULL;

	if (highres)
	{
		console_printf("camera: highres is not supported on windows (yet).\n");
		highres = 0;
	}

	HRESULT hr = S_OK;

	// Initialize Media Foundation
	if (SUCCEEDED(hr))
	{
		hr = MFStartup(MF_VERSION);
	}
	///////////////////////////////////////////
	IMFAttributes *pAttributes = NULL;
	UINT32 m_cDevices = 0;
	IMFActivate **m_ppDevices = NULL;

	// Initialize an attribute store. We will use this to
	// specify the enumeration parameters.

	hr = MFCreateAttributes(&pAttributes, 1);

	// Ask for source type = video capture devices
	if (SUCCEEDED(hr))
	{
		hr = pAttributes->SetGUID(
			MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE,
			MF_DEVSOURCE_ATTRIBUTE_SOURCE_TYPE_VIDCAP_GUID
			);
	}

	// Enumerate devices.
	if (SUCCEEDED(hr))
	{
		hr = MFEnumDeviceSources(pAttributes, &m_ppDevices, &m_cDevices);
	}

	SafeRelease(&pAttributes);

	/////////////////////////////////////////////////
	IMFActivate *pActivate = NULL;
	if (m_cDevices)
	{
		console_printf("camera: there are %d camera devices connected (0..%d).\n", m_cDevices, m_cDevices > 0 ? m_cDevices - 1 : 0);
		int device = strtol(portname, 0, 10);
		if (device < 0 || device >= m_cDevices)
			console_printf("camera: device %d does not exist.\n", device);
		else
			pActivate = m_ppDevices[device];
	}
	else
	{
		console_printf("camera: could not find a device\n");
	}
	/////////////////////////////////////////////////

	IMFMediaSource *pSource = NULL;

	//EnterCriticalSection(&m_critsec);

	// Create the media source for the device.
	hr = pActivate->ActivateObject(
		__uuidof(IMFMediaSource),
		(void**)&pSource
		);
	///////////////////////////////////////////

	//IMFAttributes *pAttributes = NULL;

	/*hr = MFCreateAttributes(&pAttributes, 2);

	if (SUCCEEDED(hr))
	{
	hr = pAttributes->SetUnknown(MF_SOURCE_READER_ASYNC_CALLBACK, this);
	}*/

	if (SUCCEEDED(hr))
	{
		hr = MFCreateSourceReaderFromMediaSource(
			pSource,
			NULL,//pAttributes,
			&camera->reader
			);
	}

	//SafeRelease(&pAttributes);

	////////////////////////////////////////////////////
	// The list of acceptable types.
	GUID subtypes[] = {
		MFVideoFormat_NV12, MFVideoFormat_YUY2, MFVideoFormat_UYVY,
		MFVideoFormat_RGB32, MFVideoFormat_RGB24, MFVideoFormat_IYUV
	};

	//HRESULT hr = S_OK;
	BOOL bUseNativeType = FALSE;

	GUID subtype = { 0 };

	IMFMediaType *pType = NULL;

	UINT32 width = 0, height = 0;
	int selectedSubtype = -1;

	// If the source's native format matches any of the formats in
	// the list, prefer the native format.

	// Note: The camera might support multiple output formats,
	// including a range of frame dimensions. The application could
	// provide a list to the user and have the user select the
	// camera's output format. That is outside the scope of this
	// sample, however.

	DWORD selectedStreamIndex = MF_SOURCE_READER_FIRST_VIDEO_STREAM;

	//while (true)
	//{
		hr = camera->reader->GetNativeMediaType(
			selectedStreamIndex,
			0,  // Type index
			&pType
			);

		if (FAILED(hr)) { console_printf("camera: could not get media type\n"); goto done; }

		hr = ::MFGetAttributeSize(pType, MF_MT_FRAME_SIZE, &width, &height);

		if (FAILED(hr)) { console_printf("camera: could not get resolution\n"); goto done; }

		//if (width != 1280 || height != 960)
		//{
			console_printf("camera: found resolution %dx%d\n", width, height);
			//selectedStreamIndex++;
			//continue;
		//}

		camera->size.width = width;
		camera->size.height = height;
		//break;
	//}


	/*UINT32 num = 0, denom = 0;
	hr = ::MFGetAttributeRatio(pType, MF_MT_FRAME_RATE_RANGE_MAX, &num, &denom);

	if (FAILED(hr)) { goto done; }*/

	//hr = ::MFSetAttributeSize(pType, MF_MT_FRAME_SIZE, 1280, 960);

	//if (FAILED(hr)) { goto done; }

	/*hr = ::MFSetAttributeRatio(pType, MF_MT_FRAME_RATE, num, denom);

	if (FAILED(hr)) { goto done; }*/

	hr = pType->GetGUID(MF_MT_SUBTYPE, &subtype);

	if (FAILED(hr)) { console_printf("camera: could not get stream type(1)\n"); goto done; }

	for (UINT32 i = 0; i < ARRAYSIZE(subtypes); i++)
	{
		if (subtype == subtypes[i])
		{
			hr = camera->reader->SetCurrentMediaType(
				(DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,
				NULL,
				pType
				);

			bUseNativeType = TRUE;
			selectedSubtype = i;
			break;
		}
	}

	if (!bUseNativeType)
	{
		// None of the native types worked. The camera might offer
		// output a compressed type such as MJPEG or DV.

		// Try adding a decoder.

		for (UINT32 i = 0; i < ARRAYSIZE(subtypes); i++)
		{
			hr = pType->SetGUID(MF_MT_SUBTYPE, subtypes[i]);

			if (FAILED(hr)) { console_printf("camera: could not get stream type(2)\n"); goto done; }

			hr = camera->reader->SetCurrentMediaType(
				(DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,
				NULL,
				pType
				);

			if (SUCCEEDED(hr))
			{
				selectedSubtype = i;
				break;
			}
		}
	}

/*	hr = ::MFGetAttributeSize(pType, MF_MT_FRAME_SIZE, &width, &height);
	WIDTH = width;
	HEIGHT = height;*/

	if (FAILED(hr)) { console_printf("camera: could not find stream type\n"); goto done; }

done:
	SafeRelease(&pType);

	console_printf("camera: selected type: %d, native: %s, resolution: %dx%d\n",
		selectedSubtype, bUseNativeType ? "yes" : "no", camera->size.width, camera->size.height);

	///////////////////////////////////////
	/*if (SUCCEEDED(hr))
	{
	hr = camera->reader->GetCurrentMediaType(
	(DWORD)MF_SOURCE_READER_FIRST_VIDEO_STREAM,
	&pType
	);
	}

	if (SUCCEEDED(hr))
	{
	// Register the color converter DSP for this process, in the video
	// processor category. This will enable the sink writer to enumerate
	// the color converter when the sink writer attempts to match the
	// media types.

	hr = MFTRegisterLocalByCLSID(
	__uuidof(CColorConvertDMO),
	MFT_CATEGORY_VIDEO_PROCESSOR,
	L"",
	MFT_ENUM_FLAG_SYNCMFT,
	0,
	NULL,
	0,
	NULL
	);
	}*/

	/////////////////////////////////////////////////

/*	IMFSample *pSample = NULL;
	DWORD streamIndex = 0, flags = 0;
	LONGLONG llTimeStamp = 0;

	hr = camera->reader->ReadSample(
		(DWORD)MF_SOURCE_READER_ANY_STREAM,    // Stream index.
		0,                              // Flags.
		&streamIndex,                   // Receives the actual stream index.
		&flags,                         // Receives status flags.
		&llTimeStamp,                   // Receives the time stamp.
		&pSample                        // Receives the sample or NULL.
		);*/

	if (selectedSubtype != 4)
	{
		console_printf("camera: unexpected stream type.\n");
		SafeRelease(&camera->reader);
		free(camera);
		return 0;
	}
	return (camera_t*)camera;
}
Beispiel #20
0
void
encoder_progress_begin( lame_global_flags const* gf
                      , char              const* inPath
                      , char              const* outPath
                      )
{
    brhist_init_package(gf);
    global_encoder_progress.time_status_init = 0;
    global_encoder_progress.last_time = 0;
    global_encoder_progress.last_frame_num = 0;
    if (global_ui_config.silent < 9) {
        char* i_file = 0;
        char* o_file = 0;
#if defined( _WIN32 ) && !defined(__MINGW32__)
        inPath = i_file = utf8ToLocal8Bit(inPath);
        outPath = o_file = utf8ToConsole8Bit(outPath);
#endif
        lame_print_config(gf); /* print useful information about options being used */

        console_printf("Encoding %s%s to %s\n",
                       strcmp(inPath, "-") ? inPath : "<stdin>",
                       strlen(inPath) + strlen(outPath) < 66 ? "" : "\n     ",
                       strcmp(outPath, "-") ? outPath : "<stdout>");

        free(i_file);
        free(o_file);

        console_printf("Encoding as %g kHz ", 1.e-3 * lame_get_out_samplerate(gf));

        {
            static const char *mode_names[2][4] = {
                {"stereo", "j-stereo", "dual-ch", "single-ch"},
                {"stereo", "force-ms", "dual-ch", "single-ch"}
            };
            switch (lame_get_VBR(gf)) {
            case vbr_rh:
                console_printf("%s MPEG-%u%s Layer III VBR(q=%g) qval=%i\n",
                               mode_names[lame_get_force_ms(gf)][lame_get_mode(gf)],
                               2 - lame_get_version(gf),
                               lame_get_out_samplerate(gf) < 16000 ? ".5" : "",
                               lame_get_VBR_quality(gf),
                               lame_get_quality(gf));
                break;
            case vbr_mt:
            case vbr_mtrh:
                console_printf("%s MPEG-%u%s Layer III VBR(q=%g)\n",
                               mode_names[lame_get_force_ms(gf)][lame_get_mode(gf)],
                               2 - lame_get_version(gf),
                               lame_get_out_samplerate(gf) < 16000 ? ".5" : "",
                               lame_get_VBR_quality(gf));
                break;
            case vbr_abr:
                console_printf("%s MPEG-%u%s Layer III (%gx) average %d kbps qval=%i\n",
                               mode_names[lame_get_force_ms(gf)][lame_get_mode(gf)],
                               2 - lame_get_version(gf),
                               lame_get_out_samplerate(gf) < 16000 ? ".5" : "",
                               0.1 * (int) (10. * lame_get_compression_ratio(gf) + 0.5),
                               lame_get_VBR_mean_bitrate_kbps(gf),
                               lame_get_quality(gf));
                break;
            default:
                console_printf("%s MPEG-%u%s Layer III (%gx) %3d kbps qval=%i\n",
                               mode_names[lame_get_force_ms(gf)][lame_get_mode(gf)],
                               2 - lame_get_version(gf),
                               lame_get_out_samplerate(gf) < 16000 ? ".5" : "",
                               0.1 * (int) (10. * lame_get_compression_ratio(gf) + 0.5),
                               lame_get_brate(gf),
                               lame_get_quality(gf));
                break;
            }
        }

        if (global_ui_config.silent <= -10) {
            lame_print_internals(gf);
        }
    }
}
static int
lis2dw12_shell_cmd_dump(int argc, char **argv)
{
    uint8_t val;
    
    if (argc > 2) {
        return lis2dw12_shell_err_too_many_args(argv[1]);
    }
    
    /* Dump all the register values for debug purposes */
    val = 0;
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_TEMP_L, &val));
    console_printf("0x%02X (OUT_TEMP_L): 0x%02X\n", LIS2DW12_REG_OUT_TEMP_L, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_TEMP_H, &val));
    console_printf("0x%02X (OUT_TEMP_H): 0x%02X\n", LIS2DW12_REG_OUT_TEMP_H, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_WHO_AM_I, &val));
    console_printf("0x%02X (WHO_AM_I): 0x%02X\n", LIS2DW12_REG_WHO_AM_I, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_CTRL_REG1, &val));
    console_printf("0x%02X (CTRL1): 0x%02X\n", LIS2DW12_REG_CTRL_REG1, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_CTRL_REG2, &val));
    console_printf("0x%02X (CTRL2): 0x%02X\n", LIS2DW12_REG_CTRL_REG2, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_CTRL_REG3, &val));
    console_printf("0x%02X (CTRL3): 0x%02X\n", LIS2DW12_REG_CTRL_REG3, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_CTRL_REG4, &val));
    console_printf("0x%02X (CTRL4): 0x%02X\n", LIS2DW12_REG_CTRL_REG4, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_CTRL_REG5, &val));
    console_printf("0x%02X (CTRL5): 0x%02X\n", LIS2DW12_REG_CTRL_REG5, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_CTRL_REG6, &val));
    console_printf("0x%02X (CTRL6): 0x%02X\n", LIS2DW12_REG_CTRL_REG6, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_TEMP_OUT, &val));
    console_printf("0x%02X (TEMP_OUT): 0x%02X\n", LIS2DW12_REG_TEMP_OUT, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_STATUS_REG, &val));
    console_printf("0x%02X (STATUS): 0x%02X\n", LIS2DW12_REG_STATUS_REG, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_X_L, &val));
    console_printf("0x%02X (OUT_X_L): 0x%02X\n", LIS2DW12_REG_OUT_X_L, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_X_H, &val));
    console_printf("0x%02X (OUT_X_H): 0x%02X\n", LIS2DW12_REG_OUT_X_H, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_Y_L, &val));
    console_printf("0x%02X (OUT_Y_L): 0x%02X\n", LIS2DW12_REG_OUT_Y_L, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_Y_H, &val));
    console_printf("0x%02X (OUT_Y_H): 0x%02X\n", LIS2DW12_REG_OUT_Y_H, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_Z_L, &val));
    console_printf("0x%02X (OUT_Z_L): 0x%02X\n", LIS2DW12_REG_OUT_Z_L, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_OUT_Z_H, &val));
    console_printf("0x%02X (OUT_Z_H): 0x%02X\n", LIS2DW12_REG_OUT_Z_H, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_FIFO_CTRL, &val));
    console_printf("0x%02X (FIFO_CTRL): 0x%02X\n", LIS2DW12_REG_FIFO_CTRL, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_FIFO_SAMPLES, &val));
    console_printf("0x%02X (FIFO_SAMPLES): 0x%02X\n", LIS2DW12_REG_FIFO_SAMPLES, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_TAP_THS_X, &val));
    console_printf("0x%02X (TAP_THS_X): 0x%02X\n", LIS2DW12_REG_TAP_THS_X, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_TAP_THS_Y, &val));
    console_printf("0x%02X (TAP_THS_Y): 0x%02X\n", LIS2DW12_REG_TAP_THS_Y, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_TAP_THS_Z, &val));
    console_printf("0x%02X (TAP_THS_Z): 0x%02X\n", LIS2DW12_REG_TAP_THS_Z, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_INT_DUR, &val));
    console_printf("0x%02X (INT_DUR): 0x%02X\n", LIS2DW12_REG_INT_DUR, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_FREEFALL, &val));
    console_printf("0x%02X (FREEFALL): 0x%02X\n", LIS2DW12_REG_FREEFALL, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_INT_SRC, &val));
    console_printf("0x%02X (INT_SRC): 0x%02X\n", LIS2DW12_REG_INT_SRC, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_X_OFS, &val));
    console_printf("0x%02X (X_OFS): 0x%02X\n", LIS2DW12_REG_X_OFS, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_Y_OFS, &val));
    console_printf("0x%02X (Y_OFS): 0x%02X\n", LIS2DW12_REG_Y_OFS, val);
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_Z_OFS, &val));
    console_printf("0x%02X (Z_OFS): 0x%02X\n", LIS2DW12_REG_Z_OFS, val);    
    assert(0 == lis2dw12_read8(&g_sensor_itf, LIS2DW12_REG_CTRL_REG7, &val));
    console_printf("0x%02X (CTRL7): 0x%02X\n", LIS2DW12_REG_CTRL_REG7, val);
    
    return 0;
}
Beispiel #22
0
void
decoder_progress_finish(DecoderProgress dp)
{
    (void) dp;
    console_printf("\n");
}
Beispiel #23
0
static int script_load_symbols(void* tcc, void* script_state, char *filename)
{
    uint32_t size = 0;
    FILE* file = NULL;
    char *buf = NULL;
    uint32_t count = 0;
    uint32_t pos = 0;

    if( FIO_GetFileSize( filename, &size ) != 0 )
    {
        console_printf("Error loading '%s': File does not exist\n", filename);
        return -1;
    }
    buf = fio_malloc(size);
    if(!buf)
    {
        console_printf("Error loading '%s': File too large\n", filename);
        return -1;
    }

    file = FIO_OpenFile(filename, O_RDONLY | O_SYNC);
    if(!file)
    {
        console_printf("Error loading '%s': File does not exist\n", filename);
        fio_free(buf);
        return -1;
    }
    FIO_ReadFile(file, buf, size);
    FIO_CloseFile(file);

    while(buf[pos])
    {
        char address_buf[16];
        char symbol_buf[128];
        uint32_t length = 0;
        uint32_t address = 0;

        while(buf[pos + length] && buf[pos + length] != ' ' && length < sizeof(address_buf))
        {
            address_buf[length] = buf[pos + length];
            length++;
        }
        address_buf[length] = '\000';

        pos += length + 1;
        length = 0;

        while(buf[pos + length] && buf[pos + length] != '\r' && buf[pos + length] != '\n' && length < sizeof(symbol_buf))
        {
            symbol_buf[length] = buf[pos + length];
            length++;
        }
        symbol_buf[length] = '\000';

        pos += length + 1;
        length = 0;

        while(buf[pos + length] && (buf[pos + length] == '\r' || buf[pos + length] == '\n'))
        {
            pos++;
        }
        sscanf(address_buf, "%x", &address);

        module_exec(tcc, "tcc_add_symbol", 3, script_state, symbol_buf, (void*)address);
        count++;
    }

    /* ToDo: parse the old plugin sections as all needed OS stubs are already described there */
    module_exec(tcc, "tcc_add_symbol", 3, script_state, "strcpy", &strcpy);
    module_exec(tcc, "tcc_add_symbol", 3, script_state, "strlen", &strlen);

    fio_free(buf);
    return 0;
}
Beispiel #24
0
void
schedule(void)
{
    pid_t pid = current->p_pid;

    if (scheduling_algorithm == 0)
        while (1) {
            pid = (pid + 1) % NPROCS;

            // Run the selected process, but skip
            // non-runnable processes.
            // Note that the 'run' function does not return.
            if (proc_array[pid].p_state == P_RUNNABLE)
                run(&proc_array[pid]);
        }

    // priority scheduling
    else if(scheduling_algorithm == __EXERCISE_2__) {
        for(pid = 1; pid < NPROCS ; pid++) {
            if (proc_array[pid].p_state == P_RUNNABLE)
                break;
        }
        run(&proc_array[pid]);

    } else if(scheduling_algorithm == __EXERCISE_4A__) {
        int topPriority = 0;
        pid_t j;

        // get the top priority number
        for(j = 1; j < NPROCS ; j++) {
            if (proc_array[j].p_state == P_RUNNABLE) {
                topPriority = (topPriority >= proc_array[j].p_priority) ? topPriority : proc_array[j].p_priority;
            }
        }
        // alternate the processes if there are more than one with top priority
        while (1) {
            pid = (pid + 1) % NPROCS;
            if (proc_array[pid].p_state == P_RUNNABLE && proc_array[pid].p_priority == topPriority)
                break;

        }
        run(&proc_array[pid]);

        // proportional-share scheduling
    } else if(scheduling_algorithm == __EXERCISE_4B__) {
        int largest = -1;
        pid_t j;
        pid_t proc = 1;
        proc_array[pid].p_share_count--;
        //cursorpos = console_printf(cursorpos, 0x200, "pid=%d ", pid );

        if(proc_array[pid].p_state == P_RUNNABLE && proc_array[pid].p_share_count > 0) {
            //	cursorpos = console_printf(cursorpos, 0x200, "c=%d ", proc_array[pid].p_share_count );

            run(&proc_array[pid]);
        }
        else {


            // find largest share that has not gone through in this turn
            for(j = 1; j < NPROCS ; j++) {
                if (proc_array[j].p_state == P_RUNNABLE && (proc_array[j].p_share_count > 1|| (proc_array[j].p_share == 1 && proc_array[j].p_share_count == 1))) {
                    largest = (largest >= proc_array[j].p_share) ? largest : proc_array[j].p_share;
                }
            }
//			cursorpos = console_printf(cursorpos, 0x200, "L=%d ", largest);

            // current pid has share_count == 0, reinitialize it to its share value
            //proc_array[pid].p_share_count = proc_array[pid].p_share;

            // cant' find largeset?
            // that means every process went through a cycle(they all took turn printing out letters already.)
            if(largest == -1) {
                // reset all counts to share
                for(j=1; j < NPROCS ; j++) {
                    if (proc_array[j].p_state == P_RUNNABLE) {
                        proc_array[j].p_share_count = proc_array[j].p_share;
                        // proc = (proc_array[proc].p_share >= proc_array[j].p_share) ? proc] : j;
                        largest = (largest >= proc_array[j].p_share) ? largest : proc_array[j].p_share;
                    }
                }
            }

//			cursorpos = console_printf(cursorpos, 0x200, "A=%d  ", largest);
            // get pid from largest
            for(j = 1; j < NPROCS ; j++) {
                if (proc_array[j].p_state == P_RUNNABLE && proc_array[j].p_share == largest) {
                    break;
                }
            }

//			cursorpos = console_printf(cursorpos, 0x200, "j=%d  ", j);

            run(&proc_array[j]);


        }

    } else if(scheduling_algorithm == __EXERCISE_7__) {

    }

    // If we get here, we are running an unknown scheduling algorithm.
    cursorpos = console_printf(cursorpos, 0x100, "\nUnknown scheduling algorithm %d\n", scheduling_algorithm);
    while (1)
        /* do nothing */;
}
Beispiel #25
0
int
lame_decoder(lame_global_flags * gfp, FILE * outf, int skip_start, char *inPath, char *outPath,
             int *enc_delay, int *enc_padding)
{
    short int Buffer[2][1152];
    int     iread;
    int     skip_end = 0;
    double  wavsize;
    int     i;
    void    (*WriteFunction) (FILE * fp, char *p, int n);
    int     tmp_num_channels = lame_get_num_channels(gfp);



    if (silent < 10)
        console_printf("\rinput:  %s%s(%g kHz, %i channel%s, ",
                       strcmp(inPath, "-") ? inPath : "<stdin>",
                       strlen(inPath) > 26 ? "\n\t" : "  ",
                       lame_get_in_samplerate(gfp) / 1.e3,
                       tmp_num_channels, tmp_num_channels != 1 ? "s" : "");

    switch (input_format) {
    case sf_mp123: /* FIXME: !!! */
      error_printf("Internal error.  Aborting.");
      exit(-1);

    case sf_mp3:
        if (skip_start == 0) {
            if (*enc_delay > -1 || *enc_padding > -1) {
                if (*enc_delay > -1)
                    skip_start = *enc_delay + 528 + 1;
                if (*enc_padding > -1)
                    skip_end = *enc_padding - (528 + 1);
            }
            else
                skip_start = lame_get_encoder_delay(gfp) + 528 + 1;
        }
        else {
            /* user specified a value of skip. just add for decoder */
            skip_start += 528 + 1; /* mp3 decoder has a 528 sample delay, plus user supplied "skip" */
        }

        if (silent < 10)
            console_printf("MPEG-%u%s Layer %s", 2 - lame_get_version(gfp),
                           lame_get_out_samplerate(gfp) < 16000 ? ".5" : "", "III");
        break;
    case sf_mp2:
        skip_start += 240 + 1;
        if (silent < 10)
            console_printf("MPEG-%u%s Layer %s", 2 - lame_get_version(gfp),
                           lame_get_out_samplerate(gfp) < 16000 ? ".5" : "", "II");
        break;
    case sf_mp1:
        skip_start += 240 + 1;
        if (silent < 10)
            console_printf("MPEG-%u%s Layer %s", 2 - lame_get_version(gfp),
                           lame_get_out_samplerate(gfp) < 16000 ? ".5" : "", "I");
        break;
    case sf_raw:
        if (silent < 10)
            console_printf("raw PCM data");
        mp3input_data.nsamp = lame_get_num_samples(gfp);
        mp3input_data.framesize = 1152;
        skip_start = 0; /* other formats have no delay *//* is += 0 not better ??? */
        break;
    case sf_wave:
        if (silent < 10)
            console_printf("Microsoft WAVE");
        mp3input_data.nsamp = lame_get_num_samples(gfp);
        mp3input_data.framesize = 1152;
        skip_start = 0; /* other formats have no delay *//* is += 0 not better ??? */
        break;
    case sf_aiff:
        if (silent < 10)
            console_printf("SGI/Apple AIFF");
        mp3input_data.nsamp = lame_get_num_samples(gfp);
        mp3input_data.framesize = 1152;
        skip_start = 0; /* other formats have no delay *//* is += 0 not better ??? */
        break;
    default:
        if (silent < 10)
            console_printf("unknown");
        mp3input_data.nsamp = lame_get_num_samples(gfp);
        mp3input_data.framesize = 1152;
        skip_start = 0; /* other formats have no delay *//* is += 0 not better ??? */
        assert(0);
        break;
    }

    if (silent < 10) {
        console_printf(")\noutput: %s%s(16 bit, Microsoft WAVE)\n",
                       strcmp(outPath, "-") ? outPath : "<stdout>",
                       strlen(outPath) > 45 ? "\n\t" : "  ");

        if (skip_start > 0)
            console_printf("skipping initial %i samples (encoder+decoder delay)\n", skip_start);
        if (skip_end > 0)
            console_printf("skipping final %i samples (encoder padding-decoder delay)\n", skip_end);
    }

    if (0 == disable_wav_header)
        WriteWaveHeader(outf, 0x7FFFFFFF, lame_get_in_samplerate(gfp), tmp_num_channels, 16);
    /* unknown size, so write maximum 32 bit signed value */

    wavsize = -(skip_start + skip_end);
    WriteFunction = swapbytes ? WriteBytesSwapped : WriteBytes;
    mp3input_data.totalframes = mp3input_data.nsamp / mp3input_data.framesize;

    assert(tmp_num_channels >= 1 && tmp_num_channels <= 2);

    do {
        iread = get_audio16(gfp, Buffer); /* read in 'iread' samples */
        if (iread >= 0) {
            mp3input_data.framenum += iread / mp3input_data.framesize;
            wavsize += iread;

            if (silent <= 0) {
                decoder_progress(&mp3input_data);
                console_flush();
            }

            skip_start -= (i = skip_start < iread ? skip_start : iread); /* 'i' samples are to skip in this frame */

            if (skip_end > 1152 && mp3input_data.framenum + 2 > mp3input_data.totalframes) {
                iread -= (skip_end - 1152);
                skip_end = 1152;
            }
            else if (mp3input_data.framenum == mp3input_data.totalframes && iread != 0)
                iread -= skip_end;

            for (; i < iread; i++) {
                if (disable_wav_header) {
                    WriteFunction(outf, (char *) &Buffer[0][i], sizeof(short));
                    if (tmp_num_channels == 2)
                        WriteFunction(outf, (char *) &Buffer[1][i], sizeof(short));
                }
                else {
                    Write16BitsLowHigh(outf, Buffer[0][i]);
                    if (tmp_num_channels == 2)
                        Write16BitsLowHigh(outf, Buffer[1][i]);
                }
            }
            if (flush_write == 1) {
                fflush(outf);
            }
        }
    } while (iread > 0);

    i = (16 / 8) * tmp_num_channels;
    assert(i > 0);
    if (wavsize <= 0) {
        if (silent < 10)
            error_printf("WAVE file contains 0 PCM samples\n");
        wavsize = 0;
    }
    else if (wavsize > 0xFFFFFFD0 / i) {
        if (silent < 10)
            error_printf("Very huge WAVE file, can't set filesize accordingly\n");
        wavsize = 0xFFFFFFD0;
    }
    else {
        wavsize *= i;
    }

    /* if outf is seekable, rewind and adjust length */
    if (!disable_wav_header && strcmp("-", outPath)
	&& !fseek(outf, 0l, SEEK_SET))
	WriteWaveHeader(outf, (int) wavsize, lame_get_in_samplerate(gfp),
			tmp_num_channels, 16);
    fclose(outf);

    if (silent <= 0)
        decoder_progress_finish();
    return 0;
}
static int do_adc (int argc, const char* const* argv)
{
	console_printf("%d\n", system_adc_read());
	return 0;
}
Beispiel #27
0
static int
lame_decoder(lame_t gfp, FILE * outf, char *inPath, char *outPath)
{
    short int Buffer[2][1152];
    int     i, iread;
    double  wavsize;
    int     tmp_num_channels = lame_get_num_channels(gfp);
    int     skip_start = samples_to_skip_at_start();
    int     skip_end = samples_to_skip_at_end();
    DecoderProgress dp = 0;

    if (!(tmp_num_channels >= 1 && tmp_num_channels <= 2)) {
        error_printf("Internal error.  Aborting.");
        exit(-1);
    }

    if (global_ui_config.silent < 9) {
        console_printf("\rinput:  %s%s(%g kHz, %i channel%s, ",
                       strcmp(inPath, "-") ? inPath : "<stdin>",
                       strlen(inPath) > 26 ? "\n\t" : "  ",
                       lame_get_in_samplerate(gfp) / 1.e3,
                       tmp_num_channels, tmp_num_channels != 1 ? "s" : "");

        printInputFormat(gfp);

        console_printf(")\noutput: %s%s(16 bit, Microsoft WAVE)\n",
                       strcmp(outPath, "-") ? outPath : "<stdout>",
                       strlen(outPath) > 45 ? "\n\t" : "  ");

        if (skip_start > 0)
            console_printf("skipping initial %i samples (encoder+decoder delay)\n", skip_start);
        if (skip_end > 0)
            console_printf("skipping final %i samples (encoder padding-decoder delay)\n", skip_end);

        switch (global_reader.input_format) {
        case sf_mp3:
        case sf_mp2:
        case sf_mp1:
            dp = decoder_progress_init(lame_get_num_samples(gfp),
                                       global_decoder.mp3input_data.framesize);
            break;
        case sf_raw:
        case sf_wave:
        case sf_aiff:
        default:
            dp = decoder_progress_init(lame_get_num_samples(gfp),
                                       lame_get_in_samplerate(gfp) < 32000 ? 576 : 1152);
            break;
        }
    }

    if (0 == global_decoder.disable_wav_header)
        WriteWaveHeader(outf, 0x7FFFFFFF, lame_get_in_samplerate(gfp), tmp_num_channels, 16);
    /* unknown size, so write maximum 32 bit signed value */

    wavsize = 0;
    do {
        iread = get_audio16(gfp, Buffer); /* read in 'iread' samples */
        if (iread >= 0) {
            wavsize += iread;
            if (dp != 0) {
                decoder_progress(dp, &global_decoder.mp3input_data, iread);
            }
            put_audio16(outf, Buffer, iread, tmp_num_channels);
        }
    } while (iread > 0);

    i = (16 / 8) * tmp_num_channels;
    assert(i > 0);
    if (wavsize <= 0) {
        if (global_ui_config.silent < 10)
            error_printf("WAVE file contains 0 PCM samples\n");
        wavsize = 0;
    }
    else if (wavsize > 0xFFFFFFD0 / i) {
        if (global_ui_config.silent < 10)
            error_printf("Very huge WAVE file, can't set filesize accordingly\n");
        wavsize = 0xFFFFFFD0;
    }
    else {
        wavsize *= i;
    }
    /* if outf is seekable, rewind and adjust length */
    if (!global_decoder.disable_wav_header && strcmp("-", outPath)
        && !fseek(outf, 0l, SEEK_SET))
        WriteWaveHeader(outf, (int) wavsize, lame_get_in_samplerate(gfp), tmp_num_channels, 16);
    fclose(outf);
    close_infile();

    if (dp != 0)
        decoder_progress_finish(dp);
    return 0;
}
Beispiel #28
0
//===========================================================
//		Kosio implementations
//===========================================================
int ICACHE_FLASH_ATTR ds18b20()
{
	int r, i, tempLength=0;
	uint8_t addr[8], data[12];
	ds_init();

	r = ds_search(addr);
	if(r)
	{
		console_printf("Found Device @ %02x %02x %02x %02x %02x %02x %02x %02x\r\n", addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);
		if(crc8(addr, 7) != addr[7])
			console_printf( "CRC mismatch, crc=%xd, addr[7]=%xd\r\n", crc8(addr, 7), addr[7]);

		switch(addr[0])
		{
		case 0x10:
			console_printf("Device is DS18S20 family.\r\n");
			break;

		case 0x28:
			console_printf("Device is DS18B20 family.\r\n");
			break;

		default:
			console_printf("Device is unknown family.\r\n");
			return 1;
		}
	}
	else {
		console_printf("No DS18B20 detected, sorry.\r\n");
		return 1;
	}
	// perform the conversion
	reset();
	select(addr);

	write(DS1820_CONVERT_T, 1); // perform temperature conversion

	sleepms(1000); // sleep 1s

	console_printf("Scratchpad: ");
	reset();
	select(addr);
	write(DS1820_READ_SCRATCHPAD, 0); // read scratchpad

	for(i = 0; i < 9; i++)
	{
		data[i] = read();
		console_printf("%2x ", data[i]);
	}
	console_printf("\r\n");

	int HighByte, LowByte, TReading, SignBit, Tc_100, Whole, Fract;
	LowByte = data[0];
	HighByte = data[1];
	TReading = (HighByte << 8) + LowByte;
	SignBit = TReading & 0x8000;  // test most sig bit
	if (SignBit) // negative
		TReading = (TReading ^ 0xffff) + 1; // 2's comp

	Whole = TReading >> 4;  // separate off the whole and fractional portions
	Fract = (TReading & 0xf) * 100 / 16;
	//MQTT stuff here
	console_printf("DS18B20/Temperature: %c%d.%d Celsius\r\n", SignBit ? '-' : '+', Whole, Fract < 10 ? 0 : Fract);
	if(SignBit){
		os_sprintf(DS18B20_Temperature, "%c%d.%d", SignBit ? '-' : '+', Whole, Fract < 10 ? 0 : Fract );
		MQTT_Publish(&mqttClient,DS18B20_MQTT_Temperature,DS18B20_Temperature,5,0,0);
	} else {
		os_sprintf(DS18B20_Temperature, "%d.%d", Whole, Fract < 10 ? 0 : Fract );
		MQTT_Publish(&mqttClient,DS18B20_MQTT_Temperature,DS18B20_Temperature,4,0,0);
	}
	// MANUAL MODE LOGICS HERE
	if (dDEVICE_MODE){
		if (Whole>=dBR_BOILER_SET&&GPIO_INPUT_GET(PIN_GPIO14)) {
			GPIO_OUTPUT_SET(PIN_GPIO14,0);
		}
	}
	return r;
}
Beispiel #29
0
static void ICACHE_FLASH_ATTR writeByByteTest()
{
	time = system_get_time();
	errors = 0;
	address = 0;
	console_printf("-----------------------------------------------\r\n");
	console_printf("Write byte test:\r\n");
	console_printf("Start address: %d, End address: %d\r\n", MIN_ADDRESS, MAX_ADDRESS);
	console_printf("Writing data: ");
	for (address = MIN_ADDRESS; address <= MAX_ADDRESS; address++)
	{
		wdata = address % loop_size;
		if(!eeprom_writeByte(DEVICEADDRESS, address, wdata))
			console_printf("Failed write, address: %d, data: %d\r\n", address, (uint8_t)wdata);
		else
		{
			if (!(address % 500)) {
				//console_printf( "Address: %d, data: %d\r\n", address, (uint8_t)wdata);
				console_printf("..500..");
			}
		}
		sleepms(3);
	}
	finishTime = system_get_time() - time;
	console_printf("DONE!\r\n");
	console_printf("Total Time (seconds): %d\r\n", (uint32_t)(finishTime / 1000000));
	console_printf("Write operations per second: %d\r\n", (uint32_t)(MAX_ADDRESS / (finishTime / 1000000)));
	console_printf("-----------------------------------------------\r\n");
	console_printf("\r\n");
}
Beispiel #30
0
static  int do_chipinfo(int argc, const char* argv[])
{
	console_printf("id=0x%x\n", system_get_chip_id());
}