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); }
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); }
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); }
/* * Class: org_bulldog_beagleboneblack_jni_NativeGpio * Method: setup * Signature: ()Z */ JNIEXPORT jboolean JNICALL Java_org_bulldog_beagleboneblack_jni_NativeGpio_setup (JNIEnv * env, jclass clazz) { int ret = iolib_init(); if(ret < 0) { return JNI_FALSE; } return JNI_TRUE; }
//------------------------------------------------------------------------------------- void keypad_4x4_init() { iolib_init(); BBBIO_sys_Enable_GPIO(BBBIO_GPIO2); // P8_39 / P8_41 / P8_43 / P8_45 as input // P8_40 / P8_42 / P8_44 / P8_46 as input // GPIO mapping reference from BBB_SRM , page 80 , "Table 11. Expansion Header P8 Pinout" BBBIO_GPIO_set_dir(BBBIO_GPIO2 , 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 main(void) { int i ,j; unsigned int *buf_ptr = &buffer[0]; /* BBBIOlib init*/ iolib_init(); /* using ADC_CALC toolkit to decide the ADC module argument . * * #./ADC_CALC -f 44100 -t 30 * * Suggest Solution : * Clock Divider : 34 , Open Dly : 1 , Sample Average : 1 , Sample Dly : 1 */ const int clk_div = 34 ; const int open_dly = 1; const int sample_dly = 1; BBBIO_ADCTSC_module_ctrl(clk_div); BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN0, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, open_dly, sample_dly, BBBIO_ADC_STEP_AVG_1, buffer, AUDIO_BUFFER_SIZE); struct timeval t_start,t_end; float mTime =0; for(i = 0 ; i < 5 ; i++) { /* fetch data from ADC */ BBBIO_ADCTSC_channel_enable(BBBIO_ADC_AIN0); gettimeofday(&t_start, NULL); BBBIO_ADCTSC_work(AUDIO_BUFFER_SIZE); gettimeofday(&t_end, NULL); /* ********************************************************** * * Add your Socket transmit function in this block * ************************************************************* */ mTime = (t_end.tv_sec -t_start.tv_sec)*1000000.0 +(t_end.tv_usec -t_start.tv_usec); mTime /=1000000.0f; printf("Sampling finish , fetch [%d] samples in %lfs\n", AUDIO_BUFFER_SIZE, mTime); } BBBIO_ehrPWM_Disable(BBBIO_PWMSS0); iolib_free(); return 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); }
int main(void) { iolib_init(); int i=0; float SM_1_duty ; //Sermotor 1 , connect to ePWM0A for(i=0 ;i<= 180 ;i+=10) { SM_1_duty = 4.0f + i* 0.04444f ; printf("Angle : %d , duty : %f\n" ,i ,SM_1_duty); BBBIO_PWMSS_Setting(0 , 50.0f ,SM_1_duty , SM_1_duty); sleep(1); } iolib_free(); return(0); }
/* ----------------------------------------------------------- */ int main(void) { unsigned int sample; int i ,j; unsigned int buffer_AIN_0[100] ={0}; unsigned int buffer_AIN_1[100] ={0}; /* BBBIOlib init*/ iolib_init(); /*ADC work mode : Busy polling mode */ //BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_BUSY_POLLING, 1); BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_TIMER_INT, 1); /*ADC work mode : Timer interrupt mode * Note : This mode handle SIGALRM using signale() function in BBBIO_ADCTSC_work(); */ //BBBIO_ADCTSC_module_ctrl(BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_BUSY_POLLING, 1); BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN0, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1, BBBIO_ADC_STEP_AVG_1, buffer_AIN_0, 100); BBBIO_ADCTSC_channel_enable(BBBIO_ADC_AIN0); BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN1, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1, BBBIO_ADC_STEP_AVG_1, buffer_AIN_1, 100); BBBIO_ADCTSC_channel_enable(BBBIO_ADC_AIN1); for(i = 0 ; i < 3 ; i++) { printf("Start sample , fetch 10 sample \n"); BBBIO_ADCTSC_work(10); printf("Channel 0 :\n"); for(j = 0 ; j < 10 ; j++) { sample = buffer_AIN_0[j]; printf("\t[sample : %d , %f v]\n", sample, ((float)sample / 4095.0f) * 1.8f); } printf("Channel 1 :\n"); for(j = 0 ; j < 10 ; j++) { sample = buffer_AIN_1[j]; printf("\t[sample : %d , %f v]\n", sample, ((float)sample / 4095.0f) * 1.8f); } printf("------------------------------\n"); sleep(1); } iolib_free(); return 0; }
void bbio::open(){ // GPIO init init(); init_pins(); // ALL 5 pins are HIGH except for GND init_DAConvAD5328(); //BBBIO init iolib_init(); BBBIO_sys_Enable_GPIO(BBBIO_GPIO1); BBBIO_GPIO_set_dir(BBBIO_GPIO1 , port_dout_SPI[0] , port_din_SPI[0] | port_clk_SPI[0] | port_cs_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_din_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_clk_SPI[0]); BBBIO_GPIO_low(BBBIO_GPIO1 ,port_cs_SPI[0]); }
int main(void) { iolib_init(); /* Initialize I/O library - required */ pthread_t thread1, thread2,thread3, main_id; //initial the data buffer and create the threads main_id=pthread_self(); buffer_init(b); pthread_create( &thread1, NULL, &producerth1, NULL); pthread_create( &thread2, NULL, &producerth2, NULL); pthread_create( &thread3, NULL, &comsumerth, NULL); //join the thread when finished pthread_join( thread1, NULL); pthread_join( thread2, NULL); pthread_join( thread3, NULL); iolib_free(); /* Release I/O library prior to program exit - required */ return(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); }
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; }
/* init_ADC() - Initialize hardware to perform ADC sampling clk_div = 160 sets the rate to 10 kHz. */ void init_ADC(void) { iolib_init(); set_clk_div(160); }
//----------------------------------------------------------------- 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 ,¶m ); 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); }
/* ----------------------------------------------------------- */ int main(void) { unsigned int sample; int i ,j; unsigned int buffer_AIN_0[BUFFER_SIZE] ={0}; unsigned int buffer_AIN_1[BUFFER_SIZE] ={0}; /* BBBIOlib init*/ iolib_init(); /* using ADC_CALC toolkit to decide the ADC module argument . Example Sample rate : 10000 sample/s * * #./ADC_CALC -f 10000 -t 5 * * Suggest Solution : * Clock Divider : 160 , Open Dly : 0 , Sample Average : 1 , Sample Dly : 1 * */ // const int clk_div = 34 ; const int clk_div = 160; const int open_dly = 0; const int sample_dly = 1; /*ADC work mode : Timer interrupt mode * Note : This mode handle SIGALRM using signale() function in BBBIO_ADCTSC_work(); */ BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_TIMER_INT, clk_div); /*ADC work mode : Busy polling mode */ /* BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_BUSY_POLLING, clk_div);*/ BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN0, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, open_dly, sample_dly, \ BBBIO_ADC_STEP_AVG_1, buffer_AIN_0, BUFFER_SIZE); BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN1, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, open_dly, sample_dly, \ BBBIO_ADC_STEP_AVG_1, buffer_AIN_1, BUFFER_SIZE); //BBBIO_ADCTSC_module_ctrl(BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_BUSY_POLLING, 1); // BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN1, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1, BBBIO_ADC_STEP_AVG_1, buffer_AIN_1, 100); for(i = 0 ; i < 3 ; i++) { printf("Start sample , fetch %d sample \n", BUFFER_SIZE); BBBIO_ADCTSC_channel_enable(BBBIO_ADC_AIN0); BBBIO_ADCTSC_channel_enable(BBBIO_ADC_AIN1); BBBIO_ADCTSC_work(SAMPLE_SIZE); printf("AIN 0 :\n"); for(j = 0 ; j < SAMPLE_SIZE ; j++) { sample = buffer_AIN_0[j]; printf("\t[sample : %d , %f v]\n", sample, ((float)sample / 4095.0f) * 1.8f); } printf("AIN 1 :\n"); for(j = 0 ; j < SAMPLE_SIZE ; j++) { sample = buffer_AIN_1[j]; printf("\t[sample : %d , %f v]\n", sample, ((float)sample / 4095.0f) * 1.8f); } printf("------------------------------\n"); sleep(1); } iolib_free(); return 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); }
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; }
/* ----------------------------------------------------------- */ int main(void) { unsigned int sample; int i ,j; unsigned int buffer_AIN_2[BUFFER_SIZE] ={0}; time_t rawtime; char data_file_name[255]; FILE* data_file; /* BBBIOlib init*/ iolib_init(); /* using ADC_CALC toolkit to decide the ADC module argument . Example Sample rate : 10000 sample/s * * #./ADC_CALC -f 10000 -t 5 * * Suggest Solution : * Clock Divider : 160 , Open Dly : 0 , Sample Average : 1 , Sample Dly : 1 * */ // const int clk_div = 34 ; // ADC sampling settings const int clk_div = 25; const int open_dly = 5; const int sample_dly = 1; /*ADC work mode : Timer interrupt mode * Note : This mode handle SIGALRM using signale() function in BBBIO_ADCTSC_work(); */ BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_TIMER_INT, clk_div); // use timer interrupts /*ADC work mode : Busy polling mode */ /* BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_BUSY_POLLING, clk_div);*/ // microphone is connected to AIN2 BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN2, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, open_dly, sample_dly, \ BBBIO_ADC_STEP_AVG_1, buffer_AIN_2, BUFFER_SIZE); //BBBIO_ADCTSC_module_ctrl(BBBIO_ADCTSC_module_ctrl(BBBIO_ADC_WORK_MODE_BUSY_POLLING, 1); // BBBIO_ADCTSC_channel_ctrl(BBBIO_ADC_AIN1, BBBIO_ADC_STEP_MODE_SW_CONTINUOUS, 0, 1, BBBIO_ADC_STEP_AVG_1, buffer_AIN_1, 100); printf("Starting capture...\n"); // get time time(&rawtime); // start capture BBBIO_ADCTSC_channel_enable(BBBIO_ADC_AIN2); BBBIO_ADCTSC_work(SAMPLE_SIZE); // format file name snprintf(data_file_name, sizeof(data_file_name), "%s", ctime(&rawtime)); //copy time to string data_file_name[strcspn(data_file_name,"\n")] = 0; //remove trailing newline // convert space to _ in filename char *p = data_file_name; for (i=0; i < strlen(data_file_name); i++){ if (data_file_name[i] == '\0') break; else if (data_file_name[i] == ' ') data_file_name[i] = '_'; } strcat(data_file_name,".dat" ); printf("saving sound data to: %s\n",data_file_name); data_file = fopen(data_file_name,"w"); // open file in write mode // add current time value to top of file fprintf(data_file, "%s", ctime(&rawtime)); // write buffer to file for(j = 0 ; j < SAMPLE_SIZE ; j++) fprintf( data_file, "%u\n", buffer_AIN_2[j] ); fclose( data_file ); iolib_free(); return 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; }