From ca1bc5eed9eacf8d7a30aed5bbb033a221636e64 Mon Sep 17 00:00:00 2001 From: elisaakj Date: Mon, 4 Mar 2024 12:43:13 +0100 Subject: [PATCH] implemented current lamps --- skeleton_project/source/FSM.c | 1 - skeleton_project/source/lamp.c | 25 ++++--------------------- skeleton_project/source/lamp.h | 9 ++------- skeleton_project/source/run.c | 11 +++++++++++ 4 files changed, 17 insertions(+), 29 deletions(-) diff --git a/skeleton_project/source/FSM.c b/skeleton_project/source/FSM.c index 975a819..4c8dc80 100644 --- a/skeleton_project/source/FSM.c +++ b/skeleton_project/source/FSM.c @@ -73,7 +73,6 @@ void FSM_behaviour(FSM* p_fsm, time_t* p_timer, Queue* p_main_queue){ elevio_motorDirection(DIRN_STOP); break; case BLOCKED_EMPTY: - // Ikke endre dør-lys? p_fsm->moving = false; elevio_motorDirection(DIRN_STOP); break; diff --git a/skeleton_project/source/lamp.c b/skeleton_project/source/lamp.c index 0f21022..9127a38 100644 --- a/skeleton_project/source/lamp.c +++ b/skeleton_project/source/lamp.c @@ -1,28 +1,11 @@ #include "lamp.h" -/* -Lamp* lamp_init(){ - Lamp* p_lamp = (Lamp*)malloc(sizeof(Lamp)); - - if (p_lamp!= NULL) { - *p_lamp = BUTTON_HALL_DOWN; - // *p_lamp = ; Lyse i etasjen heisen starter i? - } else { - printf("Error allocating memory for button\n"); - } - - return p_lamp; -} - -void lamp_deinit(Lamp* p_lamp) { - free(p_lamp); -} -*/ - -void toggle(Lamp_2 m_lamp, int floor, bool enable){ +void lamp_toggle(Lamp m_lamp, int floor, bool enable){ switch(m_lamp){ case LAMP_CURRENT: - // hvordan håndtere disse lysene? + while (elevio_floorSensor() != -1) { + elevio_floorIndicator(floor); + } break; case LAMP_UP: elevio_buttonLamp(floor, BUTTON_HALL_UP, enable); diff --git a/skeleton_project/source/lamp.h b/skeleton_project/source/lamp.h index b75f24e..9b94ba6 100644 --- a/skeleton_project/source/lamp.h +++ b/skeleton_project/source/lamp.h @@ -12,13 +12,8 @@ typedef enum{ LAMP_CAB, LAMP_STOP, LAMP_DOOR -} Lamp_2; +} Lamp; -//Lamp* lamp_init(void); -//void lamp_deinit(Lamp* p_lamp); - -void lamp_toggle(Lamp_2 m_lamp, int floor, bool enable); - -// ikke pointers pga kun enums?? +void lamp_toggle(Lamp m_lamp, int floor, bool enable); // L3 og L4! \ No newline at end of file diff --git a/skeleton_project/source/run.c b/skeleton_project/source/run.c index 68fa79b..46c72df 100644 --- a/skeleton_project/source/run.c +++ b/skeleton_project/source/run.c @@ -64,6 +64,17 @@ void run( // printf("Floor sensor: %d\n", elevio_floorSensor()); if (elevio_floorSensor() != -1) { p_fsm->current_floor = elevio_floorSensor(); + // Oppdatere current-lys (cursed løsning? hehe) + lamp_toggle(LAMP_CURRENT, p_fsm->current_floor, true); + + if (*target_floor > p_fsm->current_floor){ // beveger seg oppover + lamp_toggle(LAMP_CURRENT, p_fsm->current_floor - 1, false); + } else { + lamp_toggle(LAMP_CURRENT, p_fsm->current_floor + 1, false); + } + // evt: + // lamp_toggle(LAMP_CURRENT, p_fsm->current_floor + 1, false); + // lamp_toggle(LAMP_CURRENT, p_fsm->current_floor - 1, false); } if (*target_floor == elevio_floorSensor()) {