Added documentation

This commit is contained in:
RobinVdB8
2023-11-24 17:34:24 +01:00
parent 697403a8d8
commit 21f30bfd55

View File

@@ -46,7 +46,7 @@ static void mqtt_pub_request_cb(void *arg, err_t result) {
* Publishes the names of all the .bmp and .gif files on the topic getImageList * Publishes the names of all the .bmp and .gif files on the topic getImageList
*/ */
static void publish_data(mqtt_client_t *client, void *arg) { static void publish_data(mqtt_client_t *client, void *arg) {
char pub_payload[200]; char pub_payload[200] = {0};
err_t err; err_t err;
size_t max_files = 20; size_t max_files = 20;
size_t num_files; size_t num_files;
@@ -58,8 +58,6 @@ static void publish_data(mqtt_client_t *client, void *arg) {
num_files = llfs_file_list(file_list, max_files, "*.bmp"); num_files = llfs_file_list(file_list, max_files, "*.bmp");
strcpy(pub_payload, "\0");
if (num_files == 0) { if (num_files == 0) {
strcpy(pub_payload, "No images found"); strcpy(pub_payload, "No images found");
} else { } else {
@@ -166,6 +164,11 @@ static void mqtt_sub_request_cb(void *arg, err_t result) {
LOG_INFO(TAG, "Subscribe result: %d", result); LOG_INFO(TAG, "Subscribe result: %d", result);
} }
/**
* @brief Callback function for attempting a connection
* If a connection was made setup a callback function for incoming publishes.
* subscribes to the input topics and calls the publish_data function.
*/
static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) { static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection_status_t status) {
err_t err; err_t err;
@@ -192,6 +195,10 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection
} }
} }
/**
* @brief Attempts to create a connection to the mosquitto broker
* Creates a mqtt client and sets up a connection callback function
*/
static void mosquitto_connect(mqtt_client_t *client) { static void mosquitto_connect(mqtt_client_t *client) {
struct mqtt_connect_client_info_t ci; struct mqtt_connect_client_info_t ci;
err_t err; err_t err;
@@ -213,6 +220,10 @@ static void mosquitto_connect(mqtt_client_t *client) {
} }
} }
/**
* @brief Init function for the mosquitto application of the assignment
* Gives the global variables a value and calls the mosquitto_connect function
*/
void mug_init(void) { void mug_init(void) {
color = LCD_BLACK; color = LCD_BLACK;
bgcolor = LCD_WHITE; bgcolor = LCD_WHITE;
@@ -227,86 +238,89 @@ void mug_init(void) {
} }
} }
/**
* @brief Reads the color input string and outputs it to a useable value for LCD_APi
*/
uint32_t color_picker(char* color) { uint32_t color_picker(char* color) {
uint32_t output = LCD_BLACK; uint32_t output = LCD_BLACK;
if (strcmp((const char*)color, "blue") == 0) { if (strcmp((const char*)color, "blue") == 0) {
output = LCD_BLUE; return LCD_BLUE;
} }
if (strcmp((const char*)color, "green") == 0) { if (strcmp((const char*)color, "green") == 0) {
output = LCD_GREEN; return LCD_GREEN;
} }
if (strcmp((const char*)color, "red") == 0) { if (strcmp((const char*)color, "red") == 0) {
output = LCD_RED; return LCD_RED;
} }
if (strcmp((const char*)color, "cyan") == 0) { if (strcmp((const char*)color, "cyan") == 0) {
output = LCD_CYAN; return LCD_CYAN;
} }
if (strcmp((const char*)color, "magenta") == 0) { if (strcmp((const char*)color, "magenta") == 0) {
output = LCD_MAGENTA; return LCD_MAGENTA;
} }
if (strcmp((const char*)color, "yellow") == 0) { if (strcmp((const char*)color, "yellow") == 0) {
output = LCD_YELLOW; return LCD_YELLOW;
} }
if (strcmp((const char*)color, "light blue") == 0) { if (strcmp((const char*)color, "light blue") == 0) {
output = LCD_LIGHTBLUE; return LCD_LIGHTBLUE;
} }
if (strcmp((const char*)color, "light green") == 0) { if (strcmp((const char*)color, "light green") == 0) {
output = LCD_LIGHTGREEN; return LCD_LIGHTGREEN;
} }
if (strcmp((const char*)color, "light red") == 0) { if (strcmp((const char*)color, "light red") == 0) {
output = LCD_LIGHTRED; return LCD_LIGHTRED;
} }
if (strcmp((const char*)color, "light cyan") == 0) { if (strcmp((const char*)color, "light cyan") == 0) {
output = LCD_LIGHTCYAN; return LCD_LIGHTCYAN;
} }
if (strcmp((const char*)color, "light magenta") == 0) { if (strcmp((const char*)color, "light magenta") == 0) {
output = LCD_LIGHTMAGENTA; return LCD_LIGHTMAGENTA;
} }
if (strcmp((const char*)color, "light yellow") == 0) { if (strcmp((const char*)color, "light yellow") == 0) {
output = LCD_LIGHTYELLOW; return LCD_LIGHTYELLOW;
} }
if (strcmp((const char*)color, "dark blue") == 0) { if (strcmp((const char*)color, "dark blue") == 0) {
output = LCD_DARKBLUE; return LCD_DARKBLUE;
} }
if (strcmp((const char*)color, "dark green") == 0) { if (strcmp((const char*)color, "dark green") == 0) {
output = LCD_DARKGREEN; return LCD_DARKGREEN;
} }
if (strcmp((const char*)color, "dark red") == 0) { if (strcmp((const char*)color, "dark red") == 0) {
output = LCD_DARKRED; return LCD_DARKRED;
} }
if (strcmp((const char*)color, "dark cyan") == 0) { if (strcmp((const char*)color, "dark cyan") == 0) {
output = LCD_DARKCYAN; return LCD_DARKCYAN;
} }
if (strcmp((const char*)color, "dark magenta") == 0) { if (strcmp((const char*)color, "dark magenta") == 0) {
output = LCD_DARKMAGENTA; return LCD_DARKMAGENTA;
} }
if (strcmp((const char*)color, "dark yellow") == 0) { if (strcmp((const char*)color, "dark yellow") == 0) {
output = LCD_DARKYELLOW; return LCD_DARKYELLOW;
} }
if (strcmp((const char*)color, "white") == 0) { if (strcmp((const char*)color, "white") == 0) {
output = LCD_WHITE; return LCD_WHITE;
} }
if (strcmp((const char*)color, "light gray") == 0) { if (strcmp((const char*)color, "light gray") == 0) {
output = LCD_LIGHTGRAY; return LCD_LIGHTGRAY;
} }
if (strcmp((const char*)color, "gray") == 0) { if (strcmp((const char*)color, "gray") == 0) {
output = LCD_GRAY; return LCD_GRAY;
} }
if (strcmp((const char*)color, "dark gray") == 0) { if (strcmp((const char*)color, "dark gray") == 0) {
output = LCD_DARKGRAY; return LCD_DARKGRAY;
} }
if (strcmp((const char*)color, "black") == 0) { if (strcmp((const char*)color, "black") == 0) {
output = LCD_BLACK; return LCD_BLACK;
} }
if (strcmp((const char*)color, "brown") == 0) { if (strcmp((const char*)color, "brown") == 0) {
output = LCD_BROWN; return LCD_BROWN;
} }
if (strcmp((const char*)color, "orange") == 0) { if (strcmp((const char*)color, "orange") == 0) {
output = LCD_ORANGE; return LCD_ORANGE;
} }
if (strcmp((const char*)color, "transparent") == 0) { if (strcmp((const char*)color, "transparent") == 0) {
output = LCD_TRANSPARENT; return LCD_TRANSPARENT;
} }
return output; return output;