uint8_t I2C::receiveByte(uint8_t ack) { unsigned long startingTime = millis(); if(ack) { TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA); } else { TWCR = (1<<TWINT) | (1<<TWEN); } while (!(TWCR & (1<<TWINT))) { if(!timeOutDelay){continue;} if((millis() - startingTime) >= timeOutDelay) { lockUp(); return(1); } } if (TWI_STATUS == LOST_ARBTRTN) { uint8_t bufferedStatus = TWI_STATUS; lockUp(); return(bufferedStatus); } return(TWI_STATUS); }
uint8_t I2C::sendByte(uint8_t i2cData) { TWDR = i2cData; unsigned long startingTime = millis(); TWCR = (1<<TWINT) | (1<<TWEN); while (!(TWCR & (1<<TWINT))) { if(!timeOutDelay){continue;} if((millis() - startingTime) >= timeOutDelay) { lockUp(); return(1); } } if (TWI_STATUS == MT_DATA_ACK) { return(0); } uint8_t bufferedStatus = TWI_STATUS; if (TWI_STATUS == MT_DATA_NACK) { stop(); return(bufferedStatus); } else { lockUp(); return(bufferedStatus); } }
uint8_t I2C::start() { unsigned long startingTime = millis(); TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); while (!(TWCR & (1<<TWINT))) { if(!timeOutDelay){continue;} if((millis() - startingTime) >= timeOutDelay) { lockUp(); return(1); } } if ((TWI_STATUS == START) || (TWI_STATUS == REPEATED_START)) { return(0); } if (TWI_STATUS == LOST_ARBTRTN) { uint8_t bufferedStatus = TWI_STATUS; lockUp(); return(bufferedStatus); } return(TWI_STATUS); }
uint8_t I2C::receiveByte(boolean ack) { unsigned long startingTime = millis(); if(ack) { TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA); } else { TWCR = (1<<TWINT) | (1<<TWEN); } while (!(TWCR & (1<<TWINT))) { if(!timeOutDelay) { continue; } if((millis() - startingTime) >= timeOutDelay) { lockUp(); return(1); } } return(TWI_STATUS); }
uint8_t I2C::stop() { unsigned long startingTime = millis(); TWCR = (1<<TWINT)|(1<<TWEN)| (1<<TWSTO); while ((TWCR & (1<<TWSTO))) { if(!timeOutDelay){continue;} if((millis() - startingTime) >= timeOutDelay) { lockUp(); return(1); } } return(0); }
void Field::init(){ mainWidget = new QGridLayout(); mainWidget->setHorizontalSpacing(-1); mainWidget->setVerticalSpacing(-1); this->setLayout(mainWidget); cells = new Cell**[COUNT];//указатель на массив ячеек for(int i = 0; i < COUNT; i++) cells[i] = new Cell*[COUNT]; for(int i = 0; i < COUNT; i++){ for(int j = 0; j < COUNT; j++){ cells[i][j] = new Cell(NULL, image, i, j); connect(cells[i][j], SIGNAL(mousePressEvent(Cell*)), this, SLOT(CellClick(Cell*))); mainWidget->addWidget(cells[i][j], i, j); } } state = 0; lockUp(); }
uint8_t I2C::sendAddress(uint8_t i2cAddress) { TWDR = i2cAddress; unsigned long startingTime = millis(); TWCR = (1<<TWINT) | (1<<TWEN); while (!(TWCR & (1<<TWINT))) { if(!timeOutDelay){continue;} if((millis() - startingTime) >= timeOutDelay) { lockUp(); return(1); } } if ((TWI_STATUS == MT_SLA_ACK) || (TWI_STATUS == MR_SLA_ACK)) { return(0); } return(TWI_STATUS); }