Skip to content

Commit

Permalink
implementation of lamp toggling
Browse files Browse the repository at this point in the history
  • Loading branch information
elisaakj committed Mar 3, 2024
1 parent e84ddae commit deec978
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 139 deletions.
29 changes: 19 additions & 10 deletions skeleton_project/source/FSM.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,62 +25,61 @@ void FSM_behaviour(FSM* p_fsm, time_t* p_timer, Queue* p_main_queue){

switch(p_fsm->current_state) {
case UP_EMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, false);
p_fsm->moving = true;
elevio_motorDirection(DIRN_UP);
elevio_doorOpenLamp(0);
break;
case UP_UNEMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, false);
p_fsm->moving = true;
elevio_motorDirection(DIRN_UP);
elevio_doorOpenLamp(0);
break;
case DOWN_EMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, false);
p_fsm->moving = true;
elevio_motorDirection(DIRN_DOWN);
elevio_doorOpenLamp(0);
break;
case DOWN_UNEMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, false);
p_fsm->moving = true;
elevio_motorDirection(DIRN_DOWN);
elevio_doorOpenLamp(0);
break;
case OPEN_EMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, true);
if (time_limit(p_timer)){
printf("timer empty\n");
FSM_transition(p_fsm, TIMER, p_main_queue, p_timer);
}
p_fsm->moving = false;
elevio_motorDirection(DIRN_STOP);
elevio_doorOpenLamp(1);
break;
case OPEN_UNEMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, true);
if (time_limit(p_timer)){
printf("timer unempty\n");
FSM_transition(p_fsm, TIMER, p_main_queue, p_timer);
}
p_fsm->moving = false;
elevio_motorDirection(DIRN_STOP);
elevio_doorOpenLamp(1);
break;
case CLOSED_EMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, false);
p_fsm->moving = false;
elevio_motorDirection(DIRN_STOP);
elevio_doorOpenLamp(0);
break;
case CLOSED_UNEMPTY:
lamp_toggle(LAMP_DOOR, p_fsm->current_floor, false);
p_fsm->moving = false;
elevio_motorDirection(DIRN_STOP);
elevio_doorOpenLamp(0);
break;
case BLOCKED_EMPTY:
// Ikke endre dør-lys?
p_fsm->moving = false;
elevio_motorDirection(DIRN_STOP);
elevio_doorOpenLamp(1);
break;
case BLOCKED_UNEMPTY:
p_fsm->moving = false;
elevio_motorDirection(DIRN_STOP);
elevio_doorOpenLamp(1);
break;
}
}
Expand All @@ -93,6 +92,8 @@ void FSM_transition(FSM* p_fsm, FSM_Trigger trigger, Queue* p_main_queue, time_t
switch(trigger){
case ENTERED_FLOOR:
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
p_fsm->current_state = OPEN_UNEMPTY;
reset_timer(p_timer);
break;
Expand All @@ -108,6 +109,8 @@ void FSM_transition(FSM* p_fsm, FSM_Trigger trigger, Queue* p_main_queue, time_t
break;
case ENTERED_FLOOR:
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
lamp_toggle(LAMP_UP, elevio_floorSensor(), false);
if (queue_has_off_requests(p_main_queue)){
reset_timer(p_timer);
p_fsm->current_state = OPEN_UNEMPTY;
Expand All @@ -126,6 +129,8 @@ void FSM_transition(FSM* p_fsm, FSM_Trigger trigger, Queue* p_main_queue, time_t
case ENTERED_FLOOR:
p_fsm->current_state = OPEN_UNEMPTY;
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
lamp_toggle(LAMP_DOWN, elevio_floorSensor(), false);
reset_timer(p_timer);
break;
default:
Expand All @@ -141,6 +146,8 @@ void FSM_transition(FSM* p_fsm, FSM_Trigger trigger, Queue* p_main_queue, time_t
break;
case ENTERED_FLOOR:
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
lamp_toggle(LAMP_DOWN, elevio_floorSensor(), false);
if (queue_has_off_requests(p_main_queue)){
reset_timer(p_timer);
p_fsm->current_state = OPEN_UNEMPTY;
Expand Down Expand Up @@ -198,6 +205,7 @@ void FSM_transition(FSM* p_fsm, FSM_Trigger trigger, Queue* p_main_queue, time_t
p_fsm->current_state = OPEN_UNEMPTY;
reset_timer(p_timer);
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
break;
default:
p_fsm->current_state = CLOSED_EMPTY;
Expand All @@ -222,6 +230,7 @@ void FSM_transition(FSM* p_fsm, FSM_Trigger trigger, Queue* p_main_queue, time_t
p_fsm->current_state = OPEN_UNEMPTY;
reset_timer(p_timer);
queue_remove_all(p_main_queue, elevio_floorSensor());
lamp_toggle(LAMP_CAB, elevio_floorSensor(), false);
break;
default:
p_fsm->current_state = CLOSED_UNEMPTY;
Expand Down
1 change: 1 addition & 0 deletions skeleton_project/source/FSM.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "driver/elevio.h"
#include "queue.h"
#include "timer.h"
#include "lamp.h"

// enums
typedef enum {
Expand Down
117 changes: 13 additions & 104 deletions skeleton_project/source/lamp.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,116 +19,25 @@ void lamp_deinit(Lamp* p_lamp) {
}
*/

void enable_lamp(Lamp m_lamp){
void toggle(Lamp_2 m_lamp, int floor, bool enable){
switch(m_lamp){
case LAMP_CURRENT_1:
// lysene her er jo ikke en knapp?
case LAMP_CURRENT:
// hvordan håndtere disse lysene?
break;
case LAMP_CURRENT_2:

case LAMP_UP:
elevio_buttonLamp(floor, BUTTON_HALL_UP, enable);
break;
case LAMP_CURRENT_3:

break;
case LAMP_CURRENT_4:

break;

case LAMP_UP_1:
elevio_buttonLamp(1, BUTTON_HALL_UP, 1);
break;
case LAMP_UP_2:
elevio_buttonLamp(2, BUTTON_HALL_UP, 1);
break;
case LAMP_DOWN_2:
elevio_buttonLamp(2, BUTTON_HALL_DOWN, 1);
break;
case LAMP_UP_3:
elevio_buttonLamp(3, BUTTON_HALL_UP, 1);
break;
case LAMP_DOWN_3:
elevio_buttonLamp(3, BUTTON_HALL_DOWN, 1);
break;
case LAMP_DOWN_4:
elevio_buttonLamp(4, BUTTON_HALL_DOWN, 1);
break;

case LAMP_ORDER_1:
elevio_buttonLamp(1, BUTTON_CAB, 1);
break;
case LAMP_ORDER_2:
elevio_buttonLamp(2, BUTTON_CAB, 1);
break;
case LAMP_ORDER_3:
elevio_buttonLamp(3, BUTTON_CAB, 1);
break;
case LAMP_ORDER_4:
elevio_buttonLamp(4, BUTTON_CAB, 1);
break;

case STOP_LAMP:
elevio_stopLamp(1);
case LAMP_DOWN:
elevio_buttonLamp(floor, BUTTON_HALL_DOWN, enable);
break;
case DOOR_LAMP:
elevio_doorOpenLamp(1);
case LAMP_CAB:
elevio_buttonLamp(floor, BUTTON_CAB, enable);
break;
}
}

// slå sammen disable og enable? ta inn bool for om skal skrus av eller på

void disable_lamp(Lamp m_lamp){
switch(m_lamp){
case LAMP_CURRENT_1:
// lysene her er jo ikke en knapp?
break;
case LAMP_CURRENT_2:

break;
case LAMP_CURRENT_3:

break;
case LAMP_CURRENT_4:

break;

case LAMP_UP_1:
elevio_buttonLamp(1, BUTTON_HALL_UP, 0);
break;
case LAMP_UP_2:
elevio_buttonLamp(2, BUTTON_HALL_UP, 0);
break;
case LAMP_DOWN_2:
elevio_buttonLamp(2, BUTTON_HALL_DOWN, 0);
break;
case LAMP_UP_3:
elevio_buttonLamp(3, BUTTON_HALL_UP, 0);
break;
case LAMP_DOWN_3:
elevio_buttonLamp(3, BUTTON_HALL_DOWN, 0);
break;
case LAMP_DOWN_4:
elevio_buttonLamp(4, BUTTON_HALL_DOWN, 0);
break;

case LAMP_ORDER_1:
elevio_buttonLamp(1, BUTTON_CAB, 0);
break;
case LAMP_ORDER_2:
elevio_buttonLamp(2, BUTTON_CAB, 0);
break;
case LAMP_ORDER_3:
elevio_buttonLamp(3, BUTTON_CAB, 0);
break;
case LAMP_ORDER_4:
elevio_buttonLamp(4, BUTTON_CAB, 0);
break;

case STOP_LAMP:
elevio_stopLamp(0);
case LAMP_STOP:
elevio_stopLamp(enable);
break;
case DOOR_LAMP:
elevio_doorOpenLamp(0);
case LAMP_DOOR:
elevio_doorOpenLamp(enable);
break;
}
}
38 changes: 13 additions & 25 deletions skeleton_project/source/lamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,22 @@
#include <stdlib.h>
#include <signal.h>
#include "driver/elevio.h"
#include <stdbool.h>

typedef enum{
// Etasjepanel
LAMP_CURRENT_1,
LAMP_CURRENT_2,
LAMP_CURRENT_3,
LAMP_CURRENT_4,

LAMP_UP_1,
LAMP_UP_2,
LAMP_DOWN_2,
LAMP_UP_3,
LAMP_DOWN_3,
LAMP_DOWN_4,

// Heispanel
LAMP_ORDER_1,
LAMP_ORDER_2,
LAMP_ORDER_3,
LAMP_ORDER_4,

STOP_LAMP,
DOOR_LAMP
} Lamp;
LAMP_CURRENT,
LAMP_UP,
LAMP_DOWN,
LAMP_CAB,
LAMP_STOP,
LAMP_DOOR
} Lamp_2;

//Lamp* lamp_init(void);
//void lamp_deinit(Lamp* p_lamp);
void enable_lamp(Lamp m_lamp);
void disable_lamp(Lamp m_lamp);

// ikke pointers pga kun enums??
void lamp_toggle(Lamp_2 m_lamp, int floor, bool enable);

// ikke pointers pga kun enums??

// L3 og L4!
3 changes: 3 additions & 0 deletions skeleton_project/source/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ void run(
if (pp_down_buttons[i]->was_just_pressed) {
queue_add(p_main_queue, (Request) {i, false, false});
queue_print(p_main_queue);
lamp_toggle(LAMP_DOWN, i, true);
}

if (pp_up_buttons[i]->was_just_pressed) {
queue_add(p_main_queue, (Request) {i, true, false});
queue_print(p_main_queue);
lamp_toggle(LAMP_UP, i, true);
}

if (pp_cab_buttons[i]->was_just_pressed) {
Expand All @@ -34,6 +36,7 @@ void run(
queue_add(p_main_queue, (Request) {i, false, true});
queue_print(p_main_queue);
}
lamp_toggle(LAMP_CAB, i, true);
}
}

Expand Down
1 change: 1 addition & 0 deletions skeleton_project/source/run.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "driver/elevio.h"
#include "button.h"
#include "FSM.h"
#include "lamp.h"

void run(
int* target_floor,
Expand Down

0 comments on commit deec978

Please sign in to comment.