void InitGpioA(int clockpin)
{
	BTCK = clockpin;
	if (BTCK>100) {
		BANK = BTCK/100;
		BTCK = BTCK%100;
	}
	BTMS=BTCK+1;	
	BTDO=BTCK+2;	
	BTDI=BTCK+3;
	
	iolib_init();
	fprintf(stderr,"Init GPIO %d :: %d %d %d %d\n",BANK,BTCK,BTMS,BTDO,BTDI);	
	fprintf(stderr,"Init GPIO pin group %d %d %d %d\n",bank[BANK-8][BTCK],bank[BANK-8][BTMS],bank[BANK-8][BTDO],bank[BANK-8][BTDI]);
	if (bank[BANK-8][BTCK]>1||bank[BANK-8][BTMS]>1||bank[BANK-8][BTDO]>1||bank[BANK-8][BTDI]>1) {
		fprintf(stderr,"Pins selected from high groups! Failure likely!!\n");
		//system("echo 5 > /sys/class/gpio/export)"; fix gpio0[x] if broken.
		system("echo 65 > /sys/class/gpio/export");
		system("echo 105 > /sys/class/gpio/export");
	}
	iolib_setdir(BANK,BTCK,DIR_OUT);
	iolib_setdir(BANK,BTMS,DIR_OUT);
	iolib_setdir(BANK,BTDO,DIR_IN);
	iolib_setdir(BANK,BTDI,DIR_OUT);

}
Beispiel #2
0
void init_screen():

char black_image_path[] = "/mnt/data/bin/tangible-test.sh /mnt/data/img/default_400x240/monochrome/black.png";
char fanny_hug_image_path[] = "/mnt/data/bin/tangible-test.sh /mnt/data/img/default_400x240/monochrome/fanny_hug.png";
char fanny_heartbeat_image_path[] = "/mnt/data/bin/tangible-test.sh /mnt/data/img/default_400x240/monochrome/fanny_heartbeat.png";
char fanny_buzz_image_path[] = "/mnt/data/bin/tangible-test.sh /mnt/data/img/default_400x240/monochrome/fanny_buzz.png";

