Added styleguid.xml to editor

This commit is contained in:
RobinVdB8
2023-11-20 13:20:46 +01:00
parent b79a42b767
commit bbbf17b5ca

View File

@@ -31,7 +31,7 @@ static int inpub_id;
static const char *TAG = "mug"; static const char *TAG = "mug";
static uint16_t xpos; static uint16_t xpos;
static uint16_t ypos; static uint16_t ypos;
static sFONT* font = LCD_FONT16; static sFONT* font;
static uint32_t color; static uint32_t color;
static uint32_t bgcolor; static uint32_t bgcolor;
@@ -54,102 +54,103 @@ static void example_publish(mqtt_client_t *client, void *arg) {
num_files = llfs_file_list(file_list, max_files, "*.png"); num_files = llfs_file_list(file_list, max_files, "*.png");
if(num_files == 0) { if(num_files == 0) {
strcpy(pub_payload, "No images found"); strcpy(pub_payload, "No images found");
} else { } else {
for (size_t i = 0; i < num_files; i++) { for (size_t i = 0; i < num_files; i++) {
// Concatenate file names into the payload string // Concatenate file names into the payload string
strcat(pub_payload, file_list[i].name); strcat(pub_payload, file_list[i].name);
strcat(pub_payload, ", "); // Add a space between file names strcat(pub_payload, ", "); // Add a space between file names
} }
} }
err = mqtt_publish(client, "getImageList", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg); err = mqtt_publish(client, "getImageList", pub_payload, strlen(pub_payload), qos, retain, mqtt_pub_request_cb, arg);
if(err != ERR_OK) { if(err != ERR_OK) {
LOG_INFO(TAG, "Publish err: %d", err); LOG_INFO(TAG, "Publish err: %d", err);
} }
} }
static void mqtt_incoming_publish_cb(void *arg, const char *topic, u32_t tot_len) { 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); 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 //check for which topic a publish was received
if(strcmp(topic, "input/setText") == 0) { if(strcmp(topic, "input/setText") == 0) {
inpub_id = 0; inpub_id = 0;
} else if(strcmp(topic, "input/setImage") == 0) { } else if(strcmp(topic, "input/setImage") == 0) {
inpub_id = 1; inpub_id = 1;
} else if(strcmp(topic, "input/setTextColor") == 0) { } else if(strcmp(topic, "input/setTextColor") == 0) {
inpub_id = 2; inpub_id = 2;
} else if(strcmp(topic, "input/setColor") == 0) { } else if(strcmp(topic, "input/setColor") == 0) {
inpub_id = 3; inpub_id = 3;
} else { } else {
//in case of wrong topic //in case of wrong topic
inpub_id = 4; inpub_id = 4;
} }
} }
static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) { static void mqtt_incoming_data_cb(void *arg, const u8_t *data, u16_t len, u8_t flags) {
uint8_t data_buffer[len + 1]; uint8_t data_buffer[len + 1];
LOG_INFO(TAG, "Incoming publish payload with length %d, flags %u", len, (unsigned int)flags); LOG_INFO(TAG, "Incoming publish payload with length %d, flags %u", len, (unsigned int)flags);
if(flags & MQTT_DATA_FLAG_LAST) { if(flags & MQTT_DATA_FLAG_LAST) {
memcpy(data_buffer, data, len); memcpy(data_buffer, data, len);
data_buffer[len] = '\0'; data_buffer[len] = '\0';
switch(inpub_id) { switch(inpub_id) {
case 0: case 0:
//lcd_display_text("teststring", xpos, ypos, color, bgcolor, font); //lcd_display_text("teststring", xpos, ypos, color, bgcolor, font);
LOG_INFO(TAG, "incoming data on input/setText:\n %s.", data); LOG_INFO(TAG, "incoming data on input/setText: %s.", data);
lcd_display_text(data_buffer, xpos, ypos, color, bgcolor, font); lcd_display_text(data_buffer, xpos, ypos, color, bgcolor, font);
break; break;
case 1: case 1:
//places an image on the lcd //places an image on the lcd
LOG_INFO(TAG, "incoming data on input/setImage:\n %s.", data); LOG_INFO(TAG, "incoming data on input/setImage: %s.", data);
break; //call function here
case 2: break;
//changes the text color on the lcd case 2:
LOG_INFO(TAG, "incoming data on input/setTextColor:\n %s.", data); //changes the text color on the lcd
color = color_picker(data_buffer); LOG_INFO(TAG, "incoming data on input/setTextColor: %s.", data);
break; color = color_picker(data_buffer);
case 3: break;
//changes the background color case 3:
LOG_INFO(TAG, "incoming data on input/setColor:\n %s.", data); //changes the background color
bgcolor = color_picker(data_buffer); LOG_INFO(TAG, "incoming data on input/setColor: %s.", data);
break; bgcolor = color_picker(data_buffer);
default: break;
LOG_INFO(TAG, "Publish received on wrong topic, incoming data ignored."); default:
} LOG_INFO(TAG, "Publish received on wrong topic, incoming data ignored.");
} else { }
} else {
} }
} }
static void mqtt_sub_request_cb(void *arg, err_t result) { 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);
} }
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) {
LOG_INFO(TAG, "entered connection cb function"); LOG_INFO(TAG, "entered connection cb function");
err_t err; err_t err;
if(status == MQTT_CONNECT_ACCEPTED) { if(status == MQTT_CONNECT_ACCEPTED) {
LOG_INFO(TAG, "mqtt_connection_cb: Successfully connected"); LOG_INFO(TAG, "mqtt_connection_cb: Successfully connected");
//set up callback function for input //set up callback function for input
mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg); mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg);
//subscribe to the topics setText, setImage, setColor and setTextcolor //subscribe to the topics setText, setImage, setColor and setTextcolor
err = mqtt_subscribe(client, "input/#", 1, mqtt_sub_request_cb, arg); err = mqtt_subscribe(client, "input/#", 1, mqtt_sub_request_cb, arg);
if(err != ERR_OK) { if(err != ERR_OK) {
LOG_INFO(TAG, "mqtt_subscribe return: %d", err); LOG_INFO(TAG, "mqtt_subscribe return: %d", err);
} }
//publish list of images here //publish list of images here
example_publish(client, NULL); example_publish(client, NULL);
} else { } else {
LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status); LOG_INFO(TAG, "mqtt_connection_cb: Disconnected, reason: %d", status);
//try to reconnect //try to reconnect
example_do_connect(client); example_do_connect(client);
} }
} }
static void example_do_connect(mqtt_client_t *client) { static void example_do_connect(mqtt_client_t *client) {
LOG_INFO(TAG, "testing the connection"); LOG_INFO(TAG, "testing the connection");
struct mqtt_connect_client_info_t ci; struct mqtt_connect_client_info_t ci;
err_t err; err_t err;
@@ -169,98 +170,99 @@ static void example_do_connect(mqtt_client_t *client) {
} }
void mug_init(void) { void mug_init(void) {
color = LCD_BLACK; color = LCD_BLACK;
bgcolor = LCD_WHITE; bgcolor = LCD_WHITE;
xpos = 50; font = LCD_FONT16;
ypos = 50; xpos = 50;
ypos = 50;
mqtt_client_t *client = mqtt_client_new(); mqtt_client_t *client = mqtt_client_new();
if(client != NULL) { if(client != NULL) {
LOG_INFO(TAG, "Starting connection test"); LOG_INFO(TAG, "Starting connection test");
example_do_connect(client); example_do_connect(client);
} }
} }
uint32_t color_picker(uint8_t* color) { uint32_t color_picker(uint8_t* 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; output = LCD_BLUE;
} }
if(strcmp((const char*)color, "green") == 0) { if(strcmp((const char*)color, "green") == 0) {
output = LCD_GREEN; output = LCD_GREEN;
} }
if(strcmp((const char*)color, "red") == 0) { if(strcmp((const char*)color, "red") == 0) {
output = LCD_RED; output = LCD_RED;
} }
if(strcmp((const char*)color, "cyan") == 0) { if(strcmp((const char*)color, "cyan") == 0) {
output = LCD_CYAN; output = LCD_CYAN;
} }
if(strcmp((const char*)color, "magenta") == 0) { if(strcmp((const char*)color, "magenta") == 0) {
output = LCD_MAGENTA; output = LCD_MAGENTA;
} }
if(strcmp((const char*)color, "yellow") == 0) { if(strcmp((const char*)color, "yellow") == 0) {
output = LCD_YELLOW; output = LCD_YELLOW;
} }
if(strcmp((const char*)color, "light blue") == 0) { if(strcmp((const char*)color, "light blue") == 0) {
output = LCD_LIGHTBLUE; output = LCD_LIGHTBLUE;
} }
if(strcmp((const char*)color, "light green") == 0) { if(strcmp((const char*)color, "light green") == 0) {
output = LCD_LIGHTGREEN; output = LCD_LIGHTGREEN;
} }
if(strcmp((const char*)color, "light red") == 0) { if(strcmp((const char*)color, "light red") == 0) {
output = LCD_LIGHTRED; output = LCD_LIGHTRED;
} }
if(strcmp((const char*)color, "light cyan") == 0) { if(strcmp((const char*)color, "light cyan") == 0) {
output = LCD_LIGHTCYAN; output = LCD_LIGHTCYAN;
} }
if(strcmp((const char*)color, "light magenta") == 0) { if(strcmp((const char*)color, "light magenta") == 0) {
output = LCD_LIGHTMAGENTA; output = LCD_LIGHTMAGENTA;
} }
if(strcmp((const char*)color, "light yellow") == 0) { if(strcmp((const char*)color, "light yellow") == 0) {
output = LCD_LIGHTYELLOW; output = LCD_LIGHTYELLOW;
} }
if(strcmp((const char*)color, "dark blue") == 0) { if(strcmp((const char*)color, "dark blue") == 0) {
output = LCD_DARKBLUE; output = LCD_DARKBLUE;
} }
if(strcmp((const char*)color, "dark green") == 0) { if(strcmp((const char*)color, "dark green") == 0) {
output = LCD_DARKGREEN; output = LCD_DARKGREEN;
} }
if(strcmp((const char*)color, "dark red") == 0) { if(strcmp((const char*)color, "dark red") == 0) {
output = LCD_DARKRED; output = LCD_DARKRED;
} }
if(strcmp((const char*)color, "dark cyan") == 0) { if(strcmp((const char*)color, "dark cyan") == 0) {
output = LCD_DARKCYAN; output = LCD_DARKCYAN;
} }
if(strcmp((const char*)color, "dark magenta") == 0) { if(strcmp((const char*)color, "dark magenta") == 0) {
output = LCD_DARKMAGENTA; output = LCD_DARKMAGENTA;
} }
if(strcmp((const char*)color, "dark yellow") == 0) { if(strcmp((const char*)color, "dark yellow") == 0) {
output = LCD_DARKYELLOW; output = LCD_DARKYELLOW;
} }
if(strcmp((const char*)color, "white") == 0) { if(strcmp((const char*)color, "white") == 0) {
output = LCD_WHITE; output = LCD_WHITE;
} }
if(strcmp((const char*)color, "light gray") == 0) { if(strcmp((const char*)color, "light gray") == 0) {
output = LCD_LIGHTGRAY; output = LCD_LIGHTGRAY;
} }
if(strcmp((const char*)color, "gray") == 0) { if(strcmp((const char*)color, "gray") == 0) {
output = LCD_GRAY; output = LCD_GRAY;
} }
if(strcmp((const char*)color, "dark gray") == 0) { if(strcmp((const char*)color, "dark gray") == 0) {
output = LCD_DARKGRAY; output = LCD_DARKGRAY;
} }
if(strcmp((const char*)color, "black") == 0) { if(strcmp((const char*)color, "black") == 0) {
output = LCD_BLACK; output = LCD_BLACK;
} }
if(strcmp((const char*)color, "brown") == 0) { if(strcmp((const char*)color, "brown") == 0) {
output = LCD_BROWN; output = LCD_BROWN;
} }
if(strcmp((const char*)color, "orange") == 0) { if(strcmp((const char*)color, "orange") == 0) {
output = LCD_ORANGE; output = LCD_ORANGE;
} }
if(strcmp((const char*)color, "transparent") == 0) { if(strcmp((const char*)color, "transparent") == 0) {
output = LCD_TRANSPARENT; output = LCD_TRANSPARENT;
} }
return output; return output;
} }