Пример #1
0
void
init_esbe3_drv ()
{

  /*
   * Export digital pin for "slow-PWM"
   */
  if ((-1 == GPIOExport (POUT_INC)) || (-1 == GPIOExport (POUT_DEC)))
    {
      ml_log (LOG_ERROR, "Failed to export GPIO pins");
      raise (SIGTERM);
    }
  /*
   * Set GPIO directions
   */
  if ((-1 == GPIODirection (POUT_INC, OUT))
      || (-1 == GPIODirection (POUT_DEC, OUT)))
    {
      ml_log (LOG_ERROR, "Failed to set GPIO pins as output");
      raise (SIGTERM);
    }

  if ((-1 == GPIOWrite (POUT_INC, 0)) || (-1 == GPIOWrite (POUT_INC, 0)))
    {
      ml_log (LOG_ERROR, "Error reading %s, errno =%d, rasing SIGTERM");
      raise (SIGTERM);
    }
}
Пример #2
0
int test(int pIn){

    int repeat = 10;
 
    if (-1 == GPIOExport(POUT) || -1 == GPIOExport(PIN)){
        return(1);
    }
 
    if (-1 == GPIODirection(POUT, OUT)){
        return(2);
    }
 
    do {
        if (-1 == GPIOWrite(POUT, repeat % 2)){
            return(3);
        }
        usleep(100 * 1000);
    }
    while (repeat--);
 
    if (-1 == GPIOUnexport(POUT)){
        return(4);
    }
 
    return(0);
}
Пример #3
0
bool GPIOSetup(unsigned int pino,unsigned int direcao){
	if(GPIOExport(pino) == false)	return false;
	else{
		if(GPIODirection(pino,direcao)== false)	return false;
		else 	return true;
	}
}
Пример #4
0
int main(int argc, char *argv[])
{
	/*
	 * Enable GPIO pins
	 */
	if (-1 == GPIOExport(PIN))
		return(1);

	/*
	 * Set GPIO directions
	 */
	if (-1 == GPIODirection(PIN, IN))
		return(2);

	while (!terminated)
	{
		usleep(500 * 1000);
		if (GPIORead(PIN) == LOW)
		{
			terminated = 1;
			if (system("shutdown -h now") == -1)
				fprintf(stderr, "Failed to initiate shutdown!\n");
		}
	}

	/*
	 * Disable GPIO pins
	 */
	if (-1 == GPIOUnexport(PIN))
		return(3);

	return(0);
}
Пример #5
0
/**
 * Turn a pin on and off
 * @param pout the pin to toggle
 * @param time how long to hold the pin in milliseconds
 */
int blinkLED(int pout, int time) {

    //export pin and set as output
    if (-1 == GPIOExport(pout)) {
        return (1);
    }

    //delay to allow sysfs to open up gpio files
    usleep(200 * 1000);

    if (-1 == GPIODirection(pout, OUT)) {
        return (2);
    }

    if (-1 == GPIOWrite(pout, HIGH)) {
        return (3);
    }
    usleep(1000 * time);
    if (-1 == GPIOWrite(pout, LOW)) {
        return (3);
    }

    if (-1 == GPIOUnexport(pout)) {
        return (4);
    }
    return (0);
}
Пример #6
0
int main(int argc, char *argv[])
{
	
	unsigned char in_ch=0,get_nib=0;
        pthread_t uit,sit,cit;
	char hostname[15],pass[10],grp[12],stat[10];
	
	http.host = &hostname[0];	
        http.password = &pass[0];
        http.name = &grp[0];
        http.status = &stat[0];

        strcpy(hostname,"129.63.205.75");
        http.port = 8000;
        http.id =2 ;
        strcpy(pass,"gkrd");
        strcpy(grp,"microex");
        strcpy(stat,"OK");
	init_rtc();

	if (-1 == GPIOExport(STB) || -1 == GPIOExport(GP0) || -1 == GPIOExport(GP1) || -1 == GPIOExport(GP2) || -1 == GPIOExport(GP3))
	return(1);
	/*
	* Set GPIO directions
	*/

	if (-1 == GPIODirection(STB, OUT))
	return(2);
	GPIOWrite(STB, LOW);
        
        printf("\n intializing processes .... ") ;    
            
        pthread_create(&uit,NULL,UI_thread,NULL); 
        pthread_create(&sit,NULL,sense_thread,NULL);
        pthread_create(&cit,NULL,client_thread,NULL); 
        
	pthread_join(uit,NULL);
	pthread_join(sit,NULL);
	pthread_join(cit,NULL);
           
	return(4);
}
Пример #7
0
// Overwrite, sets the pin direction
void pinMode(int pin, ePinMode direction)
{
	if (GPIOExport(pin) == -1 ) {
		printf("Failed to enable pins");
		abort();
	}
	
	if ( GPIODirection(pin, direction) == -1) {
		printf("Failed to set pin directions");
		abort();
	}
}
Пример #8
0
int main(void){
	for(int cont =0;cont < 3; cont++){
		GPIOExport(linha[cont]);
		GPIODirection(linha[cont],SAIDA);
	}
	for(int cont =0;cont < 4; cont++){
		GPIOExport(coluna[cont]);
		GPIODirection(coluna[cont],SAIDA);
	}
	while(1){
		for(int cont = 0 ; cont < 4 ; cont++){
			for(int cont1 = 0 ; cont1 < 3;cont1++){
				GPIOWrite(coluna[cont],HIGH);
				GPIOWrite(linha[cont1],HIGH);
				delay_s(1);
				GPIOWrite(linha[cont1],LOW);
			}
				GPIOWrite(coluna[cont],LOW);
		}
	}
}
ConnectionStatusType C_Flasher_IO_GPIO::connect()
{
    /*
     * Enable GPIO pins
     */
    if (GPIO_FAILURE == GPIOExport(GPIO_OUTPUT_PIN))
    {
        return GPIO_FAILURE;
    }

    /*
     * Set GPIO directions
     */
    if (GPIO_FAILURE == GPIODirection(GPIO_OUTPUT_PIN, GPIO_OUT)) 
    {
        return GPIO_FAILURE;
    }


    connectionStatus = CONNECTED;
    return connectionStatus;
}
Пример #10
0
/**
 * init pin
 */ 
