Added lcd_clear_text() and lcd_clear_images()

This commit is contained in:
RobinVdB8
2023-11-23 17:57:26 +01:00
parent 2cb8c28ef4
commit 4da408dadf

View File

@@ -24,7 +24,7 @@ static void mqtt_incoming_data_cb(void*, const uint8_t*, u16_t, u8_t);
static void mqtt_sub_request_cb(void*, err_t);
static void mqtt_connection_cb(mqtt_client_t*, void*, mqtt_connection_status_t);
static void example_do_connect(mqtt_client_t*);
static uint32_t color_picker(uint8_t*);
static uint32_t color_picker(char*);
//global variable used in mqtt_incoming_publish_cb and mqtt_incoming_data_cb to give an easy to use ID to the subscribed topics
static int inpub_id;
@@ -41,6 +41,10 @@ static void mqtt_pub_request_cb(void *arg, err_t result) {
}
}
/**
* @brief Publishes data
* Publishes the names of all the .bmp and .gif files on the topic getImageList
*/
static void example_publish(mqtt_client_t *client, void *arg) {
LOG_INFO(TAG, "Entering publish");
char pub_payload[200];
@@ -86,6 +90,10 @@ static void example_publish(mqtt_client_t *client, void *arg) {
}
}
/**
* @brief Handles incoming publish
* Callback function for when data was published to a subscribed topic
*/
static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len) {
LOG_INFO(TAG, "Incoming publish at topic %s with total length %u", topic, (unsigned int)tot_len);
//check for which topic a publish was received
@@ -103,21 +111,27 @@ static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len
}
}
/**
* @brief Handles incoming publish data
* Handles the recieved data from a publish to a subscribed topic
*/
static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) {
uint8_t data_buffer[len + 1];
char data_buffer[len + 1];
LOG_INFO(TAG, "Incoming publish payload with length %d, flags %u", len, (unsigned int)flags);
if(flags & MQTT_DATA_FLAG_LAST) {
memcpy(data_buffer, data, len);
data_buffer[len] = '\0';
switch(inpub_id) {
case 0:
//lcd_display_text("teststring", xpos, ypos, color, bgcolor, font);
//places text on the lcd
LOG_INFO(TAG, "incoming data on input/setText: %s.", data_buffer);
lcd_display_text(data_buffer, xpos, ypos, color, bgcolor, font);
lcd_clear_text();
lcd_display_text((const char*)data_buffer, xpos, ypos, color, font);
break;
case 1:
//places an image on the lcd
LOG_INFO(TAG, "incoming data on input/setImage: %s.", data_buffer);
lcd_clear_images();
if(data_buffer[len-3] == 'b') {
lcd_draw_img_from_fs((const char*)data_buffer, xpos, ypos);
}
@@ -126,12 +140,12 @@ static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t f
}
break;
case 2:
//changes the text color on the lcd
//changes the text color for the next time text is written
LOG_INFO(TAG, "incoming data on input/setTextColor: %s.", data_buffer);
color = color_picker(data_buffer);
break;
case 3:
//changes the background color
//changes the background color for the next time text is written
LOG_INFO(TAG, "incoming data on input/setColor: %s.", data_buffer);
bgcolor = color_picker(data_buffer);
break;
@@ -143,6 +157,9 @@ static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t f
}
}
/**
* @brief Callback function for outgoing subscribe request
*/
static void mqtt_sub_request_cb(void *arg, err_t result) {
LOG_INFO(TAG, "Subscribe result: %d", result);
}
@@ -161,8 +178,8 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection
if(err != ERR_OK) {
LOG_INFO(TAG, "mqtt_subscribe return: %d", err);
}
//publish list of images here
//publish list of images here
example_publish(client, NULL);
} else {
LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status);
@@ -206,7 +223,7 @@ void mug_init(void) {
}
}
uint32_t color_picker(uint8_t* color) {
uint32_t color_picker(char* color) {
uint32_t output = LCD_BLACK;
if(strcmp((const char*)color, "blue") == 0) {
output = LCD_BLUE;