aboutsummaryrefslogtreecommitdiff
path: root/clak.c
blob: 444165f98d16fcb342fc75ab24081ece1245b3ae (plain) (blame)
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
60
61
62
63
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

#include "platform/platform.h"
#include "board/board.h"

#define VOLUME 0.15

struct board *board = NULL;

void do_exit(int code)
{
	keyboard_unhook();
	fprintf(stderr, "Goodbye.\n");
	exit(code);
}
void on_clean_exit(void) { do_exit(0); }

void keyboard_on_down(void)
{
	assert(board != NULL);
	board->on_down();
}

void keyboard_on_up(void)
{
	assert(board != NULL);
	board->on_up();
}

int main(int argc, char **argv)
{
	fprintf(stderr, "Clak: This is Clak, Nicholas Tay, version: 0.1.0.\n");

	if (argc < 2) {
		printf("ERROR: Please provide a board name.\n");
		// TODO: List valid boards.
		return 1;
	}
	if ((board = load_board(argv[1])) == NULL) {
		printf("Failed to load board, exiting.\n");
		return 1;
	}
	fprintf(stderr, "Loaded board: %s\n", board->name);

	if (!sound_init(VOLUME)) {
		printf("ERROR: Could not initialise sound system.\n");
		return 1;
	}
	if (!keyboard_hook()) {
		printf("ERROR: Could not set up keyboard hooks.\n");
		return 1;
	}
	atexit(on_clean_exit);
	fprintf(stderr, "Hooks set up, enjoy your stay!\n");

	enter_idle();

	return 0;
}