-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from angrycompany16/david_work
David work
- Loading branch information
Showing
11 changed files
with
161 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"files.associations": { | ||
"elevio.h": "c" | ||
"elevio.h": "c", | ||
"run.h": "c", | ||
"time.h": "c", | ||
"button.h": "c", | ||
"stdio.h": "c" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "button.h" | ||
|
||
Button* button_init() { | ||
Button* p_button = (Button*)malloc(sizeof(Button)); | ||
if (p_button != NULL) { | ||
p_button->pressed = false; | ||
p_button->was_just_pressed = true; | ||
p_button->was_just_released = false; | ||
} | ||
|
||
return p_button; | ||
} | ||
|
||
void button_deinit(Button* button) { | ||
free(button); | ||
} | ||
|
||
void button_update(Button* button, bool value) { | ||
if (!button->pressed && value) { | ||
button->was_just_pressed = true; | ||
} else if (button->pressed && !value) { | ||
button->was_just_released = true; | ||
} else { | ||
button->was_just_pressed = false; | ||
button->was_just_released = false; | ||
} | ||
|
||
button->pressed = value; | ||
} | ||
|
||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#pragma once | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <stdbool.h> | ||
|
||
typedef struct { | ||
bool pressed; | ||
bool was_just_pressed; | ||
bool was_just_released; | ||
} Button; | ||
|
||
Button* button_init(); | ||
|
||
void button_deinit(Button* button); | ||
|
||
void button_update(Button* button, bool value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#include "run.h" | ||
|
||
void run( | ||
int* target_floor, | ||
Queue* p_main_queue, | ||
Button** pp_up_buttons, | ||
Button** pp_down_buttons, | ||
Button** pp_cab_buttons | ||
) { | ||
// Setup elevator | ||
|
||
// button_update(p_button_2_up, false); | ||
|
||
for (size_t i = 0; i < 4; i++) { | ||
button_update(pp_up_buttons[i], elevio_callButton(i, BUTTON_HALL_UP)); | ||
button_update(pp_down_buttons[i], elevio_callButton(i, BUTTON_HALL_DOWN)); | ||
button_update(pp_cab_buttons[i], elevio_callButton(i, BUTTON_CAB)); | ||
} | ||
|
||
|
||
// printf("%d\n", pp_up_buttons[0]->was_just_pressed); | ||
|
||
if (pp_cab_buttons[3]->was_just_pressed) { | ||
printf("4th floor cab button pressed\n"); | ||
} | ||
|
||
// button_update(p_button_2_up, elevio_callButton(2, BUTTON_HALL_UP)); | ||
// if (elevio_callButton(2, BUTTON_HALL_UP)) { | ||
// } | ||
// sleep(0.001); | ||
|
||
// printf("%d\n", elevio_callButton(2, BUTTON_HALL_UP)); | ||
|
||
// if (p_button_2_up->was_just_pressed) { | ||
|
||
// // queue_add(p_main_queue, (Request) {2, false, false}); | ||
// printf("Button just pressed\n"); | ||
// // queue_print(p_main_queue); | ||
// } | ||
|
||
// if (p_button_2_up->was_just_released) { | ||
|
||
// // queue_add(p_main_queue, (Request) {2, false, false}); | ||
// printf("Button just released\n"); | ||
// // queue_print(p_main_queue); | ||
// } | ||
|
||
/* | ||
for (int i = 0; i < 4; i++) { | ||
if (elevio_callButton(i, BUTTON_HALL_DOWN)) { | ||
queue_add(p_main_queue, (Request) {i, false, false}); | ||
queue_print(p_main_queue); | ||
} | ||
if (elevio_callButton(i, BUTTON_HALL_UP)) { | ||
queue_add(p_main_queue, (Request) {i, true, false}); | ||
queue_print(p_main_queue); | ||
} | ||
if (elevio_callButton(i, BUTTON_CAB)) { | ||
if (i > elevio_floorSensor()) { | ||
queue_add(p_main_queue, (Request) {i, true, true}); | ||
queue_print(p_main_queue); | ||
} else if (i < elevio_floorSensor()) { | ||
queue_add(p_main_queue, (Request) {i, true, false}); | ||
queue_print(p_main_queue); | ||
} | ||
} | ||
} | ||
*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <signal.h> | ||
#include <time.h> | ||
#include <unistd.h> | ||
#include "queue.h" | ||
#include "driver/elevio.h" | ||
#include "button.h" | ||
|
||
void run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters