Ejemplo n.º 1
0
int ReadAndConvertVals()
{
        int value = 0;

        if (readGPIO(fileHandleGPIO_4) == 1)
        {
                value += 1;
        }
        if (readGPIO(fileHandleGPIO_5) == 1)
        {
                value += 2;
        }
        if (readGPIO(fileHandleGPIO_6) == 1)
        {
                value += 4;
        }
        if (readGPIO(fileHandleGPIO_7) == 1)
        {
                value += 8;
        }

        printf("value = %d\n", value);

        return value;
}
Ejemplo n.º 2
0
int ReadAndConvertVals3()
{
        int value = 0;
        if (readGPIO(fileHandleGPIO_4) == 1)
        {
                value += 256;
        }
        if (readGPIO(fileHandleGPIO_5) == 1)
        {
                value += 512;
        }
        printf("Last Crumb = %d\n", value);
        return value;
}
Ejemplo n.º 3
0
void PCF8574::begin(uint8_t address) {

	/* Store the I2C address and init the Wire library */
	_address = address;
	Wire.begin();
	readGPIO();
}
Ejemplo n.º 4
0
void *threadGpio(void *param){
    int etat = 0;
    int bpStop = 0;
    //int time = 0, timePrev = -1;
    
    
	while(1){
		bpStop = readGPIO(BP_STOP);
		//time = millis();
		
		pthread_mutex_lock(&mtx_order);
		switch(etat){ 
		    case 0 : if(bpStop == 0 || order == MVT) etat = 1;
		             order = STP;
		             //if(time - timePrev > 50) timePrev = time;
		             break;
		    case 1 : if(bpStop == 1) etat = 2;
		             order = MVT; 
		             break;
            case 2 : if(bpStop == 0 || order == STP) etat=3;
                     order = MVT;
		             //if(time - timePrev > 50) timePrev = time;
                     break;
            case 3 : if(bpStop == 1) etat=0;
                     order = STP; 
                     break;
		    default : printf("Error in swicth\n");
		              getchar();
		}
		pthread_mutex_unlock(&mtx_order);
	}
}
uint8_t Adafruit_MCP23008::digitalRead(uint8_t p) {
  // only 8 bits!
  if (p > 7)
    return 0;

  // read the current GPIO
  return (readGPIO() >> p) & 0x1;
}
Ejemplo n.º 6
0
void I2C_4DI4RO::begin(uint8_t address) {
	_address = address + 0x20;
	Wire.begin();
	readGPIO();
	_DDR  = 0b11110000;
	_PORT = 0b11111111;
	updateGPIO();
	lastCommandOK = false;
}
Ejemplo n.º 7
0
uint8_t I2C_4DI4RO::dinRead(uint8_t pin) {
	pin -= 1;
	
	/* Read GPIO */
	readGPIO();

	/* Read and return the pin state */
	return (_PIN & (1 << pin)) ? LOW : HIGH;
}
Ejemplo n.º 8
0
uint8_t PCF8574::read() {

	/* Read GPIO */
	readGPIO();

#ifdef PCF8574_INTERRUPT_SUPPORT
	/* Check for interrupt (manual detection) */
	//checkForInterrupt();
#endif

	/* Return current pins values */
	return _PIN;
}
Ejemplo n.º 9
0
int ReadAndConvertVals2()
{
        int value = 0;
        if (readGPIO(fileHandleGPIO_4) == 1)
        {
                value += 16;
        }
        if (readGPIO(fileHandleGPIO_5) == 1)
        {
                value += 32;
        }
        if (readGPIO(fileHandleGPIO_6) == 1)
        {
                value += 64;
        }
        if (readGPIO(fileHandleGPIO_7) == 1)
        {
                value += 128;
        }
        printf("Second Nibble: %d\n", value);
        return value;
}
Ejemplo n.º 10
0
uint8_t PCF8574::digitalRead(uint8_t pin) {

	/* Read GPIO */
	readGPIO();

#ifdef PCF8574_INTERRUPT_SUPPORT
	/* Check for interrupt (manual detection) */
	//checkForInterrupt();
#endif

	/* Read and return the pin state */
	return (_PIN & (1 << pin)) ? HIGH : LOW;
}
Ejemplo n.º 11
0
void PCF8574::checkForInterrupt() {

	/* Avoid nested interrupt triggered by I2C read/write */
	if(_isrIgnore)
		return;
	else
		_isrIgnore = 1;
		
	/* Re-enable interrupts to allow Wire library to work */
	sei();

	/* Read current pins values */
	readGPIO();

	/* Check all pins */
	for (uint8_t i = 0; i < 8; ++i) {

		/* Check for interrupt handler */
		if (!_intCallback[i])
			continue;

		/* Check for interrupt event */
		switch (_intMode[i]) {
		case CHANGE:
			if ((1 << i) & (_PIN ^ _oldPIN))
				_intCallback[i]();
			break;

		case LOW:
			if (!(_PIN & (1 << i)))
				_intCallback[i]();
			break;

		case FALLING:
			if ((_oldPIN & (1 << i)) && !(_PIN & (1 << i)))
				_intCallback[i]();
			break;

		case RISING:
			if (!(_oldPIN & (1 << i)) && (_PIN & (1 << i)))
				_intCallback[i]();
			break;
		}
	}
	
	/* Turn off ISR ignore flag */
	_isrIgnore = 0;
}
Ejemplo n.º 12
0
void KEYS::pinMode(uint32_t pin, uint8_t mode) {
  uint32_t pullUp, dbc;
  
  readGPIO();
  switch(mode) {
    case INPUT:
	  bitClear(_PORT, pin);
	  bitClear(_DDR, pin);
	  bitClear(_PKG, pin);
	  bitSet(_PUR, pin);
	  break;
	case INPUT_PULLUP:
	  bitClear(_PORT, pin);
	  bitClear(_DDR, pin);
	  bitClear(_PKG, pin);
	  bitClear(_PUR, pin); 
	  break;
    case OUTPUT:
	  bitClear(_PORT, pin);
	  bitSet(_DDR, pin);
	  bitClear(_PKG, pin);
	  bitSet(_PUR, pin);
	  break;
	case KEYPAD:
	  bitClear(_PORT, pin);
	  bitClear(_DDR, pin);
	  bitSet(_PKG, pin);
	  bitClear(_PUR, pin); 
	  break;
	case DEBOUNCE:
	  read3Bytes((uint32_t *)&dbc, REG_DEBOUNCE_DIS1);
	  bitClear(dbc, pin);
	  write3Bytes((uint32_t)dbc, REG_DEBOUNCE_DIS1);
	  break;
	case NODEBOUNCE:
	  read3Bytes((uint32_t *)&dbc, REG_DEBOUNCE_DIS1);
	  bitSet(dbc, pin);
	  write3Bytes((uint32_t)dbc, REG_DEBOUNCE_DIS1);
	  break;
	default:
	  break;
  }
  updateGPIO();
}
void Adafruit_MCP23008::digitalWrite(uint8_t p, uint8_t d) {
  uint8_t gpio;
  
  // only 8 bits!
  if (p > 7)
    return;

  // read the current GPIO output latches
  gpio = readGPIO();

  // set the pin and direction
  if (d == HIGH) {
    gpio |= 1 << p; 
  } else {
    gpio &= ~(1 << p);
  }

  // write the new GPIO
  writeGPIO(gpio);
}
Ejemplo n.º 14
0
void AbstractRPM::pollInputs()
{
	while (1)
	{
		{
			boost::lock_guard<boost::mutex> lock(pollingThreadsExitLock);
			if (shouldExit)
				return;
		}

		for (size_t i = 0; i < _computers.size(); i++)
		{
			if (gpioIsValid(_computers[i].powerLed)) {
				bool powerLedOn = readGPIO(_computers[i].powerLed);
				setPowerLedState(_computers[i].name, powerLedOn);
			}
		}

		usleep(1000000);
	}
}
Ejemplo n.º 15
0
int main(void)

