Skip to content

Commit

Permalink
Revisions and final touchups
Browse files Browse the repository at this point in the history
  • Loading branch information
angrycompany16 committed Mar 18, 2024
1 parent de9bfaa commit 6dd591e
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 34 deletions.
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"stdio.h": "c"
}
}
4 changes: 1 addition & 3 deletions skeleton_project/source/FSM.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
default:
p_fsm->current_state = UP_UNEMPTY;
}
// timer_reset(p_timer);
break;

case DOWN_EMPTY:
Expand All @@ -156,7 +155,6 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
timer_reset(p_timer);
break;
default:
// printf("default\n");
p_fsm->current_state = DOWN_EMPTY;
}
break;
Expand Down Expand Up @@ -189,7 +187,7 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
case OPEN_EMPTY:
switch(trigger){
case OBSTRUCTION:
p_fsm->current_state = BLOCKED_UNEMPTY;
p_fsm->current_state = BLOCKED_EMPTY;
break;
case TIMER:
p_fsm->current_state = CLOSED_EMPTY;
Expand Down
1 change: 0 additions & 1 deletion skeleton_project/source/FSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ typedef struct {
bool moving;
} FSM;

// functions
FSM* FSM_init(void);
void FSM_deinit(FSM* p_fsm);
void FSM_behaviour(FSM* p_fsm, time_t* p_timer, Queue* p_main_queue);
Expand Down
3 changes: 0 additions & 3 deletions skeleton_project/source/lamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ void lamp_disable_all() {
elevio_buttonLamp(i, BUTTON_HALL_UP, 0);
elevio_buttonLamp(i, BUTTON_HALL_DOWN, 0);
elevio_buttonLamp(i, BUTTON_CAB, 0);
//elevio_stopLamp(0);
elevio_doorOpenLamp(0);
// elevio_buttonLamp(i, , 0);
}
}

Expand All @@ -49,7 +47,6 @@ void lamp_startup(time_t* p_timer, int* floor) {
}

void lamp_set_all_on_floor(int floor) {
// printf("Set all on floor was called\n");
lamp_disable_all();
elevio_floorIndicator(floor);
elevio_buttonLamp(floor, BUTTON_HALL_UP, 1);
Expand Down
2 changes: 0 additions & 2 deletions skeleton_project/source/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ int main() {
/* Run */
while(1) {
run(&target_floor, p_main_queue, p_fsm, p_timer, p_stop_button, pp_up_buttons, pp_down_buttons, pp_cab_buttons);

// nanosleep(&(struct timespec){0, 20*1000}, NULL);
}

queue_deinit(p_main_queue);
Expand Down
15 changes: 0 additions & 15 deletions skeleton_project/source/queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ void queue_print(Queue* p_queue) {
}

bool queue_query(Queue* p_queue, int floor, QueueQueryItem direction, QueueQueryItem off) {
// bool return value;
for (size_t i = 0; i < p_queue->youngest_queue_element; i++) {
if (check_request(&p_queue->queue[i], floor, direction, off)) { return true; }
}
Expand All @@ -69,39 +68,25 @@ bool queue_query(Queue* p_queue, int floor, QueueQueryItem direction, QueueQuery
bool check_request(Request* p_request, int floor, QueueQueryItem direction, QueueQueryItem off) {
if (floor == -1) {
if (direction == ANY) {
// printf("floor: ANY, direction: ANY, off: ANY");
// return queue_query_off(p_queue, off);
return p_request->off == off;
} else {
if (off == ANY) {
// printf("floor: ANY, direction: something, off: ANY");
// return queue_query_direction(p_queue, direction);
return p_request->direction == direction;
} else {
// printf("floor: ANY, direction: something, off: something");
// return queue_query_off(p_queue, off) && queue_query_direction(p_queue, direction);
return p_request->direction == direction && p_request->off == off;
}
}
} else {
if (direction == ANY) {
if (off == ANY) {
// printf("floor: something, direction: ANY, off: ANY");
// return queue_query_floor(p_queue, floor);
return p_request->floor == floor;
} else {
// printf("floor: something, direction: ANY, off: something");
// return queue_query_floor(p_queue, floor) && queue_query_off(p_queue, off);
return p_request->floor == floor && p_request->off == off;
}
} else {
if (off == ANY) {
// printf("floor: something, direction: something, off: ANY");
// return queue_query_floor(p_queue, floor) && queue_query_direction(p_queue, direction);
return p_request->floor == floor && p_request->direction == direction;
} else {
// printf("floor: something, direction: something, off: something");
// return queue_query_floor(p_queue, floor) && queue_query_off(p_queue, off) && queue_query_direction(p_queue, direction);
return p_request->floor == floor && p_request->direction == direction && p_request->off == off;
}
}
Expand Down
6 changes: 0 additions & 6 deletions skeleton_project/source/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,7 @@ void queue_clear(Queue* p_queue);

void queue_print(Queue* p_queue);

// bool queue_has_off_requests(Queue* p_queue);

bool queue_query(Queue* p_queue, int floor, QueueQueryItem direction, QueueQueryItem off);
bool check_request(Request* p_request, int floor, QueueQueryItem direction, QueueQueryItem off);

// static bool queue_query_floor(Queue* p_queue, int floor);
// static bool queue_query_direction(Queue* p_queue, bool direction);
// static bool queue_query_off(Queue* p_queue, bool off);

Request* queue_find_first_off_request(Queue* p_queue);
2 changes: 1 addition & 1 deletion skeleton_project/source/request.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <stdbool.h>

// NOTE: `direction` boolean has two meanings. When a button is pressed outside the elevator, `direction` refers to whether the
// pershon pressed the direction or down button. However, when a button is pressed inside the elevator, `direction` refers to
// person pressed the up or down button. However, when a button is pressed inside the elevator, `direction` refers to
// whether the current floor is less than or greater than the floor that the person wants to go to.
// The case where a user enters the elevator and presses the button corresponding to the current floor is not handled.
typedef struct {
Expand Down
4 changes: 1 addition & 3 deletions skeleton_project/source/run.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
#include "run.h"

// TODO: Make lights work proplerly with stop button
// TODO: Performance improvements
void run(
int* target_floor,
Queue* p_main_queue,
Expand Down Expand Up @@ -105,5 +103,5 @@ void run(

FSM_behaviour(p_fsm, p_timer, p_main_queue);

printf("Current state: %d\n", p_fsm->current_state);
// printf("Current state: %d\n", p_fsm->current_state);
}

0 comments on commit 6dd591e

Please sign in to comment.