Ejemplo n.º 1
0
int
main(void)
{
	int del;
	iolib_init(); /* Initialize I/O library - required */
	iolib_setdir(8,11, BBBIO_DIR_IN);   /* Set pin P8 - 11 as input */
	iolib_setdir(8,12, BBBIO_DIR_OUT);  /* Set pin P8 - 12 as output */

	int count = 0;
	while(count < 50)
	{
		count ++ ;
		if (is_high(8,11))   /* Check if in is high (i.e. button pressed) */
		{
			del=100; /* fast speed */
		}
		if (is_low(8,11))    /* Check if in is low (i.e button is released) */
		{
			del=500; /* slow speed */
		}

		pin_high(8,12);       /* Set pin to high - LED on */
		iolib_delay_ms(del);  /* Delay for 'del' msec */
		pin_low(8,12);		  /* Set pin to low - LED off */
		iolib_delay_ms(del);  /* Delay for 'del' msec */

	}
	iolib_free();  /* Release I/O library prior to program exit - required */
	return(0);
}
Ejemplo n.º 2
0
int producerth2(void){
	int count = 0;
	int flag=0;
	iolib_setdir(8,12, BBBIO_DIR_IN);   /* Set pin P8 - 11 as input */

while(count < 10)
{

	char l='R';
	iolib_delay_ms(100);
	if (is_high(8,12))   /* Check if in is high (i.e. button pressed) */
	{
		if (flag==1)
		{
			flag=0;
			enqueue(l,count+10);
			count++;
			continue;
		}
		else
			continue;
	}
	if (is_low(8,12))    /* Check if in is low (i.e button is released) */
	{
		if (flag==0)
		{
			flag=1;
		}
		else
			continue;
	}
}
	return 0;
}
Ejemplo n.º 3
0
int main(void) 
{
	//timer0_init(); // timer 0 initialize 
	SystemInit(); // system variables and state initialize
	timer1_init(); // timer 1 initialize
	PortInit(); // inputs and outputs initialize
	_delay_ms(500);
	start_Test();
	_delay_ms(5000);
	while(1)
	{
		if(is_high(PINB,PB0))
		{
			if(first_Pause == 0)
			{
				pause_Test();
				first_Pause++;
			}
		}
		else
		{
			first_Pause= 0;
			RI_Test_1();
		}
	}
}
/*
 * Class:     org_bulldog_beagleboneblack_jni_NativeGpio
 * Method:    digitalRead
 * Signature: (II)I
 */
