aboutsummaryrefslogblamecommitdiff
path: root/clak.c
blob: f7208e721543914c8ce01508f2ba9435a1ff8825 (plain) (tree)
1
2
3
4
5
6
7
8
9
                  
                   
                   
                   
                   
 
                              
                        
 
                   
 

                           







                                        

                           

                              



                         

                              

 

                               






                                                                               
                                              

                                                           
                         
         
                                                           
 
                                                            







                                                                      
                              
                                                            
 
                     
 
                 
 
#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;
	}
	fprintf(stderr, "Loading board...\n");
	if ((board = load_board(argv[1])) == NULL) {
		printf("Failed to load board, exiting.\n");
		return 1;
	}
	fprintf(stderr, "Loaded board: %s\n", board->name);

	fprintf(stderr, "Initialisating sound system...\n");
	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;
}