Пример #1
0
int eIOBuffer::tofile(int fd, int len)
{
	int written=0;
	int w;
	while (len && !buffer.empty())
	{	
		if (buffer.begin() == buffer.end())
			break;
		int tc=buffer.front().len-ptr;
		if (tc > len)
			tc = len;
	
		w=::write(fd, buffer.front().data+ptr, tc);
		if (w < 0)
		{
			if (errno != EWOULDBLOCK && errno != EBUSY && errno != EINTR)
				eDebug("write: %m");
			w=0;
		}
		ptr+=w;
		if (ptr == buffer.front().len)
			removeblock();
		written+=w;	

		len-=w;
		if (tc != w)
			break;
	}
	return written;
}
Пример #2
0
void eIOBuffer::skip(int len)
{
	while (len)
	{
		ASSERT(! buffer.empty());
		int tn=len;
		if (tn > (buffer.front().len-ptr))
			tn=buffer.front().len-ptr;

		ptr+=tn;
		if (ptr == buffer.front().len)
			removeblock();
		len-=tn;
	}
}
Пример #3
0
void eIOBuffer::clear()
{
	while (!buffer.empty())
		removeblock();
}
Пример #4
0
void loop() {
	// get block
	block blck = getRdm();

	// update the grid and print
	// for (int i = 0; i < 4; ++i){
	// 	grid[blck.row[i]][blck.col[i]] = 1;
	// }
	block old_blck = blck;

	printblock(blck);

	while(down(&blck)) {
		// blck is has been moved down.

		// remove old_blck
		removeblock(old_blck);

		// update old_blck
		old_blck = blck;

		// check "turn" button
		if (digitalRead(turnPin) == HIGH) {
			// turn us
			turnblock(&blck);
		}

		// check "left block"
		if (digitalRead(leftPin) == HIGH) {
			// go left if possible - arguments are blockr and blockc
			left(&blck);
		}

		// check "right block"
		if (digitalRead(rightPin) == HIGH) {
			// go right if possible  - arguments are blockr and blockc
			right(&blck);
		}

		// remove old_blck
		removeblock(old_blck);

		// update old_blck
		old_blck = blck;

		// print new blck
		printblock(blck);
		
		// difficulty
		// change how fast the block falls based on score
		if (score < 5) {
			Serial.println(1);
			delay(250);
		}
		if (score >= 5 && score < 10) {
			Serial.println(2);
			delay(200);
		}
		if (score >= 10 && score < 20) {
			Serial.println(3);
			delay(150);
		}
		if (score >= 20) {
			Serial.println(4);
			delay(100);
		}

		// gridprinter();
	}

	// check grid for and full rows or endgame.
	checkrow();
}