Skip to content

Commit

Permalink
implemented current lamps
Browse files Browse the repository at this point in the history
  • Loading branch information
elisaakj committed Mar 4, 2024
1 parent 2ff623e commit ca1bc5e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 29 deletions.
1 change: 0 additions & 1 deletion skeleton_project/source/FSM.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 4 additions & 21 deletions skeleton_project/source/lamp.c
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
9 changes: 2 additions & 7 deletions skeleton_project/source/lamp.h
Original file line number Diff line number Diff line change
Expand Up @@ -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!
11 changes: 11 additions & 0 deletions skeleton_project/source/run.c
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit ca1bc5e

Please sign in to comment.