JNIEXPORT jint JNICALL Java_org_bulldog_beagleboneblack_jni_NativeGpio_digitalRead
  (JNIEnv * env, jclass clazz, jint port, jint pin) {
	if(is_high(port, pin)) {
		return 1;
	}

	return 0;
}
Ejemplo n.º 5
0
//-----------------------------------------------
int main(void)
{
	int DebFlag  =DEBOUNCING_BUTTON_UP;
	int DebCount = 0;
	iolib_init();

	iolib_setdir(8,12, BBBIO_DIR_IN);
	iolib_setdir(8,11, BBBIO_DIR_IN);

#ifdef DEBOUNCING
        BBBIO_sys_Enable_Debouncing(8 ,11 ,10);
#else
	BBBIO_sys_Disable_Debouncing(8 ,11);
#endif

	printf("OK\n");

        int count = 0;
	int Test =0;
        while(Test <10)
        {
                count ++ ;
                if (is_high(8,11))
                {
		    DebFlag = DEBOUNCING_BUTTON_DOWN;
                }
		else
                {
		    if(DebFlag == DEBOUNCING_BUTTON_DOWN)
		    {
			DebCount ++ ;
			DebFlag = DEBOUNCING_BUTTON_UP ;
		    }
                }
		if(count == 10000000)
		{
		    printf("%d\n",DebCount);
		    count =0;
		    Test ++;
		}
        }
	BBBIO_sys_Disable_Debouncing(8 ,11);
        iolib_free();
	printf("Release\n");
        return(0);
}
Ejemplo n.º 6
0
void
NEXA::Receiver::recv(code_t& cmd)
{
  uint32_t start, stop;
  int32_t bits = 0L;
  uint16_t us;
  uint16_t ix;
  do {
    // Wait for the start condition
    while (is_low());
    stop = RTC::micros();
    // Collect the samples; high followed by low pulse
    ix = 0;
    while (ix < IX_MAX) {
      // Capture length of high period
      start = stop;
      while (is_high());
      stop = RTC::micros();
      us = stop - start;
      if (us < LOW_THRESHOLD || us > HIGH_THRESHOLD) break;
      m_sample[ix & IX_MASK] = us;
      ix += 1;
      // Capture length of low period
      start = stop;
      while (is_low());
      stop = RTC::micros();
      us = stop - start;
      if (us < LOW_THRESHOLD || us > HIGH_THRESHOLD) break;
      m_sample[ix & IX_MASK] = us;
      ix += 1;
      // Decode every four samples to a code bit
      if ((ix & IX_MASK) == 0) {
	int8_t bit = decode_bit();
	if (bit < 0) break;
	bits = (bits << 1) | bit;
      }
    }
  } while (ix != IX_MAX);
  m_code = bits;
  cmd = bits;
}
Ejemplo n.º 7
0
int
ADT7301_read()
{
    int value = 0;
    int data_count =0;
    int i =0 ;

    pin_high(ADT7301_SCLK_PORT,ADT7301_SCLK_PIN);

    value =0;
    //set CS to 1 , why pin_low ? because CS in ADT7301 is inverse pin
    pin_low(ADT7301_CS_PORT,ADT7301_CS_PIN);

    //set DIN to 0
    pin_low(ADT7301_DIN_PORT,ADT7301_DIN_PIN);

    //read temperature Data
    for(i=0;i<16;i++)
    {
        //generate half cycle(1)
        pin_low(ADT7301_SCLK_PORT ,ADT7301_SCLK_PIN);
        iolib_delay_ms(1);

        //generate half cycle(0)
        pin_high(ADT7301_SCLK_PORT,ADT7301_SCLK_PIN);
        iolib_delay_ms(1);

        value <<= 1 ;
        int get_value = is_high(ADT7301_DOUT_PORT,ADT7301_DOUT_PIN) ;
        value |= get_value;
    }

    //set CS to 1
    pin_high(ADT7301_CS_PORT,ADT7301_CS_PIN);

    // return RAW value , this valuse is
    return value ;
}
void *inputCheck(void *data) {
	// Variables to be assigned values
	extern int frequency[];
	extern float amplitude[];
	extern float timeDiv;
	extern int triggerLevel;
	extern int voltageDiv;
	extern int waveType[2];
	extern int offset;
	extern int menu;
	extern int mode;

	//Stores latest value of buttons
	int latestValue[4];
	//Stores previous values for buttons
	int previousValue[4] = { 1, 1, 1, 1 };

	while (!gShouldStop) {

		//Handles Scroll Button Input
		if (is_high(scrollButton))
			latestValue[0] = 1;
		else
			latestValue[0] = 0;
		//Cycles through menu
		if (latestValue[0] == 0 && previousValue[0] == 1) {
			if (mode == -1) {
				menu++;
				menu %= 3;
				memcpy(displayBuffer, &menuBuffer[menu], 1024);
			}
		}
		previousValue[0] = latestValue[0];

		//Handles Select Button Input
		if (is_high(selectButton))
			latestValue[1] = 1;
		else
			latestValue[1] = 0;

		if (latestValue[1] == 0 && previousValue[1] == 1) {
			//Selects menu or goes back to menu
			if (mode == -1) {
				if (menu == 0) {
					mode = 0;
					memcpy(displayBuffer, &oscilliscopeBuffer, 1024);
				} else if (menu == 1) {
					mode = 1;
					memcpy(displayBuffer, &signalGenBuffer, 1024);
				} else if (menu == 2) {
					mode = 2;
					memcpy(displayBuffer, &aboutBuffer, 1024);
				}
			} else {
				mode = -1;
				memcpy(displayBuffer, &menuBuffer[menu], 1024);
			}
		}
		previousValue[1] = latestValue[1];

		//Handles Wave Type For Channel 1 or Offset for oscilloscope
		if (is_high(button1))
			latestValue[2] = 1;
		else
			latestValue[2] = 0;

		if (latestValue[2] == 0 && previousValue[2] == 1) {
			if (mode == 1) {
				if (waveType[0] == 0) {
					waveType[0] = 1;
					drawCross(26, 57, 0);
					drawCross(58, 57, 1);
				} else if (waveType[0] == 1) {
					waveType[0] = 2;
					drawCross(26, 57, 0);
					drawCross(58, 57, 0);
				} else {
					waveType[0] = 0;
					drawCross(26, 57, 1);
				}
			} else if (mode == 0) {
				offset++;
				if (offset > 30)
					offset = 30;
			}
		}
		previousValue[2] = latestValue[2];

		//Handles Wave Type For Channel 2 or Offset for oscilloscope
		if (is_high(button2))
			latestValue[3] = 1;
		else
			latestValue[3] = 0;

		if (latestValue[3] == 0 && previousValue[3] == 1) {
			if (mode == 1) {
				if (waveType[1] == 0) {
					waveType[1] = 1;
					drawCross(89, 57, 0);
					drawCross(121, 57, 1);
				} else if (waveType[1] == 1) {
					waveType[1] = 2;
					drawCross(89, 57, 0);
					drawCross(121, 57, 0);
				} else {
					waveType[1] = 0;
					drawCross(89, 57, 1);
				}
			} else if (mode == 0) {
				offset--;
				if (offset < 1)
					offset = 1;
			}
		}

		previousValue[3] = latestValue[3];

		//Retrieves 10 analouge samples
		BBBIO_work(10);

		//Averages the retrieved smaples
		int sampleAverage[5] = { 0, 0, 0, 0, 0 };
		for (int n = 0; n < 10; n++) {
			for (int m = 0; m < 5; m++) {
				sampleAverage[m] += analougeInputs[m][n];
			}
		}
		for (int n = 0; n < 5; n++)
			sampleAverage[n] /= 10;
		//End of averaging

		//checks if device in oscilliscope mode
		if (mode == 0) {

			triggerLevel = 1 + (sampleAverage[2] * (62 - 1) / 4096); // Normalises trigger level to between 1 and 62

			voltageDiv = 1 + (sampleAverage[1] * (5 - 1) / 4096); // normalise to between 0 and 5 for voltage division

			sampleAverage[0] = (sampleAverage[0] * 6 / 4096); // normalise to between 0 and 6 for time divisions

			//10 pixels per division hence sampleSkip=sampleRate X timeDiv /10
			switch (sampleAverage[0]) {
			case 0:
				timeDiv = 0.1; //0.1mS
				sampleSkip = 1; //0.96
				break;
			case 1:
				timeDiv = 0.5; //0.5mS
				sampleSkip = 5; //4.8
				break;
			case 2:
				timeDiv = 1; //1mS
				sampleSkip = 10; //9.6
				break;
			case 3:
				timeDiv = 2; //2mS
				sampleSkip = 19; //19.2
				break;
			case 4:
				timeDiv = 5; //5mS
				sampleSkip = 48; //48
				break;
			case 5:
				timeDiv = 10; //10mS
				sampleSkip = 96; //96
				break;
			}

			printf(
					"\rTime Div = %.1f mS, Voltage Div = %.2f v,TriggerLevel= %d ",
					timeDiv, (float) voltageDiv / 4, triggerLevel);

			fflush(stdout);
			//Checks if device in signal generator mode
		} else if (mode == 1) {

			frequency[0] = ((50 + (sampleAverage[3] * (20000 - 50) / 4096)) / 50
					* 50); // normalise to 50-20000 and assigns to frequency1
			frequency[1] = ((50 + (sampleAverage[4] * (20000 - 50) / 4096)) / 50
					* 50); // normalise to 50-20000 and assigns to frequency2

			drawNumber(18, 19, frequency[0], 4);
			drawNumber(82, 19, frequency[1], 4);

			amplitude[0] = (float) sampleAverage[1] / 4096;
			amplitude[1] = (float) sampleAverage[2] / 4096;
			drawNumber(42, 30, sampleAverage[1] * (100) / 4096, 1);
			drawNumber(106, 30, sampleAverage[2] * (100) / 4096, 1);
		}

		updateDisplay();
		usleep(30000);
	}
	pthread_exit(NULL);

}
Ejemplo n.º 9
0
/**
 * ww_calc_bounds
 * @screen: The screen for which to calculate the bounds
 * @struts: A list of %WnckWindow<!---->s that should be treated as
 *          blocking elements on the desktop. Eg. panels and docks
 * @x: Return value for the left side of the bounding box
 * @y: Return value for the top of the box
 * @right: Return coordinate for the right side of the bounding box
 * @bottom: Return value for the bottom coordinate of the bounding box
 *
 * Calculate the maximal rect within a set of blocking windows.
 * For simplicity this method assumes that all struts are along the screen
 * edges and expand over the entire screen edge. Ie a standard panel setup.
 */