int init_pin(int pin, int inout) {
	/*
	 * enable io port
	 */ 

	log_message(DEBUG, "Trying to enable Pin %d.",pin);
	if (-1 == GPIOExport(pin)) {
		log_message(ERROR, "could not enable GPIO-%d",pin);
		return(1);
	}

	/*wait for system acting..*/
	
	int i;
	for(i = 0; i < 100000; i++); 
	/*
	 * Set GPIO directions
	 */
	log_message(DEBUG, "Setting direction %d for Pin %d.",inout, pin);
	if (-1 == GPIODirection(pin, inout)) {
		log_message(ERROR, "could set direction pin on %x", pin);
		return(2);
	}	
}	
Пример #11
0
int main(int argc, char *argv[]) {
	printf("START...\n");
	
	//catch SIGTERM for graceful exit
	struct sigaction action;
    memset(&action, 0, sizeof(struct sigaction));
    action.sa_handler = term;
    sigaction(SIGTERM, &action, NULL);
	
	printf("INIT GPIO\n");
    //Enable GPIO pins
    if (-1 == GPIOExport(POUT))
		return(1);

    //Set GPIO directions
    if (-1 == GPIODirection(POUT, OUT))
		return(2);

    while(done == 0) {//while not done...
		//Write GPIO value
		printf("ON\n");
		if (-1 == GPIOWrite(POUT, HIGH))
			return(3);
		usleep(1000 * 1000);
		printf("OFF\n");
		if (-1 == GPIOWrite(POUT, LOW))
			return(3);
		usleep(1000 * 1000);
    }

    //Disable GPIO pins
    if (-1 == GPIOUnexport(POUT))
		return(4);

    return(0);
}
Пример #12
0
static void transfer(int fd, uint8_t * message, size_t message_size)
{
	int ret;
	sleep(.5);
	GPIOWrite(CEPIN, 0);
	sleep(.5);

	uint8_t rx[message_size];
	printf("Array size %i \n", message_size);
	struct spi_ioc_transfer tr = {
		.tx_buf = (unsigned long)message,
		.rx_buf = (unsigned long)rx,
		.len = message_size,
		.delay_usecs = delay,
		.speed_hz = speed,
		.bits_per_word = bits,
	};

	ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);

	sleep(3);
	GPIOWrite(CEPIN, 1);
	sleep(.5);

}

