Example #1
0
void *buttonVerify(){
	while(1){
		for(register unsigned int iRow = 0 ; iRow < 4 ; iRow++){
			for(register unsigned int iCol = 0; iCol < 4; iCol++){
				GPIOWrite(rowBot[iRow],HIGH);
				if(GPIORead(colBot[iCol])==HIGH){
					while(GPIORead(colBot[iCol])==HIGH){}
					push(iRow,iCol,&sFila[iCol]);
				}
			}
			GPIOWrite(rowBot[iRow],LOW);
		}
	}
}
Example #2
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);
}
Example #3
0
bool CGpio::InitPins()
{
	int fd;
	bool db_state = false;
	char path[GPIO_MAX_PATH];
	char szIdx[10];
	char label[12];
	std::vector<std::vector<std::string> > result;
	boost::mutex::scoped_lock lock(m_pins_mutex);
	pins.clear();

	for (int gpio_pin = GPIO_PIN_MIN; gpio_pin <= GPIO_PIN_MAX; gpio_pin++)
	{
		snprintf(path, GPIO_MAX_PATH, "%s%d", GPIO_PATH, gpio_pin);
		fd = open(path, O_RDONLY);

		if (fd != -1) /* GPIO export found */
		{
			result = m_sql.safe_query("SELECT nValue FROM DeviceStatus WHERE (HardwareID==%d) AND (Unit==%d)",
				m_HwdID, gpio_pin);
			if (result.size() > 0)
				db_state = atoi(result[0][0].c_str());

			snprintf(label, sizeof(label), "GPIO pin %d", gpio_pin);
			pins.push_back(CGpioPin(gpio_pin, label, GPIORead(gpio_pin, "value"), GPIORead(gpio_pin, "direction"),	GPIORead(gpio_pin, "edge"), GPIORead(gpio_pin, "active_low"), -1, db_state));
			//_log.Log(LOG_NORM, "GPIO: Pin %d added (value: %d, direction: %d, edge: %d, active_low: %d, db_state: %d)",
			//	gpio_pin, GPIORead(gpio_pin, "value"), GPIORead(gpio_pin, "direction"), GPIORead(gpio_pin, "edge"), GPIORead(gpio_pin, "active_low"), db_state);
			close(fd);

			if (GPIORead(gpio_pin, "direction") != 0)
				continue;

			snprintf(path, GPIO_MAX_PATH, "%s%d/value", GPIO_PATH, gpio_pin);
			fd = pins.back().SetReadValueFd(open(path, O_RDWR)); // O_RDWR seems mandatory to clear interrupt (not sure why?)

			if (fd != -1)
			{
				pinPass = gpio_pin;
				m_thread_interrupt[gpio_pin] = boost::shared_ptr<boost::thread>(new boost::thread(boost::bind(&CGpio::InterruptHandler, this)));
				while (pinPass != -1)
					sleep_milliseconds(1);
			}
		}
	}
	return (pins.size() > 0);
}
Example #4
0
int c_read(char *in){
    int i = atoi(in);
    if( i ==0 ){
        slog(LVL_QUIET,ERROR,"Usage : read PIN");
        return 0;
    }
    return GPIORead(i);
}
Example #5
0
int read_data(void)
{
	unsigned char data=0;

	if (-1 == GPIOWrite(STB, HIGH)) //Make strobe pin high
	return(1);

	if (-1 == GPIODirection(GP0, IN) || -1 == GPIODirection(GP1, IN) || -1 == GPIODirection(GP2, IN) || -1 == GPIODirection(GP3, IN))
	return(2);

	usleep(1000);

	data = (GPIORead(GP0) | (GPIORead(GP1) << 1) | (GPIORead(GP2) << 2) | (GPIORead(GP3) << 3));

	if (-1 == GPIOWrite(STB, LOW)) //Make strobe pin low
	return(3);

	return data;
}
Example #6
0
void loop() {
	uint16_t color;
	
	if ( digitalRead(VSYNC) == LOW ) {
    cam.waitVSYNCHigh();
    cam.writeDisable();
    cam.waitVSYNCFalling();
    cam.writeEnable();

		cam.outEnable();
		cam.readReset(LOW);
		cam.clock(LOW);
		cam.waitHREFPulse();
//		__nop();
		
		cam.clock(HIGH);
		cam.readReset(HIGH);
		__nop();
		cam.clock(LOW);
		__nop();
		cam.clock(HIGH);
		__nop();
		for(int row = 0; row <240; row++) {
      tft.drawPixel(0,row,0);
      for(int col = 0; col < 320 ; col++) {
        cam.clock(LOW);
        color = GPIORead(PD_ALL) & 0xff00;
        cam.clock(HIGH);
        __nop();
        cam.clock(LOW);
        color |= GPIORead(PD_ALL)>>8;
        cam.clock(HIGH);

        tft.drawPixel(color);
      }
    }
		cam.outDisable();
		cam.writeDisable();
		digitalWrite(PE8, LOW);
		delay(5);
	}
Example #7
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);
		}*/
	}
}