예제 #1
0
/*
 * Keyboard callback function
 *	Keys and their effects:
 *		a/A:	toggle animation
 *		1:	switch to camera position 1
 *		2:	switch to camera position 2
 *		5:	toggle light source 1
 *		6:	toggle light source 2
 *		7/d/D:	toggle disco lights
 *		q/Q:	quit program
 */
void keyboard(unsigned char key, int x, int y) {
    switch (key) {
    case 'A':
    case 'a':
        toggleAnimation();
        break;
    case 'D':
    case 'd':
        toggleDisco();
        break;
    case '1':
        switchCamera(0);
        break;
    case '2':
        switchCamera(1);
        break;
    case '5':
        toggleLight(0);
        break;
    case '6':
        toggleLight(1);
        break;
    case 'Q':
    case 'q':
        exit(0);
        break;
    default:
        break;
    }
}
예제 #2
0
/**
 * \see trafficlight.h
 */
void runTrafficLight() 
{
	/* initial state */
	enum Event event = NO_EVENT;
	struct StateClass state = states[RED];
	toggleLight(RED_LIGHT, ON);

	timer(RED_TIME, STANDBY);

	/* state-machine loop */
	while (1)
	{
		event = checkEvent();

		if (event != NO_EVENT) // do only if something happend
		{
			state = state.gotoNextState(event); // handle next state
		}
	}
}
예제 #3
0
void RequestModule::serveRequest(Request request, Input input_parameters[INPUT_PARAMETER_MAX_COUNT]) {
    // Authorizes the request
    if(! SecurityModule::authorizeRequest(request, input_parameters)) {
        // The request has not been authorized
        CommunicationModule::sendErrorResponse(UNAUTHORIZED);
        return;
    }

    // Serves the request
    switch(request) {
    case ADD_USER : {
            addUser(input_parameters[1], input_parameters[2]);
            break;
        }

    case CHANGE_PASSWORD : {
            changePassword(input_parameters[0], input_parameters[1]);
            break;
        }

    case LOGIN : {
            login(input_parameters[0], input_parameters[1]);
            break;
        }

    case LOGOUT : {
            logout(input_parameters[0]);
            break;
        }

    case REFRESH_TTL : {
            refreshTtl(input_parameters[0]);
            break;
        }

    case REMOVE_USER : {
            removeUser(input_parameters[1]);
            break;
        }

    case REQUEST_STATE : {
            requestState();
            break;
        }

    case REQUEST_USERS : {
            requestUsers();
            break;
        }

    case TOGGLE_LIGHT : {
            toggleLight();
            break;
        }

    case TOGGLE_LOCK : {
            toggleLock();
            break;
        }
    }
}
예제 #4
0
/**
 * \see trafficlight.h
 */
void runTrafficLight() 
{
	/* initial state */
	enum Event event = NO_EVENT;
	enum State state = RED;
	toggleLight(RED_LIGHT, ON);

	timer(RED_TIME, STANDBY);
	
	/* state machine loop */
	while (1) 
	{
		event = checkEvent(); // check if an event has been triggered

		switch (event) 
		{
			case STANDBY:
				if (state == RED) 
				{
					state = RED_YELLOW;
					handleStandby();			
				}
				break;
			case GO:
				if (state == RED_YELLOW) 
				{
					state = GREEN;
					handleGo();						            
				}
				break;
			case PREPARE_TO_STOP:
				if (state == GREEN) 
				{
					state = GREEN_BLINKING;
					handlePrepareToStop();
				}
				break;
			case REPEAT:
				if (state == GREEN_BLINKING) 
				{
					handleRepeatGreen();
				}
				else if (state == YELLOW_BLINKING) 
				{
					handleRepeatYellow();
				}
				break;
			case STOP:
				if (state == GREEN_BLINKING) 
				{
					state = YELLOW;
					handleStop();
				}
				break;
			case WAIT:
				if (state == YELLOW) 
				{
					state = RED;
					handleWait();
				}
				break;
			case IDLE:
				if (state == RED) 
				{
					state = YELLOW_BLINKING;
					handleIdle();
				}
			case RESET:
				if (state == YELLOW_BLINKING) 
				{
					state = RED;
					handleReset();
				}
				break;
		}
	}
}