watch-user-button.cc 1.62 KB
Newer Older
Timothy Stack's avatar
Timothy Stack committed
1 2 3 4 5
/*
 * EMULAB-COPYRIGHT
 * Copyright (c) 2005 University of Utah and the Flux Group.
 * All rights reserved.
 */
Timothy Stack's avatar
 
Timothy Stack committed
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 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86

#include "config.h"

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>

#include "garciaUtil.hh"
#include "buttonManager.hh"

class myButtonCallback : public buttonCallback
{

public:
    
    virtual bool shortClick(acpGarcia &garcia, unsigned long now)
    {
	printf("shortClick(%ld)\n", now);
	return true;
    };

    virtual bool commandMode(acpGarcia &garcia, unsigned long now, bool on)
    {
	printf("commandMode(%ld, %d)\n", now, on);
	return true;
    };

    virtual bool shortCommandClick(acpGarcia &garcia, unsigned long now)
    {
	printf("shortCommandClick(%ld)\n", now);
	return true;
    };

    virtual bool longCommandClick(acpGarcia &garcia, unsigned long now)
    {
	printf("longCommandClick(%ld)\n", now);
	return true;
    };
    
};

static volatile int looping = 1;

static void sigquit(int signal)
{
    looping = 0;
}

int main(int argc, char *argv[])
{
    int retval = EXIT_SUCCESS;
    acpGarcia garcia;
    aIOLib ioRef;
    
    signal(SIGQUIT, sigquit);
    signal(SIGTERM, sigquit);
    signal(SIGINT, sigquit);
    
    aIO_GetLibRef(&ioRef, NULL);
    
    if (!wait_for_brainstem_link(ioRef, garcia)) {
	fprintf(stderr, "error: cannot establish link to robot\n");
	
	retval = EXIT_FAILURE;
    }
    else {
	buttonManager bm(garcia, "user-button");
	unsigned long now;

	bm.setCallback(new myButtonCallback());
	while (looping) {
	    garcia.handleCallbacks(50);
	    aIO_GetMSTicks(ioRef, &now, NULL);
	    bm.update(now);
	}
    }
    
    aIO_ReleaseLibRef(ioRef, NULL);
    
    return retval;
}