{
        int fileHandleGPIO_LED;
        int fileHandleGPIO_PROXY;
        int i=0;

        puts("Starting proximity reader on Galileo board.");
        fileHandleGPIO_PROXY = openGPIO(GP_PROXY, GPIO_DIRECTION_IN);
        if(ERROR ==  fileHandleGPIO_PROXY)
        {
        		puts("Unable to open toggle Proximity port #8");
        		return(-1);
        }
        fileHandleGPIO_LED = openGPIO(GP_LED, GPIO_DIRECTION_OUT);

        if(ERROR ==  fileHandleGPIO_LED)

        {
        		puts("Unable to open toggle LED port #13");
        		return(-1);

        }


        //Switch off the LED before starting.
        writeGPIO(fileHandleGPIO_LED, 0);

        //set PWM parameters
        openPWM(GP_PWM);
        setPWMPeriod(1000000,GP_PWM);
        enablePWM(1,GP_PWM);
		setPWMDutyCycle(0,GP_PWM);


        //Start an infinite loop to keep polling for proximity info
        int proxyValue = 0;
        while(1==1)
        {
			proxyValue = readGPIO(fileHandleGPIO_PROXY,GP_PROXY);
			if(proxyValue == 1)
			{
				if(duty_cycle == 500000)
				{
					duty_cycle = 200000;
		        	writeGPIO(fileHandleGPIO_LED, 0);
				}
				else
				{
					duty_cycle = 500000;
		        	writeGPIO(fileHandleGPIO_LED, 1);
				}
				setPWMDutyCycle(duty_cycle,GP_PWM);
			}
			else
			{
				duty_cycle = 50000;
				setPWMDutyCycle(0,GP_PWM);
	        	writeGPIO(fileHandleGPIO_LED, 0);
			}
        	usleep(1000*400);
        }


        closeGPIO(GP_LED, fileHandleGPIO_LED);
        closeGPIO(GP_PROXY, fileHandleGPIO_PROXY);
        closePWM(GP_PWM);

        puts("Finished BURGLER ALARM on Galileo board.");
        return 0;
}
Ejemplo n.º 16
0
uint32_t KEYS::read(void) {

  readGPIO();
  
  return _PORT;
}
Ejemplo n.º 17
0
uint8_t KEYS::digitalRead(uint32_t pin) {

  readGPIO();
  
  return(_PIN & bit(pin)) ? HIGH : LOW;
}
MainWindowLifeGame::MainWindowLifeGame(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindowLifeGame)
{
/*
export DISPLAY=":0.0"
xhost +
cd Desktop/ISIB_LifeGameClientV1/
sudo DISPLAY=:0 ./ISIB_LifeGameClient
*/
    this->rpiGpio = new mmapGpio();
    this->rpiGpio->setPinDir(this->pinNumIn,mmapGpio::INPUT);

   this->tnbr = new QRegExp ("Tree ([0-9]+)");
   this->herbr = new QRegExp ("Herbi ([0-9]+)");
   this->carbr  = new QRegExp ("Carni ([0-9]+)");
   this->invbr  = new QRegExp ("Invad ([0-9]+)");
   this->yearBr  = new QRegExp ("YEAR ([0-9]+)");


    int id = QFontDatabase::addApplicationFont("://data/Greenscr.ttf");
    QString family = QFontDatabase::applicationFontFamilies(id).at(0);
    QFont Greenscr(family,18);

    this->socket = new QTcpSocket(this);
    this->connect(this->socket, SIGNAL(readyRead()), SLOT(readTcpData()));
    this->connect(this->socket, SIGNAL(disconnected()), SLOT(autoReconnect()));

    QSettings settings("conf.ini", QSettings::IniFormat);
    this->ip = settings.value("OPTIONS/IP","127.0.0.1").toString();
    this->port = settings.value("OPTIONS/PORT", 11900).toInt();


    //qDebug() << "Address "<<this->ip<<":"<<this->port;

    this->timerDots = new QTimer();
    this->timerDots->connect(this->timerDots, SIGNAL(timeout()),this, SLOT(updateDots()));
    this->timerDots->start(500);

    this->timerButt = new QTimer();
    this->timerButt->connect(this->timerButt, SIGNAL(timeout()),this, SLOT(changeBG()));

    this->timerGpio = new QTimer();
    this->timerGpio->connect(this->timerGpio, SIGNAL(timeout()),this, SLOT(readGPIO()));
    this->timerGpio->start(100);

    this->dataTab[0]=0;
    this->dataTab[1]=0;
    this->dataTab[2]=0;
    this->dataTab[3]=0;

    bool connected = false;
    while(!(connected)){
        this->socket->connectToHost(this->ip,this->port);
        if( this->socket->waitForConnected(5000) ) {
           this->socket->write("HELLO SERVER[/TCP]");
           this->socket->flush();
           connected = true;
        }
    }

    ui->setupUi(this);



    ui->label->setFont(Greenscr);
    ui->label->setSizePolicy(QSizePolicy(QSizePolicy::Maximum, QSizePolicy::Fixed));
    ui->labelYear->setFont(Greenscr);
    ui->labelDotAnim->setFont(Greenscr);
    ui->labelArbre->setFont(Greenscr);
    ui->labelArbre_2->setFont(Greenscr);
    ui->labelArbre_3->setFont(Greenscr);
    ui->labelArbre_4->setFont(Greenscr);
    ui->progressBarTree->setFont(Greenscr);
    ui->progressBarHerbi->setFont(Greenscr);
    ui->progressBarCarni->setFont(Greenscr);
    ui->progressBarInvade->setFont(Greenscr);

    ui->textEditTree->setFont(Greenscr);
    ui->textEditHerbi->setFont(Greenscr);
    ui->textEditCarni->setFont(Greenscr);
    ui->textEditBrut->setFont(Greenscr);
    ui->textEditInvad->setFont(Greenscr);

    QMainWindow::showFullScreen();
    QApplication::setOverrideCursor(Qt::BlankCursor);

     /*this->sbHerbi = ui->textEditHerbi->verticalScrollBar();
     this->sbHerbi->setValue(this->sbHerbi->maximum());

     this->sbCarni = ui->textEditCarni->verticalScrollBar();
     this->sbCarni->setValue(this->sbCarni->maximum());

     this->sbBrut = ui->textEditBrut->verticalScrollBar();
     this->sbBrut->setValue(this->sbBrut->maximum());

     this->sbInvad = ui->textEditInvad->verticalScrollBar();
     this->sbInvad->setValue(this->sbInvad->maximum());

    this->sbTree = ui->textEditTree->verticalScrollBar();
    this->sbTree->setValue(this->sbTree->maximum());
*/

}