示例#1
0
int main(int argc, char *argv[]) {
	int i,j,k,portFD;
	unsigned char data[1024];

	gettimeofday(&tStart,NULL);

	output(1,"HP iPAQ 214 BT chip GPIO twiddling util v1.1\n----------------------------------\n");

#ifndef NOIO
	gpioInit(1);
#else
	output(1,"TESTING MODE - NOT USING IO\n");
#endif
	
	if(argc > 1 && strcmp(argv[1],"on")==0){
		portFD=openPort();
		if(portFD == -1){ return 0; }

		output(1,"Shutting down chip first...\n");
#ifndef NOIO
		shutdownChip();
		tcflush(portFD, TCIOFLUSH); //flush buffers again
#endif
		output(1,"Waiting 2 secs.\n");
		sleep(2);

		output(1,"Bringing up chip...\n");
		bringUpChip();

		output(1,"Resetting chip...\n");
#ifndef NOIO
		sendReset(portFD);	
#endif

		output(1,"Turning LED on.\n");
#ifndef NOIO
		gpioSet(3,1);
#endif
	
		output(1,"closing port...");	fflush(stdout);
		close(portFD);
		output(1,"done\n");

	}else if(argc > 1 && strcmp(argv[1],"off")==0){
		output(1,"Shutting down chip...\n");
#ifndef NOIO
		shutdownChip();
		gpioSet(3,0);	//turn LED off
#endif
	
	}else
		printf("usage %s on/off\n",argv[0]);
	
	
#ifndef NOIO
	gpioCleanup();
#endif
	
	return 0;
}
示例#2
0
int main () {

    if (gpioSetup() != OK)
    {
        dbgPrint(DBG_INFO, "gpioSetup failed. Exiting\n");
        return 1;
    }


    seq_handle = open_seq();
	connect2MidiThroughPort(seq_handle);

    init_cmd_defaults();

    while (1) {
	midi_read();
    }

    snd_seq_close (seq_handle);
	gpioCleanup();
    return (0);
}
示例#3
0
int main(int argc, char **argv){	
	int i,j;
	int gpio[128];
	int oldstate[128], state[128];
	int ngpios;
	struct timeval tv;
	fd_set read_fd;
	char *str = NULL;
	int lenStr = 0;

	ngpios = argc - 1;
	
	for(i=0;i<128;i++)
		gpio[i] = -1;

	for(i=0;i<ngpios;i++){
		j = atoi(argv[i+1]);
		gpio[i] = j;
		oldstate[i] = -1;
	}

	#ifndef NOIO
	gpioInit();
	#endif

	do{
		tv.tv_sec=0;
		tv.tv_usec=1000;
		FD_ZERO(&read_fd);
		FD_SET(0,&read_fd);
	
		if(select(1, &read_fd,NULL,NULL,&tv) == -1)
			return 0;
	
		if(FD_ISSET(0,&read_fd)){
			
			getline(&str, &lenStr, stdin);
			i=strlen(str);
			if(str[i-1] =='\n')
				str[i-1] = 0x00;

			if(str == NULL)	
				break;

			if(str[0] == 'q')
				break;

			else if(str[0] == 'o'){
				printf("GPIO #:");
				getline(&str, &lenStr, stdin);
				i=atoi(str);

				#ifndef NOIO
				if(i >=0 && i < 128)
					gpioSetDir(i, 1);
				#endif
				printf("%i --> output\n",i);
			}else if(str[0] == 'i'){
				printf("GPIO #:");
				getline(&str, &lenStr, stdin);
				i=atoi(str);
				
				#ifndef NOIO
				if(i >=0 && i < 128)
					gpioSetDir(i, 0);
				#endif
				printf("%i --> input\n",i);
			}else if( str[0] >= '0' && str[0] <='9'){ //toggle
				i = atoi(str);
				if(i >=0 && i < 128){
					#ifndef NOIO
					j = gpioGet(i);
					printf("%i: %i --> %i\n",i,j,!j);
					gpioSet(i, !j);
					#endif
				}
			}
		}

		
		for(i=0;i<ngpios;i++){
			#ifdef NOIO
			state[i] = 0;
			#else
			state[i] = gpioGet( gpio[i] );
			#endif

			if( state[i] != oldstate[i] )
				printf("%i: %i --> %i\n",gpio[i],oldstate[i],state[i]);
			oldstate[i] = state[i];
		}


	}while(1);
	
	#ifndef NOIO
	gpioCleanup();
	#endif

	if(str != NULL)
		free(str);

	return 0;
}
示例#4
0
void mma8491CleanUp()
{
    gpioCleanup(gpio);
    i2cCleanUp(i2cDev);
}