Solved some reviews
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file mug.h
|
||||
* @header for mosquitto application of the groups assignment
|
||||
* header for mosquitto application of the groups assignment
|
||||
* @author RobinVdB
|
||||
*/
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* @file mug.c
|
||||
* @mosquitto application for group assignment
|
||||
* mosquitto application for group assignment
|
||||
* @author RobinVdB
|
||||
*/
|
||||
|
||||
@@ -16,6 +16,13 @@
|
||||
#define LOGGER_LEVEL_INFO
|
||||
#include "log.h"
|
||||
|
||||
#define ATTEMPT_RECONNECT_AMOUNT 50
|
||||
#define PUBLISH_QOS 2
|
||||
#define PUBLISH_RETAIN 1
|
||||
#define MQTT_SERVER_PORT 1883
|
||||
#define PRINT_XPOS 50
|
||||
#define PRINT_YPOS 50
|
||||
|
||||
// Function prototypes
|
||||
static void mqtt_pub_request_cb(void*, err_t);
|
||||
static void publish_data(mqtt_client_t*, void*);
|
||||
@@ -61,8 +68,8 @@ static void publish_data(mqtt_client_t* client, void* arg) {
|
||||
size_t max_files = 20;
|
||||
size_t num_files;
|
||||
llfs_file_t file_list[max_files];
|
||||
u8_t qos = 2;
|
||||
u8_t retain = 1;
|
||||
u8_t qos = PUBLISH_QOS;
|
||||
u8_t retain = PUBLISH_RETAIN;
|
||||
|
||||
LOG_DEBUG(TAG, "Entering publish");
|
||||
|
||||
@@ -108,7 +115,7 @@ static void publish_data(mqtt_client_t* client, void* arg) {
|
||||
* @param[in] tot_len Length of the incoming data
|
||||
*/
|
||||
static void mqtt_incoming_publish_cb(void* arg, const char* topic, uint32_t tot_len) {
|
||||
LOG_DEBUG(TAG, "Incoming publish at topic %s with total length %u", topic, (unsigned int)tot_len);
|
||||
LOG_DEBUG(TAG, "Incoming publish at topic %s with total length %lu", topic, tot_len);
|
||||
// Check for which topic a publish was received
|
||||
if (strcmp(topic, "input/setText") == 0) {
|
||||
inpub_id = 0;
|
||||
@@ -135,6 +142,7 @@ static void mqtt_incoming_publish_cb(void* arg, const char* topic, uint32_t tot_
|
||||
*/
|
||||
static void mqtt_incoming_data_cb(void* arg, const uint8_t* data, uint16_t len, uint8_t flags) {
|
||||
char data_buffer[len + 1];
|
||||
lcd_gif_t* gif;
|
||||
|
||||
LOG_INFO(TAG, "Incoming publish payload with length %d, flags %u", len, (unsigned int)flags);
|
||||
if (flags & MQTT_DATA_FLAG_LAST) {
|
||||
@@ -156,7 +164,10 @@ static void mqtt_incoming_data_cb(void* arg, const uint8_t* data, uint16_t len,
|
||||
lcd_draw_img_from_fs((const char*)data_buffer, xpos, ypos);
|
||||
}
|
||||
if (data_buffer[len - 3] == 'g') {
|
||||
lcd_draw_gif_from_fs((const char*)data_buffer, xpos, ypos);
|
||||
gif = lcd_draw_gif_from_fs((const char*)data_buffer, xpos, ypos);
|
||||
if (gif == NULL) {
|
||||
LOG_INFO(TAG, "GIF could not be drawn");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
@@ -216,7 +227,7 @@ static void mqtt_connection_cb(mqtt_client_t* client, void* arg, mqtt_connection
|
||||
} else {
|
||||
LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status);
|
||||
|
||||
while (connection_attempt_counter < 50) {
|
||||
while (connection_attempt_counter < ATTEMPT_RECONNECT_AMOUNT) {
|
||||
connection_attempt_counter++;
|
||||
// Try to reconnect
|
||||
mosquitto_connect(client);
|
||||
@@ -259,8 +270,8 @@ void mug_init(void) {
|
||||
color = LCD_BLACK;
|
||||
bgcolor = LCD_WHITE;
|
||||
font = LCD_FONT16;
|
||||
xpos = 50;
|
||||
ypos = 50;
|
||||
xpos = PRINT_XPOS;
|
||||
ypos = PRINT_YPOS;
|
||||
connection_attempt_counter = 0;
|
||||
|
||||
mqtt_client_t* client = mqtt_client_new();
|
||||
@@ -276,85 +287,85 @@ void mug_init(void) {
|
||||
* @param[in] color Input string to select a color
|
||||
* @return color Define to use with the LCD_API
|
||||
*/
|
||||
uint32_t color_picker(char* color) {
|
||||
uint32_t color_picker(char* color_in) {
|
||||
uint32_t output = LCD_BLACK;
|
||||
|
||||
if (strcmp((const char*)color, "blue") == 0) {
|
||||
if (strcmp((const char*)color_in, "blue") == 0) {
|
||||
return LCD_BLUE;
|
||||
}
|
||||
if (strcmp((const char*)color, "green") == 0) {
|
||||
if (strcmp((const char*)color_in, "green") == 0) {
|
||||
return LCD_GREEN;
|
||||
}
|
||||
if (strcmp((const char*)color, "red") == 0) {
|
||||
if (strcmp((const char*)color_in, "red") == 0) {
|
||||
return LCD_RED;
|
||||
}
|
||||
if (strcmp((const char*)color, "cyan") == 0) {
|
||||
if (strcmp((const char*)color_in, "cyan") == 0) {
|
||||
return LCD_CYAN;
|
||||
}
|
||||
if (strcmp((const char*)color, "magenta") == 0) {
|
||||
if (strcmp((const char*)color_in, "magenta") == 0) {
|
||||
return LCD_MAGENTA;
|
||||
}
|
||||
if (strcmp((const char*)color, "yellow") == 0) {
|
||||
if (strcmp((const char*)color_in, "yellow") == 0) {
|
||||
return LCD_YELLOW;
|
||||
}
|
||||
if (strcmp((const char*)color, "light blue") == 0) {
|
||||
if (strcmp((const char*)color_in, "light blue") == 0) {
|
||||
return LCD_LIGHTBLUE;
|
||||
}
|
||||
if (strcmp((const char*)color, "light green") == 0) {
|
||||
if (strcmp((const char*)color_in, "light green") == 0) {
|
||||
return LCD_LIGHTGREEN;
|
||||
}
|
||||
if (strcmp((const char*)color, "light red") == 0) {
|
||||
if (strcmp((const char*)color_in, "light red") == 0) {
|
||||
return LCD_LIGHTRED;
|
||||
}
|
||||
if (strcmp((const char*)color, "light cyan") == 0) {
|
||||
if (strcmp((const char*)color_in, "light cyan") == 0) {
|
||||
return LCD_LIGHTCYAN;
|
||||
}
|
||||
if (strcmp((const char*)color, "light magenta") == 0) {
|
||||
if (strcmp((const char*)color_in, "light magenta") == 0) {
|
||||
return LCD_LIGHTMAGENTA;
|
||||
}
|
||||
if (strcmp((const char*)color, "light yellow") == 0) {
|
||||
if (strcmp((const char*)color_in, "light yellow") == 0) {
|
||||
return LCD_LIGHTYELLOW;
|
||||
}
|
||||
if (strcmp((const char*)color, "dark blue") == 0) {
|
||||
if (strcmp((const char*)color_in, "dark blue") == 0) {
|
||||
return LCD_DARKBLUE;
|
||||
}
|
||||
if (strcmp((const char*)color, "dark green") == 0) {
|
||||
if (strcmp((const char*)color_in, "dark green") == 0) {
|
||||
return LCD_DARKGREEN;
|
||||
}
|
||||
if (strcmp((const char*)color, "dark red") == 0) {
|
||||
if (strcmp((const char*)color_in, "dark red") == 0) {
|
||||
return LCD_DARKRED;
|
||||
}
|
||||
if (strcmp((const char*)color, "dark cyan") == 0) {
|
||||
if (strcmp((const char*)color_in, "dark cyan") == 0) {
|
||||
return LCD_DARKCYAN;
|
||||
}
|
||||
if (strcmp((const char*)color, "dark magenta") == 0) {
|
||||
if (strcmp((const char*)color_in, "dark magenta") == 0) {
|
||||
return LCD_DARKMAGENTA;
|
||||
}
|
||||
if (strcmp((const char*)color, "dark yellow") == 0) {
|
||||
if (strcmp((const char*)color_in, "dark yellow") == 0) {
|
||||
return LCD_DARKYELLOW;
|
||||
}
|
||||
if (strcmp((const char*)color, "white") == 0) {
|
||||
if (strcmp((const char*)color_in, "white") == 0) {
|
||||
return LCD_WHITE;
|
||||
}
|
||||
if (strcmp((const char*)color, "light gray") == 0) {
|
||||
if (strcmp((const char*)color_in, "light gray") == 0) {
|
||||
return LCD_LIGHTGRAY;
|
||||
}
|
||||
if (strcmp((const char*)color, "gray") == 0) {
|
||||
if (strcmp((const char*)color_in, "gray") == 0) {
|
||||
return LCD_GRAY;
|
||||
}
|
||||
if (strcmp((const char*)color, "dark gray") == 0) {
|
||||
if (strcmp((const char*)color_in, "dark gray") == 0) {
|
||||
return LCD_DARKGRAY;
|
||||
}
|
||||
if (strcmp((const char*)color, "black") == 0) {
|
||||
if (strcmp((const char*)color_in, "black") == 0) {
|
||||
return LCD_BLACK;
|
||||
}
|
||||
if (strcmp((const char*)color, "brown") == 0) {
|
||||
if (strcmp((const char*)color_in, "brown") == 0) {
|
||||
return LCD_BROWN;
|
||||
}
|
||||
if (strcmp((const char*)color, "orange") == 0) {
|
||||
if (strcmp((const char*)color_in, "orange") == 0) {
|
||||
return LCD_ORANGE;
|
||||
}
|
||||
if (strcmp((const char*)color, "transparent") == 0) {
|
||||
if (strcmp((const char*)color_in, "transparent") == 0) {
|
||||
return LCD_TRANSPARENT;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user