int elev_init(void) { int i; // Init hardware if (!io_init()) return 0; // Zero all floor button lamps for (i = 0; i < N_FLOORS; ++i) { if (i != 0) elev_set_button_lamp(BUTTON_CALL_DOWN, i, 0); if (i != N_FLOORS - 1) elev_set_button_lamp(BUTTON_CALL_UP, i, 0); elev_set_button_lamp(BUTTON_COMMAND, i, 0); } // Clear stop lamp, door open lamp, and set floor indicator to ground floor. elev_set_stop_lamp(0); elev_set_door_open_lamp(0); elev_set_floor_indicator(0); // Return success. return 1; }
void nodstopEntry() { elev_set_stop_lamp(true); slettAlleOrdre(); elev_set_speed(0); tilstand2 = NODSTOPP; }
int elev_init(void) { int init_success = io_init(); if (!init_success){ return 0; } for (int f = 0; f < N_FLOORS; f++) { for (elev_button_type_t b = 0; b < N_BUTTONS; b++){ elev_set_button_lamp(b, f, 0); } } //drive down to valid floor if (elev_get_floor_sensor_signal() == -1){ elev_set_motor_direction(DIRN_DOWN); } while (elev_get_floor_sensor_signal() == -1) { ///Keep driving down until reached a floor } elev_set_motor_direction(DIRN_STOP); elev_set_stop_lamp(0); elev_set_door_open_lamp(0); elev_set_floor_indicator(elev_get_floor_sensor_signal()); return 1; }
int main(void){ // Initialize hardware if (!elev_init()) { printf("Unable to initialize elevator hardware!\n"); return 1; } States fsm_state = init; States fsm_previous_state = init; States fsm_new_state = init; system_state_t system_state; system_state.motor_direction = 0; system_state.current_floor = -1; reset_active_floors(&system_state); reset_called_floors(&system_state); while (1){ fsm_previous_state = fsm_state; fsm_state = fsm_new_state; switch (fsm_state){ case init: fsm_new_state = fsm_init_state(&system_state, fsm_previous_state); break; case idle: fsm_new_state = fsm_idle_state(&system_state,fsm_previous_state); break; case door_open: fsm_new_state = fsm_door_open(&system_state, fsm_previous_state); break; case going_down: fsm_new_state = fsm_going_down(&system_state, fsm_previous_state); break; case going_up: fsm_new_state = fsm_going_up(&system_state, fsm_previous_state); break; case stop: fsm_new_state = fsm_stop_button_pressed(&system_state, fsm_previous_state); break; default: elev_set_stop_lamp(1); break; } } }
void klarEntry() { elev_set_stop_lamp(false); if(tilstand1 == BEVEGER) bevegerEntry(); if(tilstand1 == APNE_DORER) startTimer(); tilstand2 = KLAR; }
void elev_reset_all_lamps(void) { elev_set_speed(0); elev_set_stop_lamp(0); elev_set_door_open_lamp(0); int floor; for (floor = 0; floor < N_FLOORS; ++floor) { elev_set_button_lamp(ELEV_DIR_DOWN, floor, 0); elev_set_button_lamp(ELEV_DIR_UP, floor, 0); elev_set_button_lamp(ELEV_DIR_COMMAND, floor, 0); } }
void elev_init(void) { int init_success = io_init(); assert(init_success && "Unable to initialize elevator hardware!"); for (int f = 0; f < N_FLOORS; f++) { for (elev_button_type_t b = 0; b < N_BUTTONS; b++){ elev_set_button_lamp(b, f, 0); } } elev_set_stop_lamp(0); elev_set_door_open_lamp(0); elev_set_floor_indicator(0); }
int elev_init(void) { int init_success = io_init(); if (!init_success){ return 0; } for (int f = 0; f < N_FLOORS; f++) { for (elev_button_type_t b = 0; b < N_BUTTONS; b++){ elev_set_button_lamp(b, f, 0); } } elev_set_stop_lamp(0); elev_set_door_open_lamp(0); elev_set_floor_indicator(0); return 1; }
void elev_init(void) { puts("ELEVATOR INIT CALLED"); int init_success = io_init(); assert(init_success && "Unable to initialize elevator hardware!"); elev_set_stop_lamp(0); elev_set_door_open_lamp(0); for (int f = 0; f < N_FLOORS; f++) { for (elev_button_type_t b = 0; b < N_BUTTONS; b++){ elev_set_button_lamp(b, f, 0); } } while(elev_get_floor_sensor_signal() != 0){ elev_set_motor_direction(DIRN_DOWN); } elev_set_motor_direction(DIRN_STOP); elev_set_floor_indicator(0); }
States fsm_stop_button_pressed(system_state_t* system_state, States fsm_previous_state){ system_state->next_floor = system_state->current_floor + system_state->motor_direction; elev_set_motor_direction(DIRN_STOP); reset_active_floors(system_state); reset_called_floors(system_state); initialize_button_indicators(system_state); if (elev_get_floor_sensor_signal() >= 0){ elev_set_stop_lamp(1); elev_set_door_open_lamp(1); if (!elev_get_stop_signal()){ elev_set_stop_lamp(0); return idle; } return stop; } else{ while (elev_get_stop_signal()) elev_set_stop_lamp(1); if (!elev_get_stop_signal()){ elev_set_stop_lamp(0); check_cmd_buttons(system_state); for (int i = 0; i < N_FLOORS; ++i){ if (system_state->elev_active_floors[i] == 1){ if (i < system_state->current_floor){ return going_down; } else if (i > system_state->current_floor){ return going_up; } else{ // if i is the floor currently indicated if (system_state->next_floor > system_state->current_floor){ return going_down; } else return going_up; } } } check_call_buttons(system_state); for (int i = 0; i < N_FLOORS; ++i){ if (system_state->elev_called_floors_down[i] || system_state->elev_called_floors_up[i]){ if (i < system_state->current_floor){ return going_down; } else if (i > system_state->current_floor){ return going_up; } else{ // if i is the floor currently indicated0 if (system_state->next_floor > system_state->current_floor) return going_down; else return going_up; } } } } } return stop; }
/* * Class: no_ntnu_stud_torbjovn_comedielevator_NativeInterface * Method: elev_set_stop_lamp * Signature: (I)V */ JNIEXPORT void JNICALL Java_no_ntnu_stud_torbjovn_comedielevator_NativeInterface_elev_1set_1stop_1lamp (JNIEnv * env, jobject obj, jint value) { elev_set_stop_lamp(value); }
void obstruksjonStoppEntry() { slettAlleOrdre(); elev_set_stop_lamp(true); tilstand2 = OBSTRUKSJON_STOPP; }
void obstruksjonEntry() { elev_set_stop_lamp(false); elev_set_speed(0); tilstand2 = OBSTRUKSJON; }
void tilstandsMaskin2(event_t event) { switch(tilstand2) { case(KLAR): switch(event) { case(NOD_STOPP): nodstopEntry(); break; case(OBSTRUKSJON_PA): obstruksjonEntry(); break; } break; case(OBSTRUKSJON): switch(event) { case(NOD_STOPP): obstruksjonStoppEntry(); break; case(OBSTRUKSJON_AV): klarEntry(); } break; case(NODSTOPP): switch(event) { case(NY_ORDRE): if(finnestOrdreInniHeis() && !elev_get_stop_signal()) { klarEntry(); } else { nodstopEntry(); } break; case(OBSTRUKSJON_PA): obstruksjonStoppEntry(); } break; case(OBSTRUKSJON_STOPP): switch(event) { case(NY_ORDRE): if(finnestOrdreInniHeis() && !elev_get_stop_signal()) obstruksjonEntry(); else obstruksjonStoppEntry(); break; case(OBSTRUKSJON_AV): nodstopEntry(); } if(tilstand2 != NODSTOPP && tilstand2 != OBSTRUKSJON_STOPP) elev_set_stop_lamp(false); break; } }