void
ww_calc_bounds (WnckScreen *screen,
                GList *struts, 
                int *left, 
                int *top, 
                int *right, 
                int *bottom)
{
	GList		*next;
	WnckWindow  *win;
	int wx, wy, ww, wh; /* current window geom */
	int edge_l, edge_t, edge_b, edge_r;
	int screen_w, screen_h;
	
	edge_l = 0;
	edge_t = 0;
	edge_r = wnck_screen_get_width (screen);
	edge_b = wnck_screen_get_height (screen);
	
	screen_w = edge_r;
	screen_h = edge_b;
	
	for (next = struts; next; next = next->next)
	{	
		win = WNCK_WINDOW (next->data);
		wnck_window_get_geometry (win, &wx, &wy, &ww, &wh);
		
		/* Left side strut */
		if (is_high(ww, wh) && wx == 0) {
			edge_l = MAX(edge_l, ww);
		}
		
		/* Top struct */
		else if (is_broad(ww, wh) && wy == 0) {
			edge_t = MAX (edge_t, wh);
		}
		
		/* Right side strut */
		else if (is_high(ww, wh) && (wx+ww) == screen_w) {
			edge_r = MIN(edge_r, wx);
		}
		
		/* Bottom struct */
		else if (is_broad(ww, wh) && (wy+wh) == screen_h) {
			edge_b = MIN (edge_b, wy);
		}
		
		else {
			g_warning ("Desktop layout contains floating element at "
					   "(%d, %d)@%dx%d", wx, wy, ww, wh);
		}
	}
	
	g_debug ("Calculated desktop bounds (%d, %d), (%d, %d)",
			 edge_l, edge_t, edge_r, edge_b);
	
	*left = edge_l;
	*top = edge_t;
	*right = edge_r;
	*bottom = edge_b;
}
Ejemplo n.º 10
0
int pin_get(int p) { return is_high(BANK,p); }
Ejemplo n.º 11
0
static bool test_allocate_ipv4_transport_address(void)
{
	struct tuple client1tuple, client2tuple, client3tuple;
	struct in_addr client1addr4, client2addr4, client3addr4;
	struct tuple *sharing_client_tuple;
	struct in_addr *non_sharing_addr;
	struct ipv4_transport_addr result;
	struct host6_node *host6;
	unsigned int i = 0;
	bool success = true;

	if (is_error(init_ipv6_tuple(&client1tuple, "1::1", 60000, "64:ff9b::1", 60000, L4PROTO_UDP)))
		goto fail;
	if (is_error(init_ipv6_tuple(&client2tuple, "1::2", 60000, "64:ff9b::2", 60000, L4PROTO_UDP)))
		goto fail;
	if (is_error(init_ipv6_tuple(&client3tuple, "1::3", 60000, "64:ff9b::3", 60000, L4PROTO_UDP)))
		goto fail;

	log_debug("IPv6 client 1 arrives and makes 25 connections.");
	/*
	 * Because it's the same IPv6 client, all of those connections should be masked with the same
	 * IPv4 address. This minimizes confusion from remote IPv4 hosts.
	 */

	client1tuple.src.addr6.l4 = 65511;
	if (!test_allocate_aux(&client1tuple, NULL, &client1addr4, true))
		goto fail;

	for (i = 65512; i < 65536; i++) {
		client1tuple.src.addr6.l4 = i;
		if (!test_allocate_aux(&client1tuple, &client1addr4, NULL, true))
			goto fail;
	}

	log_debug("Client 2 arrives and make 50 connections.");
	/*
	 * All of them should share the same IPv4 address,
	 * which should be different from client1's (again, to minimize confusion).
	 */

	client2tuple.src.addr6.l4 = 65486;
	success &= test_allocate_aux(&client2tuple, NULL, &client2addr4, true);
	success &= assert_true(client1addr4.s_addr != client2addr4.s_addr,
			"the nodes are being masked with different addresses");
	if (!success)
		goto fail;

	for (i = 65487; i < 65536; i++) {
		client2tuple.src.addr6.l4 = i;
		if (!test_allocate_aux(&client2tuple, &client2addr4, NULL, true))
			goto fail;
	}

	log_debug("Client 1 makes another 25 connections.");
	/*
	 * Because there are still ports available, he should still get the same IPv4 address.
	 * Essentially, this proves that client2's intervention doesn't affect client 1's connections.
	 */

	for (i = 65486; i < 65511; i++) {
		client1tuple.src.addr6.l4 = i;
		if (!test_allocate_aux(&client1tuple, &client1addr4, NULL, true))
			goto fail;
	}

	log_debug("Client 3 arrives and hogs up all of its address's low ports.");
	/*
	 * At this point, both IPv4 addresses have 50 high ports taken.
	 * Because both IPv4 addresses are taken, client 3 will share its IPv4 address with someone.
	 */
	client3tuple.src.addr6.l4 = 0;
	if (!test_allocate_aux(&client3tuple, NULL, &client3addr4, true))
		goto fail;

	for (i = 1; i < 1024; i++) {
		client3tuple.src.addr6.l4 = i;
		if (!test_allocate_aux(&client3tuple, &client3addr4, NULL, true))
			goto fail;
	}

	log_debug("The client that shares an address with client 3 requests a low port.");
	/*
	 * Because all of them are taken, he gets the same address but a runner-up high port instead.
	 */

	if (addr4_equals(&client1addr4, &client3addr4)) {
		sharing_client_tuple = &client1tuple;
		non_sharing_addr = &client2addr4;
	} else if (addr4_equals(&client2addr4, &client3addr4)) {
		sharing_client_tuple = &client2tuple;
		non_sharing_addr = &client1addr4;
	} else {
		log_err("Client 3 doesn't share its IPv4 address with anyone, despite validations.");
		goto fail;
	}


	if (is_error(host6_node_get_or_create(&sharing_client_tuple->src.addr6.l3, &host6)))
		goto fail;

	sharing_client_tuple->src.addr6.l4 = 0;
	success &= assert_equals_int(0, allocate_transport_address(host6, sharing_client_tuple,
			&result), "result 3");
	success &= assert_equals_ipv4(&client3addr4, &result.l3, "runnerup still gets his addr");
	success &= assert_true(is_high(result.l4), "runnerup gets a high port");
	success &= bib_inject(&sharing_client_tuple->src.addr6.l3, sharing_client_tuple->src.addr6.l4,
			&result.l3, result.l4, L4PROTO_UDP) != NULL;

	host6_node_return(host6);
	if (!success)
		goto fail;

	log_debug("Client 3 now hogs up all of its address's remaining ports.");
	/* 51 high ports were already taken, so this will stop early. */
	for (i = 1024; i < 65485; i++) {
		client3tuple.src.addr6.l4 = i;
		if (!test_allocate_aux(&client3tuple, &client3addr4, NULL, i != 65484))
			goto fail;
	}

	/*
	 * At this point, client's address has 50 + 1024 + 1 + 64461 = 65536 ports taken.
	 * ie. It no longer has any ports.
	 */

	log_debug("Then, the function will fall back to use the other address.");
	client3tuple.src.addr6.l4 = i;
	if (is_error(host6_node_get_or_create(&client3tuple.src.addr6.l3, &host6)))
		goto fail;

	success &= assert_equals_int(0, allocate_transport_address(host6, &client3tuple, &result),
			"function result");
	success &= assert_true(client3addr4.s_addr != result.l3.s_addr,
			"node gets a runnerup address");
	success &= bib_inject(&client3tuple.src.addr6.l3, client3tuple.src.addr6.l4,
			&result.l3, result.l4, L4PROTO_UDP) != NULL;

	host6_node_return(host6);
	if (!success)
		goto fail;

	log_debug("It will also fall back to use the other address as the other sharing node now hogs "
			"all remaining ports.");
	/*
	 * 51 high ports ports were already taken, so this will stop early.
	 * Also, the sharing client already requested port 0, so we have to start at 1.
	 */
	for (i = 1; i < 65486; i++) {
		sharing_client_tuple->src.addr6.l4 = i;
		if (!test_allocate_aux(sharing_client_tuple, non_sharing_addr, NULL,  i != 65485))
			goto fail;
	}


	log_debug("Now the pool is completely exhausted, so further requests cannot fall back.");

	if (is_error(host6_node_get_or_create(&client1tuple.src.addr6.l3, &host6)))
		goto fail;
	success &= assert_equals_int(-ESRCH, allocate_transport_address(host6, &client1tuple,
			&result), "client 1's request is denied");
	host6_node_return(host6);

	if (is_error(host6_node_get_or_create(&client2tuple.src.addr6.l3, &host6)))
		goto fail;
	success &= assert_equals_int(-ESRCH, allocate_transport_address(host6, &client2tuple,
			&result), "client 2's request is denied");
	host6_node_return(host6);

	if (is_error(host6_node_get_or_create(&client3tuple.src.addr6.l3, &host6)))
		goto fail;
	success &= assert_equals_int(-ESRCH, allocate_transport_address(host6, &client3tuple,
			&result), "client 3's request is denied");
	host6_node_return(host6);

	return success;

fail:
	log_debug("i was %u.", i);
	return false;
}
Ejemplo n.º 12
0
static bool is_same_range(u16 num1, u16 num2)
{
	return is_high(num1) ? is_high(num2) : is_low(num2);
}
Ejemplo n.º 13
0
/* ------------------------------------------------------------ */
int main()
{
	list_audio_devices(alcGetString(NULL, ALC_DEVICE_SPECIFIER));
	/* BBBIOlib init*/
	iolib_init();
	iolib_setdir(8,11, BBBIO_DIR_IN);	/* Button */
	iolib_setdir(8,12, BBBIO_DIR_OUT);	/* LED */


//	sys_info.capability = SYS_CAPABILITY_VIDEO_Tx | SYS_CAPABILITY_VIDEO_Rx | SYS_CAPABILITY_AUDIO_Tx | SYS_CAPABILITY_AUDIO_Rx;
//	sys_info.capability = SYS_CAPABILITY_VIDEO_Tx | SYS_CAPABILITY_AUDIO_Tx;
	sys_info.capability =SYS_CAPABILITY_AUDIO_Rx | SYS_CAPABILITY_VIDEO_Rx;
//	sys_info.capability = SYS_CAPABILITY_VIDEO_Tx;

	sys_info.status = SYS_STATUS_INIT;
	sys_info.cam.width = 320;
	sys_info.cam.height = 240;
//	sys_info.cam.pixel_fmt = V4L2_PIX_FMT_YUV420;
	sys_info.cam.pixel_fmt = V4L2_PIX_FMT_YUYV;

	/* alloc RGB565 buffer for frame buffer data store */
	RGB565_buffer = (unsigned char *)malloc(sys_info.cam.width * sys_info.cam.height *2);

	/* step Codec register  */
	avcodec_register_all();
	av_register_all();
	video_encoder_init(sys_info.cam.width, sys_info.cam.height, sys_info.cam.pixel_fmt);
	video_decoder_init(sys_info.cam.width, sys_info.cam.height, sys_info.cam.pixel_fmt);
	printf("Codec init finish\n");

	/* step Frame buffer initial*/
	if(FB_init() == 0) {
		fprintf(stderr, "Frame Buffer init error\n");
	}
	FB_clear(var_info.xres, var_info.yres);

	sys_set_status(SYS_STATUS_IDLE);

	/* Create Video thread */
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Rx) pthread_create(&Video_Rx_thread, NULL, Video_Rx_loop, NULL);
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Tx) pthread_create(&Video_Tx_thread, NULL, Video_Tx_loop, NULL);

	/* Create Audio thread*/
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Rx) pthread_create(&Audio_Rx_thread, NULL, Audio_Rx_loop, NULL);
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Tx) pthread_create(&Audio_Tx_thread, NULL, Audio_Tx_loop, NULL);

	/* Signale SIGINT */
	signal(SIGINT, SIGINT_release);

	/* Main loop */
	while(sys_get_status() != SYS_STATUS_RELEASE) {
		/* Button on */
		if (is_high(8,11)) {
			sys_set_status(SYS_STATUS_WORK);
			pin_high(8, 12);	/* LED on*/
		}
		else {
//			FB_clear(var_info.xres, var_info.yres);
//			sys_set_status(SYS_STATUS_IDLE);
			sys_set_status(SYS_STATUS_WORK);
			pin_low(8, 12);	/* LED off */
		}
		//usleep(100000);
		sleep(1);
	}
	pin_low(8, 12); /* LED off */

	/* *******************************************************
	 * Main thread for SIP server communication and HW process
	 *
	 *
	 * *******************************************************/

	/* release */
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Tx) pthread_join(Video_Tx_thread,NULL);
	if(sys_info.capability & SYS_CAPABILITY_VIDEO_Rx) pthread_join(Video_Rx_thread,NULL);
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Tx) pthread_join(Audio_Tx_thread,NULL);
	if(sys_info.capability & SYS_CAPABILITY_AUDIO_Rx) pthread_join(Audio_Rx_thread,NULL);


	munmap(FB_ptr, FB_scerrn_size);
	close(FB);
	free(RGB565_buffer);

	video_encoder_release();
	video_decoder_release();
	printf("finish\n");
	return 0;
}
Ejemplo n.º 14
0
	bool is_low()		{ return !is_high(); }
