void Sortie_Locale::initialization() {

	export_gpio("22");
	export_gpio("23");
	export_gpio("24");
	export_gpio("25");
	setdir_gpio("out", "22");
	setdir_gpio("out", "23");
	setdir_gpio("out", "24");
	setdir_gpio("out", "25");
}
void Sortie_Locale::initializationAll()
{

	/*for (int i=0;i<liste.size();i++)
		{
		    export_gpio(liste[i]);
		    setdir_gpio("out", liste[i]);
		}*/

    export_gpio("4");
    setdir_gpio("out", "4");
    export_gpio("17");
    setdir_gpio("out", "17");
    export_gpio("18");
    setdir_gpio("out", "18");
    export_gpio("21");
    setdir_gpio("out", "21");
    export_gpio("22");
    setdir_gpio("out", "22");
    export_gpio("23");
    setdir_gpio("out", "23");
    export_gpio("24");
    setdir_gpio("out", "24");
    export_gpio("25");
    setdir_gpio("out", "25");


}
Example #3
0
void init(void) {
	//Setup LED0 as GPIO OUT
	export_gpio(LED0);
	set_gpio_direction(LED0, "out");
	set_gpio_value(LED0, led0_value);
	led0_fd = gpio_fd_open(LED0);

	//Setup MUX for PWM on LED1
	set_mux_value(LED1_MUX, LED1_MUX_VAL);
	set_pwm(LED1_PWM, LED1_PWM_FREQ, read_ain(POT)/41); //Divide by 41 to put in the range [0, 99]

	//Setup button as GPIO IN
	export_gpio(BUTTON);
	set_gpio_direction(BUTTON, "in");
	set_gpio_edge(BUTTON, "rising");
	button_fd = gpio_fd_open(BUTTON);
}
Example #4
0
HT1632::HT1632(uint8_t bank, int8_t data, int8_t wr, int8_t cs, int8_t rd) {
  _data = data;
  _wr = wr;
  _cs = cs;
  _rd = rd;

  export_gpio(bank * 32 + _data);
  set_gpio_direction(bank * 32 + _data, "out");
  export_gpio(bank * 32 + _wr);
  set_gpio_direction(bank * 32 + _wr, "out");
  export_gpio(bank * 32 + _cs);
  set_gpio_direction(bank * 32 + _cs, "out");
  export_gpio(bank * 32 + _rd);
  set_gpio_direction(bank * 32 + _rd, "out");
  
  gpiobank = new GPIO_MMAP(bank);

  if (_cs > 0) {
    gpiobank->write(_cs, 1);
  }
  if (_wr > 0) {
    gpiobank->write(_wr, 1);
  }
  if (_data > 0) {
    gpiobank->write(_data, 1);
  }
  if (_rd > 0) {  
    gpiobank->write(_rd, 1);
  }
  
  for (uint8_t i=0; i<48; i++) {
    ledmatrix[i] = 0;
  }
  
  ts.tv_sec = 0;
  ts.tv_nsec = DELAY;
}
Example #5
0
void RangeFinder::start() {
	nfds = 2;

	// Set the signal callback for Ctrl-C
	//		signal(SIGINT, signal_handler);

	//		gpio = atoi(argv[1]);

	export_gpio();
	set_gpio_direction(0);
	set_gpio_edge("both"); // Can be rising, falling or both
	gpio_fd = gpio_fd_open();

	threadRunning = 1;
	pthread_create(&rangeFinderThread_t, 0, &RangeFinder::start_thread, this);
}
Example #6
0
int main(int argc, char** argv){
	
	//variable declarations
	struct pollfd fdset[1];
	int nfds = 1;
	int timeout = 3000;
	int rc;
	char* buf[MAX_BUF];	
	int gpio1, gpio2;
	int gpio1_fd, gpio2_fd;
	int gpio2_value = 0;
	int pattern =0;
	int value =0;
	char *end;
	int res, i2cbus, address, size, file;
	int daddress;
	char filename[20];
	

	//Setting the signal handler for Ctrl + C
	if (signal(SIGINT, signal_handler) == SIG_ERR)
		printf("\ncan't catch SIGINT\n");


	//Argument checking for at least five
	if(argc < 6){
		printf("Usage: %s <input-gpio> <output-gpio> <i2c-bus> <i2c-address> <register>\n", argv[0]);
		printf("polls input-gpio, and writes value to output-gpio\n");
		fflush(stdout);
		return 1;
	}

	//Assigning gpio values
	gpio1 = atoi(argv[1]);
	gpio2 = atoi(argv[2]);

	//Input for Argument 1
	export_gpio(gpio1);
	set_gpio_direction(gpio1, "in");
	set_gpio_edge(gpio1, "falling");
	gpio1_fd = gpio_fd_open(gpio1);
	
	//Output for Argument 2
	export_gpio(gpio2);
	set_gpio_direction(gpio2, "out");
	set_gpio_value(gpio2, gpio2_value);
	gpio2_fd = gpio_fd_open(gpio2);

	//Assigning I2C values
	i2cbus   = atoi(argv[3]);
	address  = atoi(argv[4]);
	daddress = atoi(argv[5]);
	size = I2C_SMBUS_BYTE;

	sprintf(filename, "/dev/i2c-%d", i2cbus);
	file = open(filename, O_RDWR);
	if (file<0) {
		if (errno == ENOENT) {
			fprintf(stderr, "Error: Could not open file "
				"/dev/i2c-%d: %s\n", i2cbus, strerror(ENOENT));
		} else {
			fprintf(stderr, "Error: Could not open file "
				"`%s': %s\n", filename, strerror(errno));
			if (errno == EACCES)
				fprintf(stderr, "Run as root?\n");
		}
		exit(1);
	}

	if (ioctl(file, I2C_SLAVE, address) < 0) {
			fprintf(stderr,
				"Error: Could not set address to 0x%02x: %s\n",
				address, strerror(errno));
			return -errno;
	}
	

	while(loop){
		memset((void*)fdset, 0, sizeof(fdset));
	
		fdset[0].fd = gpio1_fd;
		fdset[0].events = POLLPRI;

		rc = poll(fdset, nfds, timeout);

		if (rc < 0){
			printf("\npoll() failed!\n");
		}
	
		if (rc == 0){
			printf(".");
		}

		if((fdset[0].revents & POLLPRI) == POLLPRI) {
			read(fdset[0].fd, buf, MAX_BUF);
			printf("interrupt value=%c\n", buf[0]);
			pattern++;
		if(pattern == 4){
		pattern = 0;
		}
		}			
		
	


	printf("Case %d\n",pattern);
	
	switch(pattern){
	
	// Blink led 
	case 0:
		if(gpio2_value){
		gpio2_value = 0;
		}
		else{
		gpio2_value = 1;
		}
		set_gpio_value(gpio2, gpio2_value);
	break;
	// PWM output for blinking LED by frequency and duty cycle  	
	case 1:	 
		set_mux_value("gpmc_a2",6);
		set_pwm("ehrpwm.1:0",10,25);
	break;
	// Analog In for reading Voltage from POT
	case 2: unset_pwm("ehrpwm.1:0");
		value = read_ain("ain6");
		printf("Voltage: %d\n",value);
	break;	
	
	// I2C Device reading temperature from the sensor
	case 3:
		printf("Case 3\n");
		res = i2c_smbus_write_byte(file, daddress);
		if (res < 0) {
			fprintf(stderr, "Warning - write failed, filename=%s, daddress=%d\n",
				filename, daddress);
		}
		res = i2c_smbus_read_byte_data(file, daddress);
		if (res < 0) {
			fprintf(stderr, "Error: Read failed, res=%d\n", res);
			exit(2);
		}

		printf("Temperature: %d°C\n", res);
		break;
	default:
		break;

	}
	}
	
	close(file);
	gpio_fd_close(gpio1_fd);
	gpio_fd_close(gpio2_fd);
	unexport_gpio(gpio1);
	unexport_gpio(gpio2);
	fflush(stdout);
	return 0;
}
Example #7
0
int main(int argc, char** argv){
	
	//variable declarations
	struct pollfd fdset[1];
	int nfds = 1;
	int timeout = 100;
	int rc;
	char* buf[MAX_BUF];	
	
	int gpio1, gpio2, gpio_count1, gpio_count2;
	int gpio1_fd, gpio2_fd;
	int gpio2_value = 0;
	int program = 0;
	int ain = 0;
	float duty_cycle = 0;
	int i2c_read;
		
	//check that at least two arguments are passed in
	if(argc < 3){
		printf("Usage: %s <input-gpio> <output-gpio>\n", argv[0]);
		printf("polls input-gpio, and writes value to output-gpio\n");
		fflush(stdout);
		return 1;
	}

	//set signal handler
	if (signal(SIGINT, signal_handler) == SIG_ERR)
		printf("\ncan't catch SIGINT\n");

	//assign gpio values
	gpio1 = atoi(argv[1]);
	gpio2 = atoi(argv[2]);

	//argument 1 will be input
	export_gpio(gpio1);
	set_gpio_direction(gpio1, "in");
	set_gpio_edge(gpio1, "falling");
	gpio1_fd = gpio_fd_open(gpio1);

	//argument 2 will be output
	export_gpio(gpio2);
	set_gpio_direction(gpio2, "out");
	set_gpio_value(gpio2, gpio2_value);
	gpio2_fd = gpio_fd_open(gpio2);

	//prepare gpio_count1 and gpio_count2
	gpio_count1 = 30;
	gpio_count2 = 31;
	export_gpio(gpio_count1);
	export_gpio(gpio_count2);
	set_mux_value("gpmc_wait0",7);
	set_gpio_direction(gpio_count1, "out");
	set_gpio_direction(gpio_count2, "out");
	

	//prepare i2c bus
	int file;
	

	while(keepgoing){
		memset((void*)fdset, 0, sizeof(fdset));
	
		fdset[0].fd = gpio1_fd;
		fdset[0].events = POLLPRI;

		//fdset[1].fd = gpio2_fd;
		//fdset[1].events = POLLPRI;

		rc = poll(fdset, nfds, timeout);

		if (rc < 0){
			printf("\npoll() failed!\n");
		}

		if((fdset[0].revents & POLLPRI) == POLLPRI) {
			read(fdset[0].fd, buf, MAX_BUF);
			usleep(100);
			gpio2_value = ~(gpio2_value)&1;
			set_gpio_value(gpio2, gpio2_value);
			program++;
			if(program > 3) program = 0;
			set_gpio_value(gpio_count1, program & 1);
			set_gpio_value(gpio_count2, program & 2);
		}			
		
	
		switch(program){
			case 0:
				duty_cycle = read_ain("ain6");
				duty_cycle = duty_cycle/4095 * 100;
				set_mux_value("gpmc_a2", 6);
				set_pwm("ehrpwm.1:0", 1000, (int) duty_cycle);

			break;

			case 1:
				ain = read_ain("ain6");
				printf("ain5 = %d\n", ain);
				unset_pwm("ehrpwm.1:0");
			break;

			case 2: 
				unset_pwm("ehrpwm.1:0");
			break;

			case 3:
				if((file = open("/dev/i2c-3", O_RDWR)) < 0){
					printf("failed to open i2c-3 bus\n");
					return 1;
				}

				if (ioctl(file, I2C_SLAVE, 72) < 0){
					printf("Could not set address for i2c\n");
					return 1;
				}
				i2c_read = i2c_smbus_read_byte_data(file, 0);
				close(file);
				printf("0x%02x (%d)\n", i2c_read, i2c_read);
			break;

			default:
			break;

		}
	}

	gpio_fd_close(gpio1_fd);
	gpio_fd_close(gpio2_fd);
	unexport_gpio(gpio1);
	unexport_gpio(gpio2);
	unexport_gpio(gpio_count1);
	unexport_gpio(gpio_count2);
	unset_pwm("ehrpwm.1:0");
	set_mux_value("gpmc_a2", 7);

	fflush(stdout);
	return 0;
}