int main(void)
{

        iolib_init();

        iolib_setdir(8,30, DIR_OUT); //Pin 30 on P8 expansion header.
        iolib_setdir(8,39, DIR_OUT); //Pin 39 on P8 expansion header.

        init_screen();

        while(1)
        {
         
                debug_schedule();

                //test_schedule();
                //break;
        }

        iolib_free();

        return(0);
}
Beispiel #3
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);
}
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;
}
Beispiel #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);
}
Beispiel #6
0
//------------------------------------------------------------------------
int
main(void)
{
	int raw_temp  =0;
	int i= 0;
	iolib_init();
	iolib_setdir(8,11, BBBIO_DIR_OUT);
	iolib_setdir(8,12, BBBIO_DIR_OUT);
        iolib_setdir(8,15, BBBIO_DIR_IN);
        iolib_setdir(8,16, BBBIO_DIR_OUT);


	for(i=0 ;i< 10 ; i++)
	{
	    raw_temp = ADT7301_read();
	    printf("%f\n",(float)(raw_temp)/32.0f);
	    sleep(1);
	}
	iolib_free();
	return 0 ;
}
//Initialises all inputs
void inputInitialise() {
	iolib_init();
	//Sets direction of inputs
	iolib_setdir(CS, OUTPUT);
	iolib_setdir(RST, OUTPUT);
	iolib_setdir(A0, OUTPUT);
	iolib_setdir(SCLK, OUTPUT);
	iolib_setdir(SID, OUTPUT);
	iolib_setdir(scrollButton, INPUT);
	iolib_setdir(selectButton, INPUT);
	iolib_setdir(button1, INPUT);
	iolib_setdir(button2, INPUT);

	BBBIO_module_ctrl(1);

	BBBIO_channel_ctrl(BBBIO_ADC_AIN6, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1,
	BBBIO_ADC_STEP_AVG_1, analougeInputs[0], 10);

	BBBIO_channel_ctrl(BBBIO_ADC_AIN5, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1,
	BBBIO_ADC_STEP_AVG_1, analougeInputs[1], 10);

	BBBIO_channel_ctrl(BBBIO_ADC_AIN4, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1,
	BBBIO_ADC_STEP_AVG_1, analougeInputs[2], 10);

	BBBIO_channel_ctrl(BBBIO_ADC_AIN1, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1,
	BBBIO_ADC_STEP_AVG_1, analougeInputs[3], 10);

	BBBIO_channel_ctrl(BBBIO_ADC_AIN0, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1,
	BBBIO_ADC_STEP_AVG_1, analougeInputs[4], 10);

	//Enables analogue inputs
	BBBIO_channel_enable(BBBIO_ADC_AIN6);
	BBBIO_channel_enable(BBBIO_ADC_AIN5);
	BBBIO_channel_enable(BBBIO_ADC_AIN4);
	BBBIO_channel_enable(BBBIO_ADC_AIN1);
	BBBIO_channel_enable(BBBIO_ADC_AIN0);
}
Beispiel #8
0
//-----------------------------------------------------------------
int
main(void)
{
	int del =5;
	iolib_init();
	printf("init finish\n");
/*
	BBBIO_GPIO_set_dir(BBBIO_GPIO1 , 0 ,
					BBBIO_GPIO_PIN_12 |
					BBBIO_GPIO_PIN_13 |
                                        BBBIO_GPIO_PIN_14 |
                                        BBBIO_GPIO_PIN_15 );
*/
	BBBIO_sys_Enable_GPIO(BBBIO_GPIO2);

	iolib_setdir(8,11, BBBIO_DIR_OUT);	// Scan A
	iolib_setdir(8,12, BBBIO_DIR_OUT);	// Scan B
        iolib_setdir(8,15, BBBIO_DIR_OUT);	// Scan C
        iolib_setdir(8,16, BBBIO_DIR_OUT);	// Scan D

	iolib_setdir(8,39, BBBIO_DIR_OUT);      // Seg A
	iolib_setdir(8,40, BBBIO_DIR_OUT);      // Seg B
        iolib_setdir(8,41, BBBIO_DIR_OUT);      // Seg C
        iolib_setdir(8,42, BBBIO_DIR_OUT);      // Seg D
        iolib_setdir(8,43, BBBIO_DIR_OUT);      // Seg E
        iolib_setdir(8,44, BBBIO_DIR_OUT);      // Seg F
        iolib_setdir(8,45, BBBIO_DIR_OUT);      // Seg G
        iolib_setdir(8,46, BBBIO_DIR_OUT);      // Seg . (point)


	printf("OK");

	int count = 0;
	int DisplayNumber =1234 ;
	while(count < 200)
	{
		count ++ ;
		pin_low(8,11);
		Display_Number(DisplayNumber / 1000);
		iolib_delay_ms(del);
		pin_high(8,11);

                pin_low(8,12);
                Display_Number(DisplayNumber / 100);
                iolib_delay_ms(del);
                pin_high(8,12);

                pin_low(8,15);
                Display_Number(DisplayNumber / 10);
                iolib_delay_ms(del);
                pin_high(8,15);

                pin_low(8,16);
                Display_Number(DisplayNumber);
                iolib_delay_ms(del);
                pin_high(8,16);
	}
	BBBIO_sys_Disable_GPIO(BBBIO_GPIO2);
	iolib_free();
	return(0);
}
/*
 * Class:     org_bulldog_beagleboneblack_jni_NativeGpio
 * Method:    pinMode
 * Signature: (III)V
 */
