Skip to content

Commit

Permalink
lab work
Browse files Browse the repository at this point in the history
  • Loading branch information
simanm02 authored Feb 13, 2025
1 parent 5822762 commit 3f215bc
Showing 1 changed file with 15 additions and 6 deletions.
21 changes: 15 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,18 @@ fn stop_elevator_at_floor_and_start (elevator: &mut Elevator, floor: u8, mut dir
} */

fn stop_elevator_at_floor_and_start(elevator: &mut Elevator, floor: u8) {
if let Some(pos) = elevator.call_buttons.iter().position(|call| call[0] == floor) {
let serving_call = elevator.call_buttons.get(0).unwrap().get(1).unwrap();
if let Some(pos) = elevator.call_buttons.iter().position(|call| call[0] == floor && call[1] == *serving_call) {
// Stop elevator
elevator.motor_direction(e::DIRN_STOP);

// Disable call button lights
for call_type in 0..3 {
elevator.call_button_light(floor, call_type, false);
}
//for call_type in 0..3 {
//elevator.call_button_light(floor, call_type, false);
//}


// Remove the call from the list
elevator.call_button_light(floor,*serving_call, false); // Remove the call from the list
elevator.call_buttons.remove(pos);
println!("Call for floor {} removed", floor);

Expand All @@ -108,13 +110,20 @@ fn stop_elevator_at_floor_and_start(elevator: &mut Elevator, floor: u8) {
// Handle pending calls and decide next direction
if let Some(next_call) = elevator.call_buttons.first() {
let next_floor = next_call[0];
let new_dir = if next_floor > floor {
let mut new_dir = if next_floor > floor {
e::DIRN_UP
} else if next_floor < floor {
e::DIRN_DOWN
} else {
elevator.call_button_light(floor, next_call[1], false);
elevator.call_buttons.remove(0);
e::DIRN_STOP
};
if let Some(next_call) = elevator.call_buttons.first() {
if new_dir == e::DIRN_STOP {
new_dir = hall_call_start_dir(next_call[0], floor, new_dir);
}
}
elevator.current_direction;
elevator.motor_direction(new_dir);
}
Expand Down

0 comments on commit 3f215bc

Please sign in to comment.