diff --git a/.vscode/settings.json b/.vscode/settings.json index 3483249..d10acf6 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -5,7 +5,8 @@ "stdlib.h": "c", "errno.h": "c", "rfid_handler.h": "c", - "fcntl.h": "c" + "fcntl.h": "c", + "file_operations.h": "c" }, "C_Cpp.errorSquiggles": "enabled" } \ No newline at end of file diff --git a/include/main.h b/include/main.h new file mode 100644 index 0000000..f945549 --- /dev/null +++ b/include/main.h @@ -0,0 +1,16 @@ +#include +#include +#include + +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#define TRUE 1 +#define FALSE 0 +#define BYTE uint8_t +#define MIN_X_TERMINAL_SIZE 80 +#define MIN_Y_TERMINAL_SIZE 30 + +int main(int argc, char const **argv); + +#endif \ No newline at end of file diff --git a/include/tui.h b/include/tui.h index 457fb9f..05c926f 100644 --- a/include/tui.h +++ b/include/tui.h @@ -4,9 +4,8 @@ #include #include #include +#include "main.h" -#define MIN_X_TERMINAL_SIZE 80 -#define MIN_Y_TERMINAL_SIZE 30 void uartDialog(char *uart_adress, int terminal_x, int terminal_y); diff --git a/include/users.h b/include/users.h index 39ac006..9305191 100644 --- a/include/users.h +++ b/include/users.h @@ -1,3 +1,5 @@ +#include "main.h" + #include #include #include @@ -15,7 +17,9 @@ typedef struct person uint32_t department; time_t last_time_event; - uint32_t total; + time_t total; + + BYTE available; pthread_mutex_t lock; } person_t; @@ -40,7 +44,18 @@ uint16_t generateUUID(node_t *_head); uint16_t searchUUIDByName(node_t *_head); -node_t *searchPersonByUUID(node_t *_head); +/** + * @brief Searches for a person in a linked list by their UUID. + * + * This function traverses a linked list starting from the given head node + * and searches for a node that matches the specified UUID. + * + * @param _head Pointer to the head node of the linked list. + * @param _uuid The UUID of the person to search for. + * @return Pointer to the node containing the person with the matching UUID, + * or NULL if no such person is found. + */ +node_t *searchPersonByUUID(node_t *_head, uint16_t _uuid); /** * @brief Adds a new person to the linked list. diff --git a/output/main b/output/main deleted file mode 100755 index 4680260..0000000 Binary files a/output/main and /dev/null differ diff --git a/src/main.c b/src/main.c index 7295927..f0faee3 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,7 @@ #include "tui.h" #include "rfid_handler.h" #include "file_operations.h" +#include "main.h" int main(int argc, char const **argv) { diff --git a/src/rfid_handler.c b/src/rfid_handler.c index 277c7d7..62eea72 100644 --- a/src/rfid_handler.c +++ b/src/rfid_handler.c @@ -1,5 +1,6 @@ #include "rfid_handler.h" #include "users.h" +#include "main.h" #include #include diff --git a/src/tui.c b/src/tui.c index cd5bf2b..63f52d6 100644 --- a/src/tui.c +++ b/src/tui.c @@ -2,6 +2,8 @@ #include #include #include +#include "main.h" + void uartDialog(char *uart_adress, int terminal_x, int terminal_y) { diff --git a/src/users.c b/src/users.c index 7b11b0f..3a5db1f 100644 --- a/src/users.c +++ b/src/users.c @@ -1,4 +1,6 @@ #include "users.h" +#include "main.h" + #include #include @@ -31,6 +33,24 @@ uint16_t generateUUID return uuid; } +node_t *searchPersonByUUID +( + node_t *_head, + uint16_t _uuid +) +{ + node_t *current = _head; + while (current != NULL) + { + if (current->user.uuid == _uuid) + { + return current; + } + current = current->next; + } + return NULL; +}; + int addPersonToList ( node_t **_head, @@ -67,6 +87,7 @@ int addPersonToList new_node->user.department = _department; new_node->user.last_time_event = -255; new_node->user.total = 0; + new_node->user.available = FALSE; new_node->next = NULL; @@ -83,5 +104,28 @@ int addPersonToList } current->next = new_node; + return 1; +} + +int addTimeEvent +( + node_t *_person +) +{ + time_t current_time = time(0); + + if (_person == NULL) + { + return 0; + } + + if (_person->user.available) + { + _person->user.total += (current_time - _person->user.last_time_event); + } + + _person->user.available = !_person->user.available; + _person->user.last_time_event = current_time; + return 1; } \ No newline at end of file