Unverified Commit cac790cd authored by Birte Kristina Friesel's avatar Birte Kristina Friesel
Browse files

Arduino Nano: stdin: Increase buffer size; add .disable() method

parent e795564f
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -9,18 +9,19 @@
class StandardInput {
	private:
		StandardInput(const StandardInput &copy);
		char buffer[8];
		char buffer[32];
		unsigned char write_pos, read_pos;

	public:
		StandardInput() : write_pos(0), read_pos(0) {}
		void setup();
		void disable();
		bool hasKey();
		char getKey();

		inline void addKey(char key) {
			buffer[write_pos] = key;
			write_pos = (write_pos + 1) % 8;
			write_pos = (write_pos + 1) % (sizeof(buffer) / sizeof(buffer[0]));
		}
};

+6 −1
Original line number Diff line number Diff line
@@ -12,6 +12,11 @@ void StandardInput::setup()
	UCSR0B |= _BV(RXCIE0);
}

void StandardInput::disable()
{
	UCSR0B &= ~_BV(RXCIE0);
}

bool StandardInput::hasKey()
{
	if (write_pos != read_pos) {
@@ -23,7 +28,7 @@ bool StandardInput::hasKey()
char StandardInput::getKey()
{
	char ret = buffer[read_pos++];
	read_pos %= 8;
	read_pos %= sizeof(buffer) / sizeof(buffer[0]);
	return ret;
}