JNIEXPORT void JNICALL Java_org_bulldog_beagleboneblack_jni_NativeGpio_pinMode
  (JNIEnv * env, jclass clazz, jint port, jint pin, jint direction) {

	iolib_setdir(port, pin, direction);
}
Beispiel #10
0
//-----------------------------------------------------------------
int
main(void)
{
	struct timeval t_start,t_end;
	pid_t PID ;
	struct sched_param param;
	int maxpri = sched_get_priority_max(SCHED_FIFO);

	param.sched_priority =maxpri ;
	PID =getpid();
//	sched_setscheduler(PID , SCHED_FIFO ,&param );

	iolib_init();
	iolib_setdir(8,11, BBBIO_DIR_OUT);	// Server motor
	iolib_setdir(8,12, BBBIO_DIR_OUT);
	iolib_setdir(8,15, BBBIO_DIR_OUT);
	iolib_setdir(8,16, BBBIO_DIR_OUT);
	iolib_setdir(8,22, BBBIO_DIR_OUT);
        iolib_setdir(8,23, BBBIO_DIR_OUT);
	BBBIO_sys_Enable_GPIO(BBBIO_GPIO2);

	BBBIO_GPIO_set_dir(BBBIO_GPIO2 ,	// key pad pin
                           BBBIO_GPIO_PIN_12 |BBBIO_GPIO_PIN_10 |BBBIO_GPIO_PIN_8 |BBBIO_GPIO_PIN_6 ,   // input
                           BBBIO_GPIO_PIN_13 |BBBIO_GPIO_PIN_11 |BBBIO_GPIO_PIN_9 |BBBIO_GPIO_PIN_7 );  // output

	int i , j ;
	// recover
        ActionPush(SM_BUTTOM ,90 ,0);
        ActionPush(SM_ARM1 ,90 ,0);
        ActionPush(SM_ARM2 ,110 ,0);
        ActionPush(SM_ARM3 ,150 ,0);
        ActionPush(SM_HAND ,90 ,0);
        ActionStart();

	Angle_Arm_1 =90 ;
	Angle_Arm_2 =110 ;
	Angle_Arm_3 =150;
	Angle_Hand =90 ;
	Angle_Buttom = 90 ;

        //-----------------------------------------
        // create 4x4 scan therad

        pthread_t pid_4x4 ;
        int ret ;
        ret = pthread_create(&pid_4x4, NULL, (void *)Thread_4x4_scan, NULL);

        //-----------------------------------------

	usleep(100000);

	float max_Angle =0 ;


for(j=0 ;j <5 ; j ++)
{
	for(i=0 ; i<7 ;i++)
	{
            ActionPush(SM_BUTTOM ,Action[i][0] ,0);
            ActionPush(SM_ARM1 ,Action[i][1] ,0);
            ActionPush(SM_ARM2 ,Action[i][2] ,0);
            ActionPush(SM_ARM3 ,Action[i][3] ,0);
            ActionPush(SM_HAND ,Action[i][4] ,0);
            ActionStart();
	}
}

/*
	while(key_status[3][3]==1)	//f
	{

	    ActionPush(SM_BUTTOM ,Angle_Buttom ,0);
            ActionPush(SM_ARM1 ,Angle_Arm_1 ,0);
            ActionPush(SM_ARM2 ,Angle_Arm_2 ,0);
            ActionPush(SM_ARM3 ,Angle_Arm_3 ,0);
            ActionPush(SM_HAND ,Angle_Hand ,0);

            ActionStart();
	}
*/
        ActionPush(SM_BUTTOM ,90 ,0);
        ActionPush(SM_ARM1 ,90 ,0);
        ActionPush(SM_ARM2 ,110 ,0);
        ActionPush(SM_ARM3 ,150 ,0);
        ActionPush(SM_HAND ,90 ,0);
        ActionStart();

	//---------------------------

	pthread_join(pid_4x4,NULL);
	printf("Finish\n");

	iolib_free();
	return(0);
}
Beispiel #11
0
int main(void)
{
	int rc;
	iolib_init();
	iolib_setdir(9,12, DIR_OUT);

    int socket;
    modbus_t *ctx;
    modbus_mapping_t *mb_mapping;

    ctx = modbus_new_tcp("192.168.1.100", 502);
    modbus_set_debug(ctx, TRUE);

    mb_mapping = modbus_mapping_new(10, 10, 10, 10);
    if (mb_mapping == NULL) {
        fprintf(stderr, "Failed to allocate the mapping: %s\n",
                modbus_strerror(errno));
        modbus_free(ctx);
        return -1;
    }

    socket = modbus_tcp_listen(ctx, 1);
    modbus_tcp_accept(ctx, &socket);

    for (;;) {
        uint8_t query[MODBUS_TCP_MAX_ADU_LENGTH];
        int rc;

        rc = modbus_receive(ctx, query);



	if (rc != -1) {
            /* rc is the query size */
            modbus_reply(ctx, query, rc, mb_mapping);

    if((*mb_mapping).tab_bits[1] == 1) {
		 pin_high(9,12);
    }

    else if((*mb_mapping).tab_bits[1] == 0) {
		 pin_low(9,12);
   }





	} else {
            /* Connection closed by the client or error */
            break;
        }
    }



    printf("Quit the loop: %s\n", modbus_strerror(errno));

    modbus_mapping_free(mb_mapping);
    close(socket);
    modbus_free(ctx);

    return 0;
}
Beispiel #12
0
int main(int argc, char *argv[])
{
    int i = 0;
    unsigned char datatosend[20] = {0,1,2,3,4,5,6,7,8,9};
    unsigned char tmp_payload_xmit[PAYLOAD_BUF_LEN];

#ifdef MULTIPLE_COMMANDS

    char command[MAX_COMMAND_LEN];
    char string1[TXT_STR_LEN], string2[TXT_STR_LEN] = "quit";
    char default_argv[] = "";
    int i = 0;

#endif  //MULTIPLE_COMMANDS

#ifndef DEBUG

#ifdef USE_SPI

    //Open SPI:
    flexsea_spi_open();

    //Initialize IO library:
    iolib_init();
    iolib_setdir(RESET_PORT, RESET_PIN, DIR_OUT);
    pin_low(RESET_PORT, RESET_PIN);

#endif

#else

    printf("\nFlexSEA-Plan - Debug or Native USB\n==================================\n\n");

#ifdef USE_USB

    //Open USB (serial) port:
    flexsea_serial_open(100, 50000);

    /*

    	//Test code
    	for(i = 0; i < 30; i++)
    	{
    		tx_cmd_ctrl_mode(FLEXSEA_EXECUTE_2, CMD_WRITE, tmp_payload_xmit, PAYLOAD_BUF_LEN, CTRL_OPEN);
    		comm_gen_str(tmp_payload_xmit, comm_str_spi, PAYLOAD_BUF_LEN);
    		flexsea_serial_transmit(COMM_STR_BUF_LEN, comm_str_spi, 0);
    	}
    	*/

#endif

#endif

#ifdef MULTIPLE_COMMANDS

    while(fgets(command, sizeof(command), stdin))
    {
        int fake_argc = 1;

        //Fills fake_argv with empty strings to avoid sending old values with new commands
        for(i = 0; i < MAX_ARGS; i++)
        {
            fake_argv[i] = default_argv;
        }

        //First argument
        fake_argv[fake_argc] = strtok(command, delims);

        //Other arguments
        while( fake_argv[fake_argc] != NULL )
        {
            fake_argv[++fake_argc] = strtok(NULL, delims);
        }

        //Enable for terminal debug only:
        /*
        for(i = 0; i < MAX_ARGS; i++)
        {
            printf("fake_argv[%i] = %s\n", i, fake_argv[i]);
        }
         */

        //Do we want to exit? (exit when "quit" is received)
        strcpy(string1, fake_argv[1]);
        if(!strcmp(string1, string2))
        {
            printf("Quitting.\n");
            break;
        }
        else
        {
            //Parser for console commands:
            flexsea_console_parser(fake_argc, fake_argv);

            //Can we decode what we received?
            decode_spi_rx();
        }
    }

#endif  //MULTIPLE_COMMANDS

#ifdef SINGLE_COMMAND

    //Parser for console commands:
    parser_console(argc, argv);

    //Can we decode what we received?

#ifdef USE_SPI

    decode_spi_rx();

#endif

#ifdef USE_USB

    //decode_usb_rx();	ToDo

#endif

#endif  //SINGLE_COMMAND

#ifndef DEBUG

#ifdef USE_SPI

    //Close SPI:
    flexsea_spi_close();

    iolib_free();

#endif

#ifdef USE_USB

    //Close serial port:
    flexsea_serial_close();

#endif

#endif

    return 0;
}
Beispiel #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;
}