int main(int argc, char *argv[])
{

	/*
	 * Enable GPIO pins
	 */
	if (-1 == GPIOExport(CEPIN))
		return(1);
 
	/*
	 * Set GPIO directions
	 */
	if (-1 == GPIODirection(CEPIN, OUT))
		return(2);

	// Reset VGATonic to ensure we are at pixel 0,0
	sleep(.5);
	GPIOWrite(CEPIN, 1);
	sleep(.5);
	GPIOWrite(CEPIN, 0);
	sleep(.5);
	GPIOWrite(CEPIN, 1);
	sleep(.5);
	GPIOWrite(CEPIN, 0);
	sleep(.5);
	GPIOWrite(CEPIN, 1);
	sleep(.5);

	int ret = 0;
	int fd;
	
	fd = open(device, O_RDWR);
	if (fd < 0)
		pabort("can't open device");

	/*
	 * spi mode
	 */
	ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
	if (ret == -1)
		pabort("can't set spi mode");

	ret = ioctl(fd, SPI_IOC_RD_MODE, &mode);
	if (ret == -1)
		pabort("can't get spi mode");

	/*
	 * bits per word
	 */
	ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't set bits per word");

	ret = ioctl(fd, SPI_IOC_RD_BITS_PER_WORD, &bits);
	if (ret == -1)
		pabort("can't get bits per word");

	/*
	 * max speed hz
	 */
	ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't set max speed hz");

	ret = ioctl(fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
	if (ret == -1)
		pabort("can't get max speed hz");

	printf("spi mode: %d\n", mode);
	printf("bits per word: %d\n", bits);
	printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);

	while (1) {
		
		transfer(fd, doge, 307200);
		transfer(fd, guitars, 307200);
	
	}

	close(fd);


	return ret;
}
Пример #13
0
int main(void){

	LCDInit(CLK, DIN, DC, CE,RST, contrast);

  	LCDclear();
	LCDshowLogo();
	struct sGENERAL person;
	delay_ms(1000);

	system("clear");
	printf("Deseja Sobrescrever os Dados ? S/N\n");
	unsigned int choose;
	do{choose = (int)getchar();}while(choose != 115 && choose != 83 && choose != 110 && choose != 78);
	getchar();
	if(choose == 115 || choose == 83){
		LCDDrawBitmap(profile);
		if(healthProfile(&person) == false){
			printf("Falha ao realizar o Cadastro!\n");
			return -1;
		}
	}else{
		system("clear");
		LCDDrawBitmap(profile);
		if(importData(&person)==false){
			printf("Falha ao importar dados!\n");
			return -1;
		}
	}
	LCDDrawBitmap(sensors);
	int raspDuino = serialOpen(SERIAL_PORT[1],BAUDS[1]);
	if(raspDuino == -1){
		printf("Houve um erro ao Abrir a porta Serial!\n");
		return -1;
	}

	serialFlush(raspDuino);
	
	GPIOExport(changeDisplay);	GPIODirection(changeDisplay,INPUT);
	GPIOExport(backLight);		GPIODirection(backLight,INPUT);
	GPIOExport(BL);				GPIODirection(BL,OUTPUT);
	GPIOWrite(BL,HIGH);

	uint8_t change_Layer = 0;

	while(1){
		if(GPIORead(changeDisplay) == HIGH){
			while(GPIORead(changeDisplay) == HIGH){}
			change_Layer++;
			if(change_Layer > 2)	change_Layer = 0;
		}
		if(GPIORead(backLight) == HIGH){
			while(GPIORead(backLight) == HIGH){}
			GPIOWrite(BL,!GPIORead(BL));
		}
		switch(change_Layer){
			case 0:
				lcdDisplayMain(raspDuino);
				break;
			case 1:
				lcdDisplayProfile(person);
				break;
			case 2:
				lcdDisplaySensors(raspDuino,person);
				break;
		}
		/*if(serialDataAvail(raspDuino)!=-1){ // Usar Threads 
			Sensors.BPM = (unsigned int)serialGetchar(raspDuino);
			Sensors.Temp = ((float)serialGetchar(raspDuino)*5/(1023))/0.01;
			
			Sensors.BPMState = healthState(person,Sensors.BPM);
			Sensors.TempState = isNormal(Sensors.Temp);
		}*/
	}
}
Пример #14
0
int main(int argc, char *argv[]) {
	char *line;
	char lines[4][LCD_WIDTH + 1];
	int i = 0, n = 0;
	size_t bytes = LCD_WIDTH;
	int fd;

	fd = open(LOCKFILE, O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
	if (fd < 0) {
		fd = creat(LOCKFILE, O_RDWR | S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
		if (fd < 0) {
			perror("creat");
			fprintf(stderr, "Couldn't create lockfile. Execution aborted.\n");
			exit(1);
		}
	}
	f_elock(fd);

	line = calloc(bytes + 1, sizeof (char));
	while ((n = getline(&line, &bytes, stdin)) != -1) {
		// The \n is 1 byte more
		if (n > LCD_WIDTH + 1) {
			fprintf(stderr, "Too many characters. The line will be truncated.\n");
			line[LCD_WIDTH + 1] = '\0';
		} else {
			// Strip \n
			line[strlen(line) - 1] = '\0';
		}
		snprintf(lines[i], LCD_WIDTH + 1, "%s", line);
		i++;
		if (i > 4) {
			fprintf(stderr, "Too many lines!\n");
			exit(1);
		}
	}
	free(line);

	GPIOExport(LCD_E);
	GPIOExport(LCD_RS);
	GPIOExport(LCD_D4);
	GPIOExport(LCD_D5);
	GPIOExport(LCD_D6);
	GPIOExport(LCD_D7);

	GPIODirection(LCD_E, OUT);
	GPIODirection(LCD_RS, OUT);
	GPIODirection(LCD_D4, OUT);
	GPIODirection(LCD_D5, OUT);
	GPIODirection(LCD_D6, OUT);
	GPIODirection(LCD_D7, OUT);

	// Initialise display
	lcd_init();

	if (i == 0) {
		lcd_empty();
	}
	if (i > 0) {
		lcd_byte(LCD_LINE_1, LCD_CMD);
		lcd_string(lines[0]);
	}
	if (i > 1) {
		lcd_byte(LCD_LINE_2, LCD_CMD);
		lcd_string(lines[1]);
	}
	if (i > 2) {
		lcd_byte(LCD_LINE_3, LCD_CMD);
		lcd_string(lines[2]);
	}
	if (i > 3) {
		lcd_byte(LCD_LINE_4, LCD_CMD);
		lcd_string(lines[3]);
	}

	f_unlock(fd);
	close(fd);
	unlink(LOCKFILE);
	exit(0);
}