Beispiel #1
0
void elev_set_speed(int speed)
{
	// In order to sharply stop the elevator, the direction bit is toggled
	// before setting speed to zero.
	static int last_speed = 0;
	
	// If to start (speed > 0)
	if (speed > 0) 
		io_clear_bit(MOTORDIR);
	else if (speed < 0) 
		io_set_bit(MOTORDIR);

	// If to stop (speed == 0)
	else if (last_speed < 0)
		io_clear_bit(MOTORDIR);
	else if (last_speed > 0)
		io_set_bit(MOTORDIR);

	last_speed = speed ;

	// Write new setting to motor.
	io_write_analog(MOTOR, 2048 + 2*abs(speed));

	//printf(__FILE__ ": Speed set to %d\n", speed);
}
Beispiel #2
0
void elev_set_floor_indicator(int floor) {
    assert(floor >= 0);
    assert(floor < N_FLOORS);

    // Binary encoding. One light must always be on.
    if (floor & 0x02)
        io_set_bit(LIGHT_FLOOR_IND1);
    else
        io_clear_bit(LIGHT_FLOOR_IND1);

    if (floor & 0x01)
        io_set_bit(LIGHT_FLOOR_IND2);
    else
        io_clear_bit(LIGHT_FLOOR_IND2);
}
Beispiel #3
0
void elev_set_floor_indicator(int floor)
{
	assert(floor >= 0);
	assert(floor < N_FLOORS);

	if (floor & 0x02)
		io_set_bit(FLOOR_IND1);
	else
		io_clear_bit(FLOOR_IND1);
		
	if (floor & 0x01)
		io_set_bit(FLOOR_IND2);
	else
		io_clear_bit(FLOOR_IND2);
}
Beispiel #4
0
void elev_set_door_open_lamp(int value) {
    if (value) {
        io_set_bit(LIGHT_DOOR_OPEN);
    } else {
        io_clear_bit(LIGHT_DOOR_OPEN);
    }
}
Beispiel #5
0
void elev_set_stop_lamp(int value) {
    if (value) {
        io_set_bit(LIGHT_STOP);
    } else {
        io_clear_bit(LIGHT_STOP);
    }
}
Beispiel #6
0
//elev_get_stop_signal=value
void ui_set_stop_lamp(int value)
{
    if (value)
        io_set_bit(LIGHT_STOP);
    else
        io_clear_bit(LIGHT_STOP);
}
Beispiel #7
0
void ui_set_door_open_lamp(int value)
{
    if (value)
        io_set_bit(DOOR_OPEN);
    else
        io_clear_bit(DOOR_OPEN);
}
Beispiel #8
0
void ui_set_floor_indicator(int floor)
{
	// assert crashes the program deliberately if it's condition does not hold,
	// and prints an informative error message. Useful for debugging.
    //assert(floor >= 0);
    //assert(floor < N_FLOORS);

    if (floor & 0x02)
        io_set_bit(FLOOR_IND1);
    else
        io_clear_bit(FLOOR_IND1);
        
    if (floor & 0x01)
        io_set_bit(FLOOR_IND2);
    else
        io_clear_bit(FLOOR_IND2);
}
Beispiel #9
0
void elev_set_button_lamp(elev_direction_t lamp, int floor, int value)
{
	assert(floor >= 0);
	assert(floor < N_FLOORS);

	if (value == 1)
		io_set_bit(lamp_channel_matrix[floor][lamp]);
	else
		io_clear_bit(lamp_channel_matrix[floor][lamp]);		
}
Beispiel #10
0
void elev_set_motor_direction(elev_motor_direction_t dirn) {
    if (dirn == 0){
        io_write_analog(MOTOR, 0);
    } else if (dirn > 0) {
        io_clear_bit(MOTORDIR);
        io_write_analog(MOTOR, 2800);
    } else if (dirn < 0) {
        io_set_bit(MOTORDIR);
        io_write_analog(MOTOR, 2800);
    }
}
void ElevInterface::set_motor_direction(elev_motor_direction_t dirn) {
    if (dirn == 0) {
        io_write_analog(MOTOR, 0);
    } else if (dirn > 0) {
        io_clear_bit(MOTORDIR);
        io_write_analog(MOTOR, MOTOR_SPEED);
    } else if (dirn < 0) {
        io_set_bit(MOTORDIR);
        io_write_analog(MOTOR, MOTOR_SPEED);
    }
}
Beispiel #12
0
void elev_set_button_lamp(elev_button_type_t button, int floor, int value) {
    assert(floor >= 0);
    assert(floor < N_FLOORS);
    assert(!(button == BUTTON_CALL_UP && floor == N_FLOORS - 1));
    assert(!(button == BUTTON_CALL_DOWN && floor == 0));
    assert(button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND);

    if (value)
        io_set_bit(lamp_channel_matrix[floor][button]);
    else
        io_clear_bit(lamp_channel_matrix[floor][button]);
}
Beispiel #13
0
void elev_set_button_lamp(elev_button_type_t button, int floor, int value) {
    assert(floor >= 0);
    assert(floor < N_FLOORS);
    assert(button >= 0);
    assert(button < N_BUTTONS);

    if (value) {
        io_set_bit(lamp_channel_matrix[floor][button]);
    } else {
        io_clear_bit(lamp_channel_matrix[floor][button]);
    }
}
Beispiel #14
0
//maybe let the queue arrays in queues handle button lamps?
//to decrease dependancy
void ui_set_button_lamp(int button, int floor, int value)
{
	// assert crashes the program deliberately if it's condition does not hold,
	// and prints an informative error message. Useful for debugging.
    assert(floor >= 0);
    assert(floor < N_FLOORS);
  //  assert(!(button == BUTTON_CALL_UP && floor == N_FLOORS-1));
  //  assert(!(button == BUTTON_CALL_DOWN && floor == 0));
  //  assert(button == BUTTON_CALL_UP || button == BUTTON_CALL_DOWN || button == BUTTON_COMMAND);

    if (value == 1)
        io_set_bit(lamp_channel_matrix[floor][button]);
    else
        io_clear_bit(lamp_channel_matrix[floor][button]);        
}
Beispiel #15
0
void elev_toggle_stop_lamp() {
	if(io_read_bit(LIGHT_STOP))
			io_clear_bit(LIGHT_STOP);
	else
		io_set_bit(LIGHT_STOP);
}