Skip to content

Commit

Permalink
cleanup lamp module names
Browse files Browse the repository at this point in the history
  • Loading branch information
elisaakj committed Mar 5, 2024
1 parent 108aef6 commit 6213704
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 33 deletions.
30 changes: 15 additions & 15 deletions skeleton_project/source/FSM.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void FSM_behaviour(FSM* p_fsm, time_t* p_timer, Queue* p_main_queue){
break;
case OPEN_EMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, true);
if (time_limit(p_timer, 3)){
if (timer_limit(p_timer, 3)){
printf("Empty elevator, timer ran out\n");
FSM_transition(p_fsm, TIMER, p_main_queue, p_timer);
}
Expand All @@ -58,7 +58,7 @@ void FSM_behaviour(FSM* p_fsm, time_t* p_timer, Queue* p_main_queue){
break;
case OPEN_UNEMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, true);
if (time_limit(p_timer, 3)){
if (timer_limit(p_timer, 3)){
printf("Unempty elevator, timer ran out\n");
FSM_transition(p_fsm, TIMER, p_main_queue, p_timer);
}
Expand All @@ -79,7 +79,7 @@ void FSM_behaviour(FSM* p_fsm, time_t* p_timer, Queue* p_main_queue){
elevio_motorDirection(DIRN_STOP);
break;
case BLOCKED_EMPTY:
if (time_limit(p_timer, 3)){
if (timer_limit(p_timer, 3)){
printf("Blocked empty elevator, timer ran out\n");
FSM_transition(p_fsm, TIMER, p_main_queue, p_timer);
}
Expand All @@ -88,7 +88,7 @@ void FSM_behaviour(FSM* p_fsm, time_t* p_timer, Queue* p_main_queue){
elevio_motorDirection(DIRN_STOP);
break;
case BLOCKED_UNEMPTY:
if (time_limit(p_timer, 3)){
if (timer_limit(p_timer, 3)){
printf("Blocked unempty elevator, timer ran out\n");
FSM_transition(p_fsm, TIMER, p_main_queue, p_timer);
}
Expand All @@ -111,7 +111,7 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
lamp_toggle(LAMP_DOWN, elevio_floorSensor(), false);
p_fsm->current_state = OPEN_UNEMPTY;
reset_timer(p_timer);
timer_reset(p_timer);
break;
default:
p_fsm->current_state = UP_EMPTY;
Expand All @@ -130,17 +130,17 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
lamp_toggle(LAMP_DOWN, elevio_floorSensor(), false);
if (queue_query(p_main_queue, -1, ANY, FALSE)){
reset_timer(p_timer);
timer_reset(p_timer);
p_fsm->current_state = OPEN_UNEMPTY;
} else {
reset_timer(p_timer);
timer_reset(p_timer);
p_fsm->current_state = OPEN_EMPTY;
}
break;
default:
p_fsm->current_state = UP_UNEMPTY;
}
// reset_timer(p_timer);
// timer_reset(p_timer);
break;

case DOWN_EMPTY:
Expand All @@ -151,7 +151,7 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
lamp_toggle(LAMP_DOWN, elevio_floorSensor(), false);
reset_timer(p_timer);
timer_reset(p_timer);
break;
default:
printf("default\n");
Expand All @@ -171,10 +171,10 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
lamp_toggle(LAMP_DOWN, elevio_floorSensor(), false);
if (queue_query(p_main_queue, -1, ANY, FALSE)) {
reset_timer(p_timer);
timer_reset(p_timer);
p_fsm->current_state = OPEN_UNEMPTY;
} else {
reset_timer(p_timer);
timer_reset(p_timer);
p_fsm->current_state = OPEN_EMPTY;
}
break;
Expand All @@ -201,7 +201,7 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
case STOP:
p_fsm->current_state = OPEN_EMPTY;
queue_clear(p_main_queue);
reset_timer(p_timer);
timer_reset(p_timer);
break;
case OBSTRUCTION:
p_fsm->current_state = BLOCKED_UNEMPTY;
Expand All @@ -224,7 +224,7 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
break;
case STAY:
p_fsm->current_state = OPEN_UNEMPTY;
reset_timer(p_timer);
timer_reset(p_timer);
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
Expand All @@ -241,7 +241,7 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
if (elevio_floorSensor()!=-1){
p_fsm->current_state = OPEN_EMPTY;
queue_clear(p_main_queue);
reset_timer(p_timer);
timer_reset(p_timer);
}
break;
case UP:
Expand All @@ -252,7 +252,7 @@ void FSM_transition(FSM* p_fsm, FSMTrigger trigger, Queue* p_main_queue, time_t*
break;
case STAY:
p_fsm->current_state = OPEN_UNEMPTY;
reset_timer(p_timer);
timer_reset(p_timer);
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
Expand Down
4 changes: 2 additions & 2 deletions skeleton_project/source/lamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ void lamp_disable_all() {
}

void lamp_startup(time_t* p_timer, int* floor) {
if (time_limit(p_timer, 0.75)) {
if (timer_limit(p_timer, 0.75)) {
lamp_set_all_on_floor((*floor)++);
reset_timer(p_timer);
timer_reset(p_timer);
*floor %= 4;
}
}
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 @@ -10,8 +10,6 @@
#include "button.h"
#include "lamp.h"

// TODO: check pragma once

int main() {
elevio_init();
time_t* p_timer = timer_init();
Expand Down
4 changes: 2 additions & 2 deletions skeleton_project/source/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ void run(

if (p_stop_button->was_just_released) { lamp_toggle(LAMP_STOP, -1, false); }

if (p_stop_button->pressed) { reset_timer(p_timer); }
if (p_stop_button->pressed) { timer_reset(p_timer); }

if (elevio_obstruction()) {
reset_timer(p_timer);
timer_reset(p_timer);
FSM_transition(p_fsm, OBSTRUCTION, p_main_queue, p_timer);
}

Expand Down
1 change: 1 addition & 0 deletions skeleton_project/source/run.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#pragma once
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
Expand Down
12 changes: 2 additions & 10 deletions skeleton_project/source/timer.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#include "timer.h"

// TODO: rename all functions to start with 'timer'
time_t* timer_init(){
time_t* p_timer = (time_t*)malloc(sizeof(time_t));

Expand All @@ -17,17 +16,10 @@ void timer_deinit(time_t* p_timer){
free(p_timer);
}

void reset_timer(time_t* p_timer){
void timer_reset(time_t* p_timer){
*p_timer = time(NULL);
}

// checks whether the timer has ran out of time and resets it if so
bool time_limit(time_t* p_timer, int limit){
bool timer_limit(time_t* p_timer, int limit){
return (difftime(time(NULL), *p_timer) >= limit);


// reset_timer(p_timer);
// return true;
// }
// return false;
}
4 changes: 2 additions & 2 deletions skeleton_project/source/timer.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@

time_t* timer_init();
void timer_deinit(time_t* p_timer);
void reset_timer(time_t* p_timer);
bool time_limit(time_t* p_timer, int limit);
void timer_reset(time_t* p_timer);
bool timer_limit(time_t* p_timer, int limit);

0 comments on commit 6213704

Please sign in to comment.