Ejemplo n.º 15
0
//Function to read in audio data from speaker through audio input pin on the audio cape
void readAudioData(int mArraySize, char mArray[]) {

	struct timespec currentTime;
	struct timespec lastChange;
	char cur;
	char prev;
	int curPos = 0;
	int bitsRead = 0;
	int numOfPeriods;
	int i;
	uint64_t timeDifferenceNS;
	uint64_t audioPeriod;
	uint64_t difference;

	//Reads in different numbers for period between bits read from Audio Cape in different states
	if (state == 1) {
		audioPeriod = RECORDING_PERIOD_NS;
		difference = RECORDING_PERIOD_DIFFERENCE;
	} else {
		audioPeriod = TUNER_PERIOD_NS;
		difference = TUNER_PERIOD_DIFFERENCE;
	}

	// Check initial reading of Audio Input pin
	if (is_high(9, 25)) {
		cur = 1;
		mArray[curPos] = 1;
		prev = 1;
	} else {
		cur = 0;
		mArray[curPos] = 0;
		prev = 0;
	}
	++curPos;
	++bitsRead;
	clock_gettime(CLOCK_REALTIME, &currentTime);
	lastChange = currentTime;

	// Loops that continuosly poll the audio input pin and modifies the char array as needed
	while (curPos < mArraySize - 1 && (state == 1 && stopButton == 0)) {
		// Check current input from audio input pin
		if (is_high(9, 25)) {
			cur = 1;
		} else {
			cur = 0;
		}

		// Check to see if whether there has been a change of input from audio input pin
		if (cur != prev) {

			// Calculate time difference between changes of input from audio input pin
			clock_gettime(CLOCK_REALTIME, &currentTime);
			if (currentTime.tv_nsec < lastChange.tv_nsec) {
				timeDifferenceNS = ((1000000000)
						* (currentTime.tv_sec - 1 - lastChange.tv_sec))
						+ ((1000000000 + currentTime.tv_nsec)
								- lastChange.tv_nsec);
			} else {
				timeDifferenceNS = ((1000000000)
						* (currentTime.tv_sec - lastChange.tv_sec))
						+ (currentTime.tv_nsec - lastChange.tv_nsec);
			}
			numOfPeriods = timeDifferenceNS / AUDIOCAPE_PERIOD_NS;

			// Modify character array as needed to store input from audio pin
			for (i = 0; (i < numOfPeriods) && (bitsRead < BIT_DEPTH); ++i) {
				mArray[curPos] = cur;
				++curPos;
				++bitsRead;
			}
			prev = cur;

			// Reset the bitsRead variable
			if (bitsRead > BIT_DEPTH) {
				bitsRead = 0;

				// If there is a difference between sampling rate of Audio Cape and current sampling rate, sleep
				if (difference != 0) {
					currentTime.tv_nsec += difference;
					clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, &currentTime,
					NULL);
				}
			}
		}
	}

	// If input has finished, end array with an 'f' char and fill remaining chars as literal 0
	mArray[curPos] = 'f';
	for (i = curPos + 1; i < mArraySize - 1; ++i) {
		mArray[i] = 0;
	}
}