summaryrefslogtreecommitdiff
path: root/12key-arduino/12key-arduino.ino
blob: b239c17c5ede755f10afff40dc9443cbbb665c96 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <Arduino.h>
#include "Keypad.h"
#include "Mode.h"
#include "ModeMenu.h"
#include "ModeMouse.h"
#include "ModeKeyboard.h"
#include "ModeNav.h"

Mode *modes[] = {
	new ModeMenu(),
	new ModeMouse(),
	new ModeKeyboard(),
	new ModeNav(),
};
Mode **Mode::modes;

Mode *currentMode;


void streamf(Stream& s, const char *fmt, ...) {
	static char buf[128];
	va_list args;
	va_start(args, fmt);
	vsnprintf(buf, 128, fmt, args);
	va_end(args);
	s.print(buf);
}


void setup() {
	Mouse.begin();
	Keypad::Setup();
	Serial.begin(115200);

	Mode::modes = modes;
	currentMode = Mode::modes[0];
}


void PrintPin(unsigned int pins, int index, const char *msg) {
	if (pins & (1 << index)) {
		Serial.print(msg);
	}
}


void loop() {
	Keypad::Update();

	if (Keypad::state != 0) {
		Mode *next = currentMode->update(Keypad::state);
		if (next != NULL) {
			currentMode = next;
			currentMode->reset();
		}

		Keypad::state = 